diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index e3325b06755..f09a147308b 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -5,6 +5,7 @@ import csv from collections import defaultdict from functools import wraps from inspect import getmembers +from copy import deepcopy import logging import re @@ -495,7 +496,7 @@ class AccountChartTemplate(models.AbstractModel): created_models.add(model) created_vals = {} - for model, data in defer(list(data.items())): + for model, data in defer(list(deepcopy(data).items())): create_vals = [] for xml_id, record in data.items(): # Extract the translations from the values diff --git a/addons/l10n_ar_withholding/__init__.py b/addons/l10n_ar_withholding/__init__.py index cb742dc6a2e..170707ae9f4 100644 --- a/addons/l10n_ar_withholding/__init__.py +++ b/addons/l10n_ar_withholding/__init__.py @@ -12,7 +12,9 @@ _logger = logging.getLogger(__name__) def _l10n_ar_withholding_post_init(env): """ Existing companies that have the Argentinean Chart of Accounts set """ template_codes = ['ar_ri', 'ar_ex', 'ar_base'] - for template_code in template_codes: + ar_companies = env['res.company'].search([('chart_template', 'in', template_codes)]) + used_template_codes = set(ar_companies.mapped('chart_template')) + for template_code in used_template_codes: data = { model: env['account.chart.template']._parse_csv(template_code, model, module='l10n_ar_withholding') for model in [ @@ -21,12 +23,11 @@ def _l10n_ar_withholding_post_init(env): 'account.tax', ] } - for company in env['res.company'].search([('chart_template', '=', template_code)]): + for company in ar_companies.filtered(lambda c: c.chart_template == template_code): _logger.info("Company %s already has the Argentinean 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) + company_chart_template._deref_account_tags(template_code, data['account.tax']) + company_chart_template._load_data(data) company.l10n_ar_tax_base_account_id = env.ref('account.%i_base_tax_account' % company.id) if env.ref('base.module_l10n_ar_withholding').demo: