Browse Source
[REF] autovacuum_message_attachment: Improve the way we manage domains
12.0-mig-module_prototyper_last
[REF] autovacuum_message_attachment: Improve the way we manage domains
12.0-mig-module_prototyper_last
Enric Tobella
5 years ago
committed by
Florian da Costa
8 changed files with 126 additions and 88 deletions
-
1autovacuum_message_attachment/models/__init__.py
-
30autovacuum_message_attachment/models/autovacuum_mixin.py
-
13autovacuum_message_attachment/models/base.py
-
20autovacuum_message_attachment/models/ir_attachment.py
-
26autovacuum_message_attachment/models/mail_message.py
-
76autovacuum_message_attachment/models/vacuum_rule.py
-
1autovacuum_message_attachment/readme/CONTRIBUTORS.rst
-
47autovacuum_message_attachment/views/rule_vacuum.xml
@ -0,0 +1,13 @@ |
|||
# Copyright (C) 2019 Akretion |
|||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
|||
|
|||
from odoo import fields, models |
|||
|
|||
|
|||
class Base(models.AbstractModel): |
|||
_inherit = "base" |
|||
|
|||
attachment_ids = fields.One2many( |
|||
'ir.attachment', 'res_id', string='Attachments', |
|||
domain=lambda self: [('res_model', '=', self._name)], auto_join=True |
|||
) |
@ -1,9 +1,27 @@ |
|||
# Copyright (C) 2018 Akretion |
|||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
|||
|
|||
from odoo import models |
|||
from odoo import fields, models |
|||
from datetime import timedelta |
|||
|
|||
|
|||
class IrAttachment(models.Model): |
|||
_name = "ir.attachment" |
|||
_inherit = ["ir.attachment", "autovacuum.mixin"] |
|||
_autovacuum_relation = 'attachment_ids' |
|||
|
|||
def _get_autovacuum_domain(self, rule): |
|||
domain = super()._get_autovacuum_domain(rule) |
|||
today = fields.Datetime.now() |
|||
limit_date = today - timedelta(days=rule.retention_time) |
|||
domain += [('create_date', '<', limit_date)] |
|||
if rule.filename_pattern: |
|||
domain += [('name', 'ilike', rule.filename_pattern)] |
|||
if rule.model_ids: |
|||
models = rule.model_ids.mapped('model') |
|||
domain += [('res_model', 'in', models)] |
|||
else: |
|||
# Avoid deleting attachment without model, if there are, it is |
|||
# probably some attachments created by Odoo |
|||
domain += [('res_model', '!=', False)] |
|||
return domain |
@ -1,10 +1,32 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright (C) 2018 Akretion |
|||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
|||
|
|||
from odoo import models |
|||
from odoo import fields, models |
|||
from datetime import timedelta |
|||
|
|||
|
|||
class MailMessage(models.Model): |
|||
_name = "mail.message" |
|||
_inherit = ["mail.message", "autovacuum.mixin"] |
|||
_autovacuum_relation = 'message_ids' |
|||
|
|||
def _get_autovacuum_domain(self, rule): |
|||
domain = super()._get_autovacuum_domain(rule) |
|||
today = fields.Datetime.now() |
|||
limit_date = today - timedelta(days=rule.retention_time) |
|||
domain += [('date', '<', limit_date)] |
|||
if rule.message_type != 'all': |
|||
domain += [('message_type', '=', rule.message_type)] |
|||
if rule.model_ids: |
|||
models = rule.model_ids.mapped('model') |
|||
domain += [('model', 'in', models)] |
|||
subtype_ids = rule.message_subtype_ids.ids |
|||
if subtype_ids and rule.empty_subtype: |
|||
domain = [ |
|||
'|', ('subtype_id', 'in', subtype_ids), |
|||
('subtype_id', '=', False)] |
|||
elif subtype_ids and not rule.empty_subtype: |
|||
domain += [('subtype_id', 'in', subtype_ids)] |
|||
elif not subtype_ids and not rule.empty_subtype: |
|||
domain += [('subtype_id', '!=', False)] |
|||
return domain |
@ -1 +1,2 @@ |
|||
* Florian da Costa <florian.dacosta@akretion.com> |
|||
* Enric Tobella <etobella@creublanca.es> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue