[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) <yti@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user