From a4a94fa13388f4d3946f600d2205a293293f1885 Mon Sep 17 00:00:00 2001 From: Jinane Maksoud Date: Thu, 29 Jun 2023 11:21:24 +0000 Subject: [PATCH] [FIX] account: match journal by type and name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When upgrading and loading data from templates, there could be journals that match our target but the code is modified by the users. The code may be different due to translations or simply a user choice, but the journal can be the standard one. And the noupdate=True that is on the xmlids of the created journals confirm that it is possible for the users to keep their customizations on the journals. Matching the journals by type and name can be an alternative to creating a duplicate journal, which will cause more conflict down the line (for ex. the unique constraint on mail aliases) closes odoo/odoo#128139 X-original-commit: 069714ee8e7175ab92a4d28b75e3725ea0be1b0f Signed-off-by: William André (wan) Signed-off-by: Jinane Maksoud (maji) --- addons/account/models/chart_template.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index bc515bc498c..07cb080dfc2 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -218,11 +218,19 @@ class AccountChartTemplate(models.AbstractModel): for xmlid, journal_data in list(data.get('account.journal', {}).items()): if self.ref(xmlid, raise_if_not_found=False): del data['account.journal'][xmlid] - elif 'code' in journal_data: - journal = self.env['account.journal'].with_context(active_test=False).search([ - ('code', '=', journal_data['code']), - ('company_id', '=', company.id), - ]) + else: + if 'code' in journal_data: + journal = self.env['account.journal'].with_context(active_test=False).search([ + ('code', '=', journal_data['code']), + ('company_id', '=', company.id), + ]) + # Try to match by journal name to avoid conflict in the unique constraint on the mail alias + if not journal and 'name' in journal_data and 'type' in journal_data: + journal = self.env['account.journal'].with_context(active_test=False).search([ + ('type', '=', journal_data['type']), + ('name', '=', journal_data['name']), + ('company_id', '=', company.id), + ], limit=1) if journal: del data['account.journal'][xmlid] self.env['ir.model.data']._update_xmlids([{