[FIX] account: fix foreign taxes creation with group-type taxes
Steps to reproduce: - Install Accounting - Create a fiscal position for a foreign country: * Country: [Any country that has group-type taxes] (e.g. Italy) * Foreign Tax ID: [any tax ID for that country] (e.g. IT12345670017) - Click on the "here" button appearing in the banner (Click "here" to create the taxes for this country.) => A ValueError is raised. "External ID not found in the system: account.1_22vsp" Cause: During the creation of the taxes, the xml_id of each tax is prefixed with the chart template code to avoid collision. However, when linking a group-type tax to its children taxes, it cannot find them because they are prefixed but the group-type tax is using their unprefixed value. opw-3518213 closes odoo/odoo#141448 X-original-commit: 3c22a2d4766e2401e25f2fe8eb0aadc0e9f77524 Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com> Signed-off-by: Anh Thao Pham (pta) <pta@odoo.com>
This commit is contained in:
@@ -812,6 +812,13 @@ class AccountChartTemplate(models.AbstractModel):
|
||||
}
|
||||
for model, templates in data.items()
|
||||
}
|
||||
# add the prefix to the "children_tax_ids" value for group-type taxes
|
||||
for tax_data in data['account.tax'].values():
|
||||
if tax_data.get('amount_type') == 'group':
|
||||
children_taxes = tax_data['children_tax_ids'].split(',')
|
||||
for idx, child_tax in enumerate(children_taxes):
|
||||
children_taxes[idx] = f"{chart_template_code}_{child_tax}"
|
||||
tax_data['children_tax_ids'] = ','.join(children_taxes)
|
||||
self._load_data(data)
|
||||
|
||||
# --------------------------------------------------------------------------------
|
||||
|
||||
@@ -98,11 +98,20 @@ def data_method_provider(chart_template_name, country_code):
|
||||
},
|
||||
},
|
||||
'account.tax': {
|
||||
xmlid: _tax_vals(name, amount, external_id_prefix)
|
||||
for name, xmlid, amount in (
|
||||
('Tax 1', 'test_tax_1_template', 15),
|
||||
('Tax 2', 'test_tax_2_template', 0),
|
||||
)
|
||||
**{
|
||||
xmlid: _tax_vals(name, amount, external_id_prefix)
|
||||
for name, xmlid, amount in (
|
||||
('Tax 1', 'test_tax_1_template', 15),
|
||||
('Tax 2', 'test_tax_2_template', 0),
|
||||
)
|
||||
},
|
||||
'test_composite_tax_template': {
|
||||
'name': 'Tax Grouped',
|
||||
'amount_type': 'group',
|
||||
'type_tax_use': 'purchase',
|
||||
'tax_group_id': 'tax_group_taxes',
|
||||
'children_tax_ids': 'test_tax_1_template,test_tax_2_template',
|
||||
}
|
||||
},
|
||||
}
|
||||
return test_data_getter
|
||||
@@ -175,8 +184,10 @@ class TestMultiVAT(TransactionCase):
|
||||
# tax
|
||||
'test_tax_1_template',
|
||||
'test_tax_2_template',
|
||||
'test_composite_tax_template',
|
||||
'foreign_test_tax_1_template',
|
||||
'foreign_test_tax_2_template',
|
||||
'foreign_test_composite_tax_template'
|
||||
):
|
||||
with self.subTest(xml_id=xml_id):
|
||||
record = self.env["account.chart.template"].ref(xml_id, raise_if_not_found=False)
|
||||
@@ -223,3 +234,17 @@ class TestMultiVAT(TransactionCase):
|
||||
_base_line, tax_line = tax.invoice_repartition_line_ids
|
||||
self.assertEqual(tax_line.account_id.code, '411001',
|
||||
"The previously created tax account should be reused for similar tax")
|
||||
|
||||
def test_children_taxes(self):
|
||||
# Ensure that group-type taxes are correctly linked to their children
|
||||
composite_taxes = ['test_composite_tax_template', 'foreign_test_composite_tax_template']
|
||||
children_taxes = {
|
||||
'test_composite_tax_template': ['test_tax_1_template', 'test_tax_2_template'],
|
||||
'foreign_test_composite_tax_template': ['foreign_test_tax_1_template', 'foreign_test_tax_2_template'],
|
||||
}
|
||||
for xml_id in composite_taxes:
|
||||
with self.subTest(xml_id=xml_id):
|
||||
record = self.env["account.chart.template"].ref(xml_id, raise_if_not_found=False)
|
||||
for i, child in enumerate(record.children_tax_ids):
|
||||
child_tax = self.env["account.chart.template"].ref(children_taxes[xml_id][i], raise_if_not_found=False)
|
||||
self.assertEqual(child.id, child_tax.id)
|
||||
|
||||
Reference in New Issue
Block a user