From ce5fc3a1f233dabd796b6f9eddf1b4bbfe22c4f8 Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Tue, 7 Nov 2023 14:47:32 +0000 Subject: [PATCH] [FIX] l10n_it_edi_withholding: fix install with multiple IT companies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - Install Accounting - Create a Company located in Italy (e.g. Company A) - Create another company located in Italy (e.g. Company B) - Switch to Company A and set its fiscal localization to Italy in Accounting settings - Switch to Company B and set its fiscal localization to Italy in Accounting settings - Try to install "Italy - E-invoicing (Withholding)" module (10n_it_edi_withholding") => An User Error is raised: "Incompatible companies on records: - 'account.tax.repartition.line,688' belongs to company 'Company B' and 'Account' (account_id: '160900 Receivables for withholdings incurred') belongs to another company. - 'account.tax.repartition.line,690' belongs to company 'Company B' and 'Account' (account_id: '160900 Receivables for withholdings incurred') belongs to another company. - 'account.tax.repartition.line,692' belongs to company 'Company B' and 'Account' (account_id: '260200 Payables for withholding taxes to be paid') belongs to another company. - 'account.tax.repartition.line,694' belongs to company 'Company B' and 'Account' (account_id: '260200 Payables for withholding taxes to be paid') belongs to another company. - 'account.tax.repartition.line,696' belongs to company 'Company B' and 'Account' (account_id: '160900 Receivables for withholdings incurred') belongs to another company." Cause: When installing "10n_it_edi_withholding" module, some tax data are updated for each Italian company. These data are "generic" (not linked to any company) data, but some treatment is performed on them for the first Italian company, linking them to the account ids of that company. The following companies are then updated with data linked to the first company. opw-3538921 closes odoo/odoo#141898 X-original-commit: 9939789fd7024d864c365fe8f3ce311b96ba652c Signed-off-by: William André (wan) Signed-off-by: Anh Thao Pham (pta) --- addons/l10n_it_edi_withholding/__init__.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/addons/l10n_it_edi_withholding/__init__.py b/addons/l10n_it_edi_withholding/__init__.py index a8ca4231bc7..ef6df594e94 100644 --- a/addons/l10n_it_edi_withholding/__init__.py +++ b/addons/l10n_it_edi_withholding/__init__.py @@ -7,18 +7,11 @@ _logger = logging.getLogger(__name__) def _l10n_it_edi_withholding_post_init(env): """ Existing companies that have the Italian Chart of Accounts set """ - template_code = 'it' - data = { - model: env['account.chart.template']._parse_csv(template_code, model, module='l10n_it_edi_withholding') - for model in [ - 'account.account', - 'account.tax.group', - 'account.tax', - ] - } - for company in env['res.company'].search([('chart_template', '=', template_code)]): + for company in env['res.company'].search([('chart_template', '=', 'it')]): _logger.info("Company %s already has the Italian localization installed, updating...", company.name) - company_chart_template = env['account.chart.template'].with_company(company) - company_data = dict(data) - company_chart_template._deref_account_tags(template_code, company_data['account.tax']) - company_chart_template._load_data(company_data) + ChartTemplate = env['account.chart.template'].with_company(company) + ChartTemplate._load_data({ + 'account.account': ChartTemplate._get_it_withholding_account_account(), + 'account.tax': ChartTemplate._get_it_withholding_account_tax(), + 'account.tax.group': ChartTemplate._get_it_withholding_account_tax_group(), + })