From e907b132dc74f272be60d255442b2821519cba2e Mon Sep 17 00:00:00 2001 From: Atul Patel Date: Thu, 18 Apr 2024 09:51:06 +0000 Subject: [PATCH] [FIX] account: avoid a uniqueness constraint violation for journal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit step to reproduce: 1. account journal with `INV` code AND `FAC` translated code, will get two journal which was raise traceback as we have unique constraint raised. these are two journal with 1. INV code 2. FAC code as translated code so will get two journal and got traceback ``` select name,id, code from account_journal where id in (12,13); name | id | code ----------------------------------------------------------------------+----+------ {"en_US": "Factures clients", "fr_BE": "Factures clients"} | 12 | FAC {"en_US": "Factures fournisseurs", "fr_BE": "Factures fournisseurs"} | 13 | INV (2 rows) File "/tmp/tmpwqzy2fx8/migrations/account/saas~16.2.1.2/end-migrate.py", line 50, in migrate ChartTemplate._pre_reload_data(company, template_data, data) File "/home/odoo/src/odoo/17.0/addons/account/models/chart_template.py", line 264, in _pre_reload_data self.env['ir.model.data']._update_xmlids([{ File "/home/odoo/src/odoo/17.0/odoo/addons/base/models/ir_model.py", line 2270, in _update_xmlids rows.add((prefix, suffix, record._name, record.id, noupdate)) File "/home/odoo/src/odoo/17.0/odoo/fields.py", line 5142, in __get__ raise ValueError("Expected singleton: %s" % record) ValueError: Expected singleton: account.journal(12, 13) ``` closes odoo/odoo#163185 X-original-commit: 32b4bd2e146522c3feb03e34d0e9bd3261e37cbe Signed-off-by: Atul Patel (atp) Signed-off-by: William André (wan) --- addons/account/models/chart_template.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index c5110e26c21..7371d58de40 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -245,9 +245,10 @@ class AccountChartTemplate(models.AbstractModel): 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_code = translated_code or journal_data['code'] journal = self.env['account.journal'].with_context(active_test=False).search([ *self.env['account.journal']._check_company_domain(company), - ('code', 'in', (journal_data['code'], translated_code)), + ('code', '=', journal_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)