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.

27 lines
1.0 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 IrAttachment(models.Model):
  6. _name = "ir.attachment"
  7. _inherit = ["ir.attachment", "autovacuum.mixin"]
  8. _autovacuum_relation = 'assigned_attachment_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 += [('create_date', '<', limit_date)]
  14. if rule.filename_pattern:
  15. domain += [('name', 'ilike', rule.filename_pattern)]
  16. if rule.model_ids:
  17. models = rule.model_ids.mapped('model')
  18. domain += [('res_model', 'in', models)]
  19. else:
  20. # Avoid deleting attachment without model, if there are, it is
  21. # probably some attachments created by Odoo
  22. domain += [('res_model', '!=', False)]
  23. return domain