You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.2 KiB

  1. # Copyright (C) 2018 Akretion
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  3. from odoo import fields, models
  4. from datetime import timedelta
  5. class MailMessage(models.Model):
  6. _name = "mail.message"
  7. _inherit = ["mail.message", "autovacuum.mixin"]
  8. _autovacuum_relation = 'message_ids'
  9. def _get_autovacuum_domain(self, rule):
  10. domain = super()._get_autovacuum_domain(rule)
  11. today = fields.Datetime.now()
  12. limit_date = today - timedelta(days=rule.retention_time)
  13. domain += [('date', '<', limit_date)]
  14. if rule.message_type != 'all':
  15. domain += [('message_type', '=', rule.message_type)]
  16. if rule.model_ids:
  17. models = rule.model_ids.mapped('model')
  18. domain += [('model', 'in', models)]
  19. subtype_ids = rule.message_subtype_ids.ids
  20. if subtype_ids and rule.empty_subtype:
  21. domain = [
  22. '|', ('subtype_id', 'in', subtype_ids),
  23. ('subtype_id', '=', False)]
  24. elif subtype_ids and not rule.empty_subtype:
  25. domain += [('subtype_id', 'in', subtype_ids)]
  26. elif not subtype_ids and not rule.empty_subtype:
  27. domain += [('subtype_id', '!=', False)]
  28. return domain