[FIX] l10n_it_edi_withholding: fix install with multiple IT companies
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) <wan@odoo.com> Signed-off-by: Anh Thao Pham (pta) <pta@odoo.com>
This commit is contained in:
@@ -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(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user