From c7231773cd3ba5eac99a297a13f06caa769278a0 Mon Sep 17 00:00:00 2001 From: Sven Fuehr Date: Wed, 27 Mar 2024 11:33:03 +0000 Subject: [PATCH] [FIX] account: on chart reload: fix matching journals without xmlid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently there is the following problem when reloading the chart. Journals without xmlid may not be matched to chart data correctly (via code or name). This then leads to duplicate journals being created / uniqueness constraint issues on journal codes. The matching happens in `_pre_reload_data`. This should only be a problem for upgrade or user created journals since journals created from the chart data have an xmlid. The problem was introduced in commit d6695f2892ded178371f6c69cf594037c19ce438 : (1) We load the chart data in en_US to be able to use the code translations (2) We switched the language of the loading process to en_US (to switch the chart data to en_US for the previous point and to avoid inconsistencies) When matching journals in the DB by code or name to the chart data: - We fetch the en_US name of the journals in the DB due to (2); Code is not translatable. - We compare those values (journal code / name) against the en_US term due to (1). Thus the matching fails. This commit improves the matching: We also compare the name and code (still en_US version) against the translated values. closes odoo/odoo#159871 X-original-commit: 005ebd59cba6b6ca20c736c46d89259af8bd251a Signed-off-by: William André (wan) Signed-off-by: Sven Führ (svfu) --- addons/account/models/chart_template.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index bc1f2edcac6..973e12dd3d4 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -244,17 +244,20 @@ class AccountChartTemplate(models.AbstractModel): del data['account.journal'][xmlid] else: journal = None + lang = self._get_untranslatable_fields_target_language(company.chart_template, company) + translated_code = self._get_field_translation(journal_data, 'code', lang) if 'code' in journal_data: journal = self.env['account.journal'].with_context(active_test=False).search([ *self.env['account.journal']._check_company_domain(company), - ('code', '=', journal_data['code']), + ('code', 'in', (journal_data['code'], translated_code)), ]) # Try to match by journal name to avoid conflict in the unique constraint on the mail alias + translated_name = self._get_field_translation(journal_data, 'name', lang) if not journal and 'name' in journal_data and 'type' in journal_data: journal = self.env['account.journal'].with_context(active_test=False).search([ *self.env['account.journal']._check_company_domain(company), ('type', '=', journal_data['type']), - ('name', '=', journal_data['name']), + ('name', 'in', (journal_data['name'], translated_name)), ], limit=1) if journal: del data['account.journal'][xmlid]