[FIX] account: CoA load: only update tags in existing accounts
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) <wan@odoo.com>
This commit is contained in:
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user