[FIX] account, l10n_ar_withholding: fix install with multiple AR companies
Steps to reproduce: - Install Accounting and l10n_ar - Create 2 companies located in Argentina (e.g. Company A & Company B) - Switch to Company A - Go to Accounting settings - Set Fiscal Localization to Argentina (e.g. Argentina - Argentine Generic Chart of Accounts for Excempt individuals) - Switch to Company B - Go to Accounting settings - Set Fiscal Localization to the same Fiscal Localization than Company A (i.e. Argentina - Argentine Generic Chart of Accounts for Excempt individuals) - Try to install "l10n_ar_withholding" module Issue: A User Error is raised: "Incompatible companies on records: - 'account.tax.repartition.line,1230' belongs to company 'Company A' and 'Account' (account_id: '1.1.4.03.020 SUSS Withholding incurred') belongs to another company. - 'account.tax.repartition.line,1232' belongs to company 'Company A' and 'Account' (account_id: '1.1.4.03.020 SUSS Withholding incurred') belongs to another company. - 'account.tax.repartition.line,1234' belongs to company 'Company A' and 'Account' (account_id: '1.1.4.05.030 Withholdings of Profits incurred') belongs to another company. - 'account.tax.repartition.line,1236' belongs to company 'Company A' and 'Account' (account_id: '1.1.4.05.030 Withholdings of Profits incurred') belongs to another company." Cause: When installing "l10n_ar_withholding" module, each Argentine company is updated with some tax data. These data are "generic" (not linked to any company) and used for each company, but some treatment is performed on them by the first Argentine company, linking them to the account ids of that company. The following companies are then updated with data linked to the first company. Solution: Compute the data for each company. opw-3709819 closes odoo/odoo#154219 Signed-off-by: Cedric Snauwaert <csn@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user