Migrate autovacuum_mail_message to version 12 and rename it

pull/2766/head
Florian da Costa 2019-06-29 10:13:21 +02:00
parent 590cf43c30
commit 8265c71fa0
17 changed files with 784 additions and 0 deletions

View File

@ -0,0 +1,66 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:alt: License: LGPL-3
=======================
AutoVacuum Mail Message
=======================
Odoo create a lot of message and/or mails. With time it can slow the system or take a lot of disk space.
The goal of this module is to clean these message once they are obsolete.
Configuration
=============
* Go to the menu configuration => Technical => Email => Message vacuum Rule
* Add the adequates rules for your company. On each rule, you can indicate the models, type and subtypes for which you want to delete the messages, along with a retention time (in days).
* Activate the cron AutoVacuum Mails and Messages
It is recommanded to run it frequently and when the system is not very loaded.
(For instance : once a day, during the night.)
Usage
=====
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/9.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors
------------
* Florian da Costa <florian.dacosta@akretion.com>
Do not contact contributors directly about support or help with technical issues.
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

View File

@ -0,0 +1 @@
from . import models

View File

@ -0,0 +1,21 @@
# Copyright (C) 2018 Akretion
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
"name": "AutoVacuum Mail Message",
"version": "12.0.1.0.0",
"category": "Tools",
"website": "https://github.com/OCA/server-tools",
"author": "Akretion, Odoo Community Association (OCA)",
"license": "LGPL-3",
"installable": True,
"summary": "Automatically delete old mail messages to clean database",
"depends": [
"mail",
],
"data": [
"data/data.xml",
"views/message_rule_vacuum.xml",
"security/ir.model.access.csv",
],
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<record id="ir_cron_vacuum_message" model="ir.cron">
<field name="name">AutoVacuum Mails and Messages</field>
<field eval="False" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="state">code</field>
<field name="code">model.autovacuum_mail_message()</field>
<field eval="False" name="doall"/>
<field name="model_id" ref="mail.model_mail_message"/>
</record>
</odoo>

View File

@ -0,0 +1,158 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * autovacuum_mail_message
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: autovacuum_mail_message
#: selection:message.vacuum.rule,message_type:0
msgid "All"
msgstr ""
#. module: autovacuum_mail_message
#: selection:message.vacuum.rule,message_type:0
msgid "Comment"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_company_id
msgid "Company"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_create_uid
msgid "Created by"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_create_date
msgid "Created on"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_display_name
msgid "Display Name"
msgstr ""
#. module: autovacuum_mail_message
#: selection:message.vacuum.rule,message_type:0
msgid "Email"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_empty_subtype
msgid "Empty subtype"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_id
msgid "ID"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule___last_update
msgid "Last Modified on"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_write_uid
msgid "Last Updated by"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_write_date
msgid "Last Updated on"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model,name:autovacuum_mail_message.model_mail_message
msgid "Message"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.ui.view,arch_db:autovacuum_mail_message.message_vacuum_rule_form_view
msgid "Message Models"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.ui.view,arch_db:autovacuum_mail_message.message_vacuum_rule_form_view
msgid "Message Subtypes"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.actions.act_window,name:autovacuum_mail_message.action_message_vacuum_rule
#: model:ir.ui.menu,name:autovacuum_mail_message.menu_action_message_vacuum_rule
#: model:ir.ui.view,arch_db:autovacuum_mail_message.message_vacuum_rule_form_view
msgid "Message Vacuum Rule"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,help:autovacuum_mail_message.field_message_vacuum_rule_message_subtype_ids
msgid "Message subtypes concerned by the rule. If left empty, the system won't take the subtype into account to find the messages to delete"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_message_type
msgid "Message type"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_model_ids
msgid "Models"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,help:autovacuum_mail_message.field_message_vacuum_rule_model_ids
msgid "Models concerned by the rule. If left empty, it will take all models into account"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_name
msgid "Name"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,help:autovacuum_mail_message.field_message_vacuum_rule_retention_time
msgid "Number of days the messages concerned by this rule will be keeped in the database after creation. Once the delay is passed, they will be automatically deleted."
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_retention_time
msgid "Retention time"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model,name:autovacuum_mail_message.model_message_vacuum_rule
msgid "Rules Used to delete message historic"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_message_subtype_ids
msgid "Subtypes"
msgstr ""
#. module: autovacuum_mail_message
#: selection:message.vacuum.rule,message_type:0
msgid "System notification"
msgstr ""
#. module: autovacuum_mail_message
#: model:ir.model.fields,help:autovacuum_mail_message.field_message_vacuum_rule_empty_subtype
msgid "Take also into account messages with no subtypes"
msgstr ""
#. module: autovacuum_mail_message
#: code:addons/autovacuum_mail_message/models/message_vacuum_rule.py:48
#, python-format
msgid "The Retention Time can't be 0 days"
msgstr ""

View File

@ -0,0 +1,180 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * autovacuum_mail_message
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-03-29 11:30+0000\n"
"PO-Revision-Date: 2018-03-29 11:30+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: autovacuum_mail_message
#: selection:message.vacuum.rule,message_type:0
msgid "All"
msgstr "Tous"
#. module: autovacuum_mail_message
#: selection:message.vacuum.rule,message_type:0
msgid "Comment"
msgstr "Commentaires"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_company_id
msgid "Company"
msgstr "Société"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_create_uid
msgid "Created by"
msgstr "Créé par"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_create_date
msgid "Created on"
msgstr "Créé le"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_display_name
msgid "Display Name"
msgstr "Nom à afficher"
#. module: autovacuum_mail_message
#: selection:message.vacuum.rule,message_type:0
msgid "Email"
msgstr "Email"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_empty_subtype
msgid "Empty subtype"
msgstr "Sous-type Vide"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_id
msgid "ID"
msgstr "ID"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule___last_update
msgid "Last Modified on"
msgstr "Dernière modification le"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_write_uid
msgid "Last Updated by"
msgstr "Dernière modification par"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_write_date
msgid "Last Updated on"
msgstr "Dernière mise à jour le"
#. module: autovacuum_mail_message
#: model:ir.model,name:autovacuum_mail_message.model_mail_message
msgid "Message"
msgstr "Message"
#. module: autovacuum_mail_message
#: model:ir.ui.view,arch_db:autovacuum_mail_message.message_vacuum_rule_form_view
msgid "Message Models"
msgstr "Documents des messages"
#. module: autovacuum_mail_message
#: model:ir.ui.view,arch_db:autovacuum_mail_message.message_vacuum_rule_form_view
msgid "Message Subtypes"
msgstr "Sous-types des messages"
#. module: autovacuum_mail_message
#: model:ir.actions.act_window,name:autovacuum_mail_message.action_message_vacuum_rule
#: model:ir.ui.menu,name:autovacuum_mail_message.menu_action_message_vacuum_rule
#: model:ir.ui.view,arch_db:autovacuum_mail_message.message_vacuum_rule_form_view
msgid "Message Vacuum Rule"
msgstr "Règle de supression des messages"
#. module: autovacuum_mail_message
#: model:ir.model.fields,help:autovacuum_mail_message.field_message_vacuum_rule_message_subtype_ids
msgid ""
"Message subtypes concerned by the rule. If left empty, the system won't take "
"the subtype into account to find the messages to delete"
msgstr ""
"Sous-types de message concernés par cette règle. Si c'est laissé vide, le "
"système ne prendra pas en compte les sous type pour trouver les messages à "
"supprimer"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_message_type
msgid "Message type"
msgstr "Type de message"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_model_ids
msgid "Models"
msgstr "Documents"
#. module: autovacuum_mail_message
#: model:ir.model.fields,help:autovacuum_mail_message.field_message_vacuum_rule_model_ids
msgid ""
"Models concerned by the rule. If left empty, it will take all models into "
"account"
msgstr ""
"Documents concernés par la règle. Si c'est laissé vide, les messages de tous "
"les modèles seront pris en compte"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_name
msgid "Name"
msgstr "Nom"
#. module: autovacuum_mail_message
#: model:ir.model.fields,help:autovacuum_mail_message.field_message_vacuum_rule_retention_time
msgid ""
"Number of days the messages concerned by this rule will be keeped in the "
"database after creation. Once the delay is passed, they will be "
"automatically deleted."
msgstr ""
"Nombre de jour de rétention des messages concerné par la règle. Une fois ce "
"délai passé, les messages sont automatiquement supprimés"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_retention_time
msgid "Retention time"
msgstr "Temps de rétention"
#. module: autovacuum_mail_message
#: model:ir.model,name:autovacuum_mail_message.model_message_vacuum_rule
msgid "Rules Used to delete message historic"
msgstr "Règle de supression automatique de message"
#. module: autovacuum_mail_message
#: model:ir.model.fields,field_description:autovacuum_mail_message.field_message_vacuum_rule_message_subtype_ids
msgid "Subtypes"
msgstr "Sous-types"
#. module: autovacuum_mail_message
#: selection:message.vacuum.rule,message_type:0
msgid "System notification"
msgstr "Notification Système"
#. module: autovacuum_mail_message
#: model:ir.model.fields,help:autovacuum_mail_message.field_message_vacuum_rule_empty_subtype
msgid "Take also into account messages with no subtypes"
msgstr "Prend également en compte les messages sans aucun sous-type"
#. module: autovacuum_mail_message
#: code:addons/autovacuum_mail_message/models/message_vacuum_rule.py:48
#, python-format
msgid "The Retention Time can't be 0 days"
msgstr "Le temps de retention ne peut pas être de 0 jours."
#~ msgid "Companies"
#~ msgstr "Sociétés"
#~ msgid "mail_message_subtype"
#~ msgstr "mail_message_subtype"

View File

@ -0,0 +1,2 @@
from . import mail_message
from . import message_vacuum_rule

View File

@ -0,0 +1,44 @@
# Copyright (C) 2018 Akretion
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
import logging
import odoo
from odoo import api, models
_logger = logging.getLogger(__name__)
class MailMessage(models.Model):
_inherit = "mail.message"
@api.multi
def batch_unlink(self):
with api.Environment.manage():
with odoo.registry(
self.env.cr.dbname).cursor() as new_cr:
new_env = api.Environment(new_cr, self.env.uid,
self.env.context)
try:
while self:
batch_delete_messages = self[0:1000]
self -= batch_delete_messages
# do not attach new env to self because it may be
# huge, and the cache is cleaned after each unlink
# so we do not want to much record is the env in
# which we call unlink because odoo would prefetch
# fields, cleared right after.
batch_delete_messages.with_env(new_env).unlink()
new_env.cr.commit()
except Exception as e:
_logger.exception(
"Failed to delete messages : %s", str(e))
# Call by cron
@api.model
def autovacuum_mail_message(self):
rules = self.env['message.vacuum.rule'].search([])
for rule in rules:
domain = rule.get_message_domain()
messages = self.search(domain)
messages.batch_unlink()

View File

@ -0,0 +1,103 @@
# Copyright (C) 2018 Akretion
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from datetime import date, timedelta
from odoo import _, api, exceptions, fields, models
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
from odoo.tools.safe_eval import safe_eval
import datetime
class MessageVacuumRule(models.Model):
_name = "message.vacuum.rule"
_description = "Rules Used to delete message historic"
@api.depends('model_ids')
@api.multi
def _compute_model_id(self):
for rule in self:
if rule.model_ids and len(rule.model_ids) == 1:
rule.model_id = rule.model_ids.id
else:
rule.model_id = False
name = fields.Char(required=True)
company_id = fields.Many2one(
'res.company', string="Company",
default=lambda self: self.env['res.company']._company_default_get(
'message.vacuum.rule'))
message_subtype_ids = fields.Many2many(
'mail.message.subtype', string="Subtypes",
help="Message subtypes concerned by the rule. If left empty, the "
"system won't take the subtype into account to find the "
"messages to delete")
empty_subtype = fields.Boolean(
help="Take also into account messages with no subtypes")
model_ids = fields.Many2many(
'ir.model', string="Models",
help="Models concerned by the rule. If left empty, it will take all "
"models into account")
model_id = fields.Many2one(
'ir.model', readonly=True,
compute='_compute_model_id',
help="Technical field used to set attributes (invisible/required, "
"domain, etc...for other fields, like the domain filter")
model_filter_domain = fields.Text(
string='Model Filter Domain')
message_type = fields.Selection([
('email', 'Email'),
('comment', 'Comment'),
('notification', 'System notification'),
('all', 'All')], required=True)
retention_time = fields.Integer(
required=True, default=365,
help="Number of days the messages concerned by this rule will be "
"keeped in the database after creation. Once the delay is "
"passed, they will be automatically deleted.")
active = fields.Boolean(default=True)
description = fields.Text()
@api.multi
@api.constrains('retention_time')
def retention_time_not_null(self):
for rule in self:
if not rule.retention_time:
raise exceptions.ValidationError(
_("The Retention Time can't be 0 days"))
@api.multi
def get_message_domain(self):
self.ensure_one()
today = date.today()
limit_date = today - timedelta(days=self.retention_time)
limit_date = limit_date.strftime(DEFAULT_SERVER_DATE_FORMAT)
message_domain = [('date', '<', limit_date)]
if self.message_type != 'all':
message_domain += [('message_type', '=', self.message_type)]
if self.model_ids:
models = self.model_ids.mapped('model')
message_domain += [('model', 'in', models)]
subtype_ids = self.message_subtype_ids.ids
subtype_domain = []
if subtype_ids and self.empty_subtype:
subtype_domain = ['|', ('subtype_id', 'in', subtype_ids),
('subtype_id', '=', False)]
elif subtype_ids and not self.empty_subtype:
subtype_domain += [('subtype_id', 'in', subtype_ids)]
elif not subtype_ids and not self.empty_subtype:
subtype_domain += [('subtype_id', '!=', False)]
message_domain += subtype_domain
# Case we want a condition on linked model records
if self.model_id and self.model_filter_domain:
domain = safe_eval(self.model_filter_domain,
locals_dict={'datetime': datetime})
res_model = self.model_id.model
res_records = self.env[res_model].with_context(
active_test=False).search(domain)
res_ids = res_records.ids
message_domain += ['|', ('res_id', 'in', res_ids),
('res_id', '=', False)]
return message_domain

View File

@ -0,0 +1,6 @@
* Go to the menu configuration => Technical => Email => Message Vacuum Rules
* Add the adequates rules for your company. On each rule, you can indicate the models, type and subtypes for which you want to delete the messages, along with a retention time (in days).
* Activate the cron AutoVacuum Mails and Messages
It is recommanded to run it frequently and when the system is not very loaded.
(For instance : once a day, during the night.)

View File

@ -0,0 +1 @@
* Florian da Costa <florian.dacosta@akretion.com>

View File

@ -0,0 +1,3 @@
Odoo create a lot of message and/or mails. With time it can slow the system or take a lot of disk space.
The goal of this module is to clean these message once they are obsolete.
You can choose various criterias manage which messages you want to delete automatically.

View File

@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_full_message_vaccum_rule,access.full.message.vaccum.rule,model_message_vacuum_rule,base.group_system,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_full_message_vaccum_rule access.full.message.vaccum.rule model_message_vacuum_rule base.group_system 1 1 1 1

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -0,0 +1,4 @@
# © 2018 Akretion (Florian da Costa)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_message_vacuum_rule

View File

@ -0,0 +1,118 @@
# © 2018 Akretion (Florian da Costa)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import date, timedelta
from odoo import api, exceptions
from odoo.tests import common
class TestMessageVacuumRule(common.TransactionCase):
def create_mail_message(self, message_type, subtype):
vals = {
'message_type': message_type,
'subtype_id': subtype and subtype.id or False,
'date': self.before_400_days,
'model': 'mail.channel',
'res_id': self.env.ref('mail.channel_all_employees').id,
'subject': 'Test',
'body': 'Body Test',
}
return self.message_obj.create(vals)
def tearDown(self):
self.registry.leave_test_mode()
super(TestMessageVacuumRule, self).tearDown()
def setUp(self):
super(TestMessageVacuumRule, self).setUp()
self.registry.enter_test_mode(self.env.cr)
self.env = api.Environment(self.registry.test_cr, self.env.uid,
self.env.context)
self.subtype = self.env.ref('mail.mt_comment')
self.message_obj = self.env['mail.message']
self.channel_model = self.env.ref('mail.model_mail_channel')
today = date.today()
self.before_400_days = today - timedelta(days=400)
def test_mail_vacuum_rules(self):
rule_vals = {
'name': 'Subtype Model',
'retention_time': 399,
'message_type': 'email',
'model_ids': [(6, 0, [self.channel_model.id])],
'message_subtype_ids': [(6, 0, [self.subtype.id])],
}
rule = self.env['message.vacuum.rule'].create(rule_vals)
m1 = self.create_mail_message('notification', self.subtype)
m2 = self.create_mail_message('email', self.env.ref('mail.mt_note'))
m3 = self.create_mail_message('email', False)
message_ids = [m1.id, m2.id, m3.id]
self.message_obj.autovacuum_mail_message()
message = self.message_obj.search(
[('id', 'in', message_ids)])
# no message deleted because either message_type is wrong or subtype
# is wront or subtype is empty
self.assertEqual(len(message),
3)
rule.write({'message_type': 'notification', 'retention_time': 405})
self.message_obj.autovacuum_mail_message()
message = self.message_obj.search(
[('id', 'in', message_ids)])
# no message deleted because of retention time
self.assertEqual(len(message),
3)
rule.write({'retention_time': 399})
self.message_obj.autovacuum_mail_message()
message = self.message_obj.search(
[('id', 'in', message_ids)])
self.assertEqual(len(message),
2)
rule.write({'message_type': 'email',
'message_subtype_ids': [(6, 0, [])],
'empty_subtype': True})
self.message_obj.autovacuum_mail_message()
message = self.message_obj.search(
[('id', 'in', message_ids)])
self.assertEqual(len(message),
0)
def test_retention_time_constraint(self):
rule_vals = {
'name': 'Subtype Model',
'retention_time': 0,
'message_type': 'email',
}
with self.assertRaises(exceptions.ValidationError):
self.env['message.vacuum.rule'].create(rule_vals)
def test_res_model_domain(self):
partner = self.env['res.partner'].create({'name': 'Test Partner'})
# automatic creation message
self.assertEqual(len(partner.message_ids), 1)
# change date message to simulate it is an old one
partner.message_ids.write({'date': '2017-01-01'})
partner_model = self.env.ref('base.model_res_partner')
rule_vals = {
'name': 'Partners',
'retention_time': 399,
'message_type': 'all',
'model_ids': [(6, 0, [partner_model.id])],
'model_filter_domain': "[['name', '=', 'Dummy']]",
'empty_subtype': True,
}
rule = self.env['message.vacuum.rule'].create(rule_vals)
self.message_obj.autovacuum_mail_message()
# no message deleted as the filter does not match
self.assertEqual(len(partner.message_ids), 1)
rule.write({
'model_filter_domain': "[['name', '=', 'Test Partner']]"
})
self.message_obj.autovacuum_mail_message()
self.assertEqual(len(partner.message_ids), 0)

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="message_vacuum_rule_form_view">
<field name="name">message.vacuum.rule.form.view</field>
<field name="model">message.vacuum.rule</field>
<field name="arch" type="xml">
<form string="Message Vacuum Rule">
<sheet>
<group col="4">
<group col="4" colspan="4">
<field name="name" colspan="2"/>
<field name="company_id" colspan="2"/>
<field name="message_type" colspan="2"/>
<field name="empty_subtype" colspan="2"/>
<field name="retention_time" colspan="2"/>
<field name="active" colspan="2"/>
</group>
<separator string="Message Models" colspan="4"/>
<field name="model_ids" nolabel="1" colspan="4"/>
<field name="model_id" colspan="4"/>
<field name="model_filter_domain" attrs="{'invisible': [('model_id', '=', False)]}" colspan="4"/>
<separator string="Message Subtypes" colspan="4"/>
<field name="message_subtype_ids" nolabel="1" colspan="4"/>
<separator string="Description" colspan="4"/>
<field name="description" nolabel="1" colspan="4"/>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="message_vacuum_rule_tree_view">
<field name="name">message.vacuum.rule.form.view</field>
<field name="model">message.vacuum.rule</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="company_id"/>
<field name="message_type"/>
<field name="empty_subtype"/>
<field name="retention_time"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_message_vacuum_rule">
<field name="name">Message Vacuum Rules</field>
<field name="res_model">message.vacuum.rule</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_action_message_vacuum_rule" parent="base.menu_email" action="action_message_vacuum_rule"/>
</odoo>