From 79010e68c37e3695ef4f8aef164751911ffd5672 Mon Sep 17 00:00:00 2001 From: "Carsten Wolff (cawo)" Date: Fri, 29 Mar 2024 08:44:15 +0000 Subject: [PATCH] [FIX] account: CoA load: only update tags in existing accounts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The intended behavior to only update tags and no other fields on existing accounts during CoA loading was originally introduced in https://github.com/odoo/odoo/pull/125320 and has recently been broken by commit f2861b9d8d50 (https://github.com/odoo/odoo/pull/155256). This has been recognized because of failing requests in the upgrade platform when it tried to update the `code` field, which lead to excessive recomputations and in turn to MemoryErrors. The problem is that the tests, if the current `xmlid` constitutes a record update or a new record[^1], need to be correct, no matter if the code above[^2] managed to update the `xmlid` pointer or not. Thus, restore the previous logic regarding that by only assigning the alternative record to the `account` var if it is not None. [^1]: https://github.com/odoo/odoo/blob/35bb495d5e5a8dac563ba4dee1702d77e4b71461/addons/account/models/chart_template.py#L312 and https://github.com/odoo/odoo/blob/35bb495d5e5a8dac563ba4dee1702d77e4b71461/addons/account/models/chart_template.py#L314 [^2]: https://github.com/odoo/odoo/blob/35bb495d5e5a8dac563ba4dee1702d77e4b71461/addons/account/models/chart_template.py#L303 closes odoo/odoo#159950 X-original-commit: daa3747e94a6b7000617be91c0c33569bf3bd484 Signed-off-by: William André (wan) --- addons/account/models/chart_template.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index 973e12dd3d4..8458265f9e3 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -335,13 +335,14 @@ class AccountChartTemplate(models.AbstractModel): query = self.env['account.account']._search(self.env['account.account']._check_company_domain(company)) query.add_where("account_account.code SIMILAR TO %s", [f'{values["code"]}0*']) accounts = self.env['account.account'].browse(query) - account = accounts.sorted(key=lambda x: x.code != normalized_code)[0] if accounts else None - if account: + existing_account = accounts.sorted(key=lambda x: x.code != normalized_code)[0] if accounts else None + if existing_account: self.env['ir.model.data']._update_xmlids([{ 'xml_id': f"account.{company.id}_{xmlid}", - 'record': account, + '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]: