From 0778891cc976052ec6cd974bbb94d967e9cc912a Mon Sep 17 00:00:00 2001 From: "Carsten Wolff (cawo)" Date: Thu, 15 Jun 2023 13:08:44 +0000 Subject: [PATCH] [FIX] account: avoid unneeded updates during chart data reload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During upgrade, l10n migration scripts that call `try_loading()` can cause an exception _You cannot switch an account to prevent the reconciliation_ in `_toggle_reconcile_to_false()` of model `account.account`. This is caused by new chart template data containing a _False_ value for the _reconcile_ field, while the already existing record has this field set to _True_. Under this constellation, the code path leads into `_toggle_reconcile_to_false()`, which checks for partial reconciliation and throws the exception when the record is under partial reconciliation. Also, the update of existing account.account data from the default data triggers a lot of superfluous re-computes. To avoid both the update of the reconcile field as well as other unnecessary updates that trigger superfluous re-computes, filter the default data in the update case to only update `tag_ids`. This is done after the code that fixes XMLIDs to be sure about whether the record is being updated or created. closes odoo/odoo#127099 X-original-commit: 2a8100e9ee8d49a957c1aab21a5a533a28dc2060 Signed-off-by: Carsten Wolff (cawo) Signed-off-by: William André (wan) --- addons/account/models/chart_template.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index a3cdc41a99d..4891e38e4a7 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -249,6 +249,7 @@ class AccountChartTemplate(models.AbstractModel): ) obsolete_xmlid = set() + skip_update = set() for model_name, records in data.items(): _fields = self.env[model_name]._fields for xmlid, values in records.items(): @@ -313,6 +314,15 @@ class AccountChartTemplate(models.AbstractModel): 'record': existing_account, 'noupdate': True, }]) + account = existing_account + # on existing accounts, only tag_ids are to be updated using default data + if account and 'tag_ids' in data[model_name][xmlid]: + data[model_name][xmlid] = {'tag_ids': data[model_name][xmlid]['tag_ids']} + elif account: + skip_update.add((model_name, xmlid)) + + for skip_model, skip_xmlid in skip_update: + data[skip_model].pop(skip_xmlid, None) if obsolete_xmlid: self.env['ir.model.data'].search([ @@ -353,7 +363,8 @@ class AccountChartTemplate(models.AbstractModel): # Normalize the code_digits of the accounts code_digits = int(template_data.get('code_digits', 6)) for key, account_data in data.get('account.account', {}).items(): - data['account.account'][key]['code'] = f'{account_data["code"]:<0{code_digits}}' + if 'code' in account_data: + data['account.account'][key]['code'] = f'{account_data["code"]:<0{code_digits}}' for model in ('account.fiscal.position', 'account.reconcile.model'): if model in data: