From f9d00055dad27e6b60207f3b7d9401d2c539ae41 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 20 Jun 2018 10:20:15 +0200 Subject: [PATCH] [FIX] l10n_es: fix chart_template installation Since d5359cfcf49e1796b95b52b2d618617c49ed847b, it's no longer possible to install the l10n_es chart templates. Indeed, the transfer account template is generated twice with the same code due to the addition of a domain in the previous commit: ('chart_template_id', '=', self.id) ...that doesn't take care about the hierarchy of chart template (through the parent_id field). --- addons/account/models/chart_template.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index b529cfa3b28..16b7c6dc690 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -138,7 +138,8 @@ class AccountChartTemplate(models.Model): new_code = '' for num in range(1, 100): new_code = str(prefix.ljust(digits - 1, '0')) + str(num) - rec = self.env['account.account.template'].search([('code', '=', new_code), ('chart_template_id', '=', self.id)], limit=1) + rec = self.env['account.account.template'].search( + [('code', '=', new_code), '|', ('chart_template_id', 'child_of', self.id), ('chart_template_id', 'parent_of', self.id)], limit=1) if not rec: break else: @@ -1043,8 +1044,14 @@ class IrModelData(models.Model): # - an entry in ir_model_data: this allow to still use the method create_record_with_xmlid() and don't make any difference between # regular accounts created and that liquidity transfer account if model == 'account.chart.template' and xml_id and module: + chart_template = self.env[model].browse(record_id) + + # Create the transfer account only for leaf chart template in the hierarchy. + if chart_template.parent_id: + return record_id + new_xml_id = xml_id + '_liquidity_transfer' if not self.search([('model', '=', 'account.account.template'), ('module', '=', module), ('name', '=', new_xml_id)]): - vals = self.env[model].browse(record_id)._prepare_transfer_account_template() + vals = chart_template._prepare_transfer_account_template() self._update('account.account.template', module, vals, xml_id=new_xml_id, store=True, noupdate=noupdate, mode=mode, res_id=False) return record_id