Add selection of attachments through inheriting model

Selection of attachments through inheriting model can be useful if
we want to purge attachments that are extended through another
model.

For example, shipping.label (from base_delivery_carrier_label)
inherits from ir.attachment but the attachment itself is linked to
the stock.picking model.
By using inheriting_model defined to shipping.label and setting
model_ids to stock.picking, we can safely select the attachments
linked to stock.pickings that are shipping labels and avoid deleting
any picking list or delivery note reports.
pull/2766/head
Akim Juillerat 2022-12-06 13:40:38 +01:00 committed by Florian da Costa
parent cb68657b8a
commit 1e19a4b6dd
10 changed files with 198 additions and 9 deletions

View File

@ -75,6 +75,7 @@ Contributors
* Florian da Costa <florian.dacosta@akretion.com>
* Enric Tobella <etobella@creublanca.es>
* Helly kapatel <helly.kapatel@initos.com>
* Akim Juillerat <akim.juillerat@camptocamp.com>
Maintainers
~~~~~~~~~~~

View File

@ -25,7 +25,6 @@ msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field__unknown__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_abstract_conditional_image__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_abstract_config_settings__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_account_account__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_account_account_tag__assigned_attachment_ids
@ -105,6 +104,7 @@ msgstr ""
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_http_session__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log_line__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log_line_view__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_rule__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auth_totp_wizard__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin__assigned_attachment_ids
@ -212,7 +212,6 @@ msgstr ""
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_format_address_mixin__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_iap_account__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_iap_enrich_api__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_image__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_image_mixin__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_actions_act_url__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_actions_act_window__assigned_attachment_ids
@ -350,6 +349,12 @@ msgstr ""
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_order__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_order_line__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_report__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job_channel__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job_function__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_jobs_to_cancelled__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_jobs_to_done__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_requeue_job__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_record_changeset__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_record_changeset_change__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_report_account_report_hash_integrity__assigned_attachment_ids
@ -483,6 +488,12 @@ msgstr ""
msgid "Base"
msgstr ""
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "Cannot find relation to ir.attachment on model %s"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin__changeset_change_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_attachment__changeset_change_ids
@ -577,6 +588,25 @@ msgstr ""
msgid "If set, only attachments containing this pattern will be deleted."
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,help:autovacuum_message_attachment.field_vacuum_rule__inheriting_model
msgid ""
"If set, this model will be searched and only related attachments will be deleted.\n"
"\n"
"N.B: model must implement _inherits to link ir.attachment"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_vacuum_rule__inheriting_model
msgid "Inheriting Model"
msgstr ""
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "Inheriting model cannot be used on rule where type is not attachment"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin____last_update
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_attachment____last_update
@ -671,6 +701,12 @@ msgstr ""
msgid "Name"
msgstr ""
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "No inheritance of ir.attachment was found on model %s"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,help:autovacuum_message_attachment.field_vacuum_rule__retention_time
msgid ""

View File

@ -26,7 +26,6 @@ msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field__unknown__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_abstract_conditional_image__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_abstract_config_settings__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_account_account__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_account_account_tag__assigned_attachment_ids
@ -106,6 +105,7 @@ msgstr ""
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_http_session__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log_line__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log_line_view__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_rule__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auth_totp_wizard__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin__assigned_attachment_ids
@ -213,7 +213,6 @@ msgstr ""
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_format_address_mixin__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_iap_account__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_iap_enrich_api__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_image__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_image_mixin__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_actions_act_url__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_actions_act_window__assigned_attachment_ids
@ -351,6 +350,12 @@ msgstr ""
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_order__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_order_line__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_report__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job_channel__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job_function__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_jobs_to_cancelled__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_jobs_to_done__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_requeue_job__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_record_changeset__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_record_changeset_change__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_report_account_report_hash_integrity__assigned_attachment_ids
@ -484,6 +489,12 @@ msgstr ""
msgid "Base"
msgstr ""
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "Cannot find relation to ir.attachment on model %s"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin__changeset_change_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_attachment__changeset_change_ids
@ -578,6 +589,26 @@ msgstr ""
msgid "If set, only attachments containing this pattern will be deleted."
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,help:autovacuum_message_attachment.field_vacuum_rule__inheriting_model
msgid ""
"If set, this model will be searched and only related attachments will be "
"deleted.\n"
"\n"
"N.B: model must implement _inherits to link ir.attachment"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_vacuum_rule__inheriting_model
msgid "Inheriting Model"
msgstr ""
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "Inheriting model cannot be used on rule where type is not attachment"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin____last_update
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_attachment____last_update
@ -672,6 +703,12 @@ msgstr ""
msgid "Name"
msgstr ""
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "No inheritance of ir.attachment was found on model %s"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,help:autovacuum_message_attachment.field_vacuum_rule__retention_time
msgid ""

View File

@ -28,7 +28,6 @@ msgstr "Todos"
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field__unknown__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_abstract_conditional_image__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_abstract_config_settings__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_account_account__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_account_account_tag__assigned_attachment_ids
@ -108,6 +107,7 @@ msgstr "Todos"
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_http_session__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log_line__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log_line_view__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_rule__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auth_totp_wizard__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin__assigned_attachment_ids
@ -215,7 +215,6 @@ msgstr "Todos"
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_format_address_mixin__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_iap_account__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_iap_enrich_api__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_image__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_image_mixin__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_actions_act_url__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_actions_act_window__assigned_attachment_ids
@ -353,6 +352,12 @@ msgstr "Todos"
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_order__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_order_line__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_report__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job_channel__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job_function__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_jobs_to_cancelled__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_jobs_to_done__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_requeue_job__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_record_changeset__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_record_changeset_change__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_report_account_report_hash_integrity__assigned_attachment_ids
@ -486,6 +491,12 @@ msgstr "AutoLimpiar Mails y Mensajes"
msgid "Base"
msgstr "Base"
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "Cannot find relation to ir.attachment on model %s"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin__changeset_change_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_attachment__changeset_change_ids
@ -582,6 +593,26 @@ msgstr ""
"Si se establece, solo se eliminarán los archivos adjuntos que contengan este "
"patrón."
#. module: autovacuum_message_attachment
#: model:ir.model.fields,help:autovacuum_message_attachment.field_vacuum_rule__inheriting_model
msgid ""
"If set, this model will be searched and only related attachments will be "
"deleted.\n"
"\n"
"N.B: model must implement _inherits to link ir.attachment"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_vacuum_rule__inheriting_model
msgid "Inheriting Model"
msgstr ""
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "Inheriting model cannot be used on rule where type is not attachment"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin____last_update
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_attachment____last_update
@ -680,6 +711,12 @@ msgstr ""
msgid "Name"
msgstr "Nombre"
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "No inheritance of ir.attachment was found on model %s"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,help:autovacuum_message_attachment.field_vacuum_rule__retention_time
msgid ""

View File

@ -28,7 +28,6 @@ msgstr "Tous"
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field__unknown__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_abstract_conditional_image__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_abstract_config_settings__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_account_account__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_account_account_tag__assigned_attachment_ids
@ -108,6 +107,7 @@ msgstr "Tous"
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_http_session__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log_line__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_log_line_view__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auditlog_rule__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_auth_totp_wizard__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin__assigned_attachment_ids
@ -215,7 +215,6 @@ msgstr "Tous"
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_format_address_mixin__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_iap_account__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_iap_enrich_api__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_image__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_image_mixin__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_actions_act_url__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_actions_act_window__assigned_attachment_ids
@ -353,6 +352,12 @@ msgstr "Tous"
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_order__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_order_line__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_purchase_report__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job_channel__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_job_function__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_jobs_to_cancelled__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_jobs_to_done__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_queue_requeue_job__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_record_changeset__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_record_changeset_change__assigned_attachment_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_report_account_report_hash_integrity__assigned_attachment_ids
@ -486,6 +491,12 @@ msgstr ""
msgid "Base"
msgstr ""
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "Cannot find relation to ir.attachment on model %s"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin__changeset_change_ids
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_attachment__changeset_change_ids
@ -581,6 +592,26 @@ msgstr "ID"
msgid "If set, only attachments containing this pattern will be deleted."
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,help:autovacuum_message_attachment.field_vacuum_rule__inheriting_model
msgid ""
"If set, this model will be searched and only related attachments will be "
"deleted.\n"
"\n"
"N.B: model must implement _inherits to link ir.attachment"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_vacuum_rule__inheriting_model
msgid "Inheriting Model"
msgstr ""
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "Inheriting model cannot be used on rule where type is not attachment"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_autovacuum_mixin____last_update
#: model:ir.model.fields,field_description:autovacuum_message_attachment.field_ir_attachment____last_update
@ -685,6 +716,12 @@ msgstr ""
msgid "Name"
msgstr "Nom"
#. module: autovacuum_message_attachment
#: code:addons/autovacuum_message_attachment/models/vacuum_rule.py:0
#, python-format
msgid "No inheritance of ir.attachment was found on model %s"
msgstr ""
#. module: autovacuum_message_attachment
#: model:ir.model.fields,help:autovacuum_message_attachment.field_vacuum_rule__retention_time
msgid ""

View File

@ -16,7 +16,15 @@ class IrAttachment(models.Model):
domain = super()._get_autovacuum_domain(rule)
today = fields.Datetime.now()
limit_date = today - timedelta(days=rule.retention_time)
domains = [domain, [("create_date", "<", limit_date)]]
create_date_domain = [("create_date", "<", limit_date)]
domains = [domain, create_date_domain]
if rule.inheriting_model:
inheriting_model = self.env[rule.inheriting_model]
attachment_link = inheriting_model._inherits.get("ir.attachment")
att_ids = inheriting_model.search(create_date_domain).mapped(
attachment_link + ".ids"
)
domains.append([("id", "in", att_ids)])
if rule.filename_pattern:
domains.append([("name", "ilike", rule.filename_pattern)])
if rule.model_ids:

View File

@ -27,6 +27,10 @@ class VacuumRule(models.Model):
filename_pattern = fields.Char(
help=("If set, only attachments containing this pattern will be" " deleted.")
)
inheriting_model = fields.Char(
help="If set, this model will be searched and only related attachments will "
"be deleted.\n\nN.B: model must implement _inherits to link ir.attachment"
)
company_id = fields.Many2one(
"res.company",
string="Company",
@ -83,6 +87,32 @@ class VacuumRule(models.Model):
_("The Retention Time can't be 0 days")
)
@api.constrains("inheriting_model")
def _check_inheriting_model(self):
for rule in self.filtered(lambda r: r.inheriting_model):
if rule.ttype != "attachment":
raise exceptions.ValidationError(
_(
"Inheriting model cannot be used on rule where type is not attachment"
)
)
if (
rule.inheriting_model
not in self.env["ir.attachment"]._inherits_children
):
raise exceptions.ValidationError(
_("No inheritance of ir.attachment was found on model %s")
% rule.inheriting_model
)
attachment_field = self.env[rule.inheriting_model]._inherits.get(
"ir.attachment"
)
if not attachment_field:
raise exceptions.ValidationError(
_("Cannot find relation to ir.attachment on model %s")
% rule.inheriting_model
)
def _search_autovacuum_records(self):
self.ensure_one()
model = self.ttype

View File

@ -1,3 +1,4 @@
* Florian da Costa <florian.dacosta@akretion.com>
* Enric Tobella <etobella@creublanca.es>
* Helly kapatel <helly.kapatel@initos.com>
* Akim Juillerat <akim.juillerat@camptocamp.com>

View File

@ -423,6 +423,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<li>Florian da Costa &lt;<a class="reference external" href="mailto:florian.dacosta&#64;akretion.com">florian.dacosta&#64;akretion.com</a>&gt;</li>
<li>Enric Tobella &lt;<a class="reference external" href="mailto:etobella&#64;creublanca.es">etobella&#64;creublanca.es</a>&gt;</li>
<li>Helly kapatel &lt;<a class="reference external" href="mailto:helly.kapatel&#64;initos.com">helly.kapatel&#64;initos.com</a>&gt;</li>
<li>Akim Juillerat &lt;<a class="reference external" href="mailto:akim.juillerat&#64;camptocamp.com">akim.juillerat&#64;camptocamp.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">

View File

@ -38,6 +38,7 @@
</group>
<group attrs="{'invisible': [('ttype', '!=', 'attachment')]}">
<field name="filename_pattern" />
<field name="inheriting_model" />
</group>
<group string="Message Models">
<field name="model_ids" nolabel="1" />