From f7dc38f18d6a8235fcd3eaf2a88e18d17fcf4f9c Mon Sep 17 00:00:00 2001 From: Edoardo Piroli Date: Thu, 15 Feb 2024 13:55:39 +0100 Subject: [PATCH] [FIX] account: cascade expression removal to account.report.external.value Cascade removal of account.report.expression records to corresponding account.report.external.value, avoiding the following issue when upgrading: ``` Traceback (most recent call last): File "/home/odoo/src/odoo/17.0/odoo/service/server.py", line 1302, in preload_registries registry = Registry.new(dbname, update_module=update_module) File "", line 2, in new File "/home/odoo/src/odoo/17.0/odoo/tools/func.py", line 87, in locked return func(inst, *args, **kwargs) File "/home/odoo/src/odoo/17.0/odoo/modules/registry.py", line 113, in new odoo.modules.load_modules(registry, force_demo, status, update_module) File "/home/odoo/src/odoo/17.0/odoo/modules/loading.py", line 536, in load_modules env['ir.model.data']._process_end(processed_modules) File "/tmp/tmpwrjjshgf/migrations/base/0.0.0/pre-models-no-model-data-delete.py", line 103, in _process_end return super(IrModelData, self)._process_end(modules) File "/home/odoo/src/odoo/17.0/odoo/addons/base/models/ir_model.py", line 2562, in _process_end self._process_end_unlink_record(record) File "/home/odoo/src/odoo/17.0/addons/website/models/ir_model_data.py", line 36, in _process_end_unlink_record return super()._process_end_unlink_record(record) File "/home/odoo/src/odoo/17.0/odoo/addons/base/models/ir_model.py", line 2491, in _process_end_unlink_record record.unlink() File "/home/odoo/src/odoo/17.0/odoo/models.py", line 4218, in unlink cr.execute(SQL( File "/home/odoo/src/odoo/17.0/odoo/sql_db.py", line 332, in execute res = self._obj.execute(query, params) psycopg2.errors.ForeignKeyViolation: update or delete on table "account_report_expression" violates foreign key constraint "account_report_external_value_target_report_expression_id_fkey" on table "account_report_external_value" DETAIL: Key (id)=(94) is still referenced from table "account_report_external_value". ``` closes odoo/odoo#155242 X-original-commit: d28ae22e08c86392f3d772d3d7564b1b8e70e7e0 Signed-off-by: Olivier Colson (oco) --- addons/account/models/account_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/models/account_report.py b/addons/account/models/account_report.py index ed0fafe4472..265ffffcc18 100644 --- a/addons/account/models/account_report.py +++ b/addons/account/models/account_report.py @@ -833,7 +833,7 @@ class AccountReportExternalValue(models.Model): text_value = fields.Char(string="Text Value") date = fields.Date(required=True) - target_report_expression_id = fields.Many2one(string="Target Expression", comodel_name="account.report.expression", required=True) + target_report_expression_id = fields.Many2one(string="Target Expression", comodel_name="account.report.expression", required=True, ondelete="cascade") target_report_line_id = fields.Many2one(string="Target Line", related="target_report_expression_id.report_line_id") target_report_expression_label = fields.Char(string="Target Expression Label", related="target_report_expression_id.label") report_country_id = fields.Many2one(string="Country", related='target_report_line_id.report_id.country_id')