From 23ea458a811f2b37051903cd73029fa80a1fd01b Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Tue, 19 Mar 2024 13:32:00 +0000 Subject: [PATCH] [FIX] account: Prevent deleting basic accounting pdf reports Those master data would break the basic accounting pdf generation flow as those are widely used and it is not expected from end users to delete them. Example of support ticket from that issue: 3790875 closes odoo/odoo#158637 Taskid: 3802440 X-original-commit: b1ecc922503ff3a9618e89afd13659e37eb3fbed Signed-off-by: Yannick Tivisse (yti) --- addons/account/i18n/account.pot | 9 +++++++++ addons/account/models/ir_actions_report.py | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 672a158a975..705f9959ab9 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -15972,6 +15972,15 @@ msgid "" "and is not the last one in the chain. You should probably revert it instead." msgstr "" +#. module: account +#. odoo-python +#: code:addons/account/models/ir_actions_report.py:0 +#, python-format +msgid "" +"You cannot delete this report (%s), it is used by the accounting PDF " +"generation engine." +msgstr "" + #. module: account #. odoo-python #: code:addons/account/models/res_config_settings.py:0 diff --git a/addons/account/models/ir_actions_report.py b/addons/account/models/ir_actions_report.py index d504eac3ae9..a1d46948c50 100644 --- a/addons/account/models/ir_actions_report.py +++ b/addons/account/models/ir_actions_report.py @@ -6,7 +6,7 @@ try: except ImportError: from PyPDF2.utils import PdfStreamError, PdfReadError -from odoo import models, _ +from odoo import api, models, _ from odoo.exceptions import UserError from odoo.tools import pdf @@ -59,3 +59,19 @@ class IrActionsReport(models.Model): raise UserError(_("Only invoices could be printed.")) return super()._render_qweb_pdf(report_ref, res_ids=res_ids, data=data) + + @api.ondelete(at_uninstall=False) + def _unlink_except_master_tags(self): + master_xmlids = [ + "account_invoices", + "action_account_original_vendor_bill" + "account_invoices_without_payment", + "action_report_journal", + "action_report_payment_receipt", + "action_report_account_statement", + "action_report_account_hash_integrity", + ] + for master_xmlid in master_xmlids: + master_report = self.env.ref(f"account.{master_xmlid}", raise_if_not_found=False) + if master_report and master_report in self: + raise UserError(_("You cannot delete this report (%s), it is used by the accounting PDF generation engine.", master_report.name))