diff --git a/addons/l10n_eu_oss/models/res_company.py b/addons/l10n_eu_oss/models/res_company.py index 0cc315296d5..eb109124055 100644 --- a/addons/l10n_eu_oss/models/res_company.py +++ b/addons/l10n_eu_oss/models/res_company.py @@ -26,7 +26,7 @@ class Company(models.Model): oss_tax_groups = self.env['ir.model.data'].search([ ('module', '=', 'l10n_eu_oss'), ('model', '=', 'account.tax.group')]) - for company in self: + for company in self.root_id: # instantiate OSS taxes on the root company only invoice_repartition_lines, refund_repartition_lines = company._get_repartition_lines_oss() taxes = self.env['account.tax'].search([ *self.env['account.tax']._check_company_domain(company), diff --git a/addons/l10n_eu_oss/tests/test_oss.py b/addons/l10n_eu_oss/tests/test_oss.py index 6d5cde0a94d..6d6da612127 100644 --- a/addons/l10n_eu_oss/tests/test_oss.py +++ b/addons/l10n_eu_oss/tests/test_oss.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- -from odoo.addons.l10n_eu_oss.models.eu_tag_map import EU_TAG_MAP +from odoo import Command from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.l10n_eu_oss.models.eu_tag_map import EU_TAG_MAP from odoo.tests import tagged @@ -24,8 +25,25 @@ class TestOSSBelgium(OssTemplateTestCase): @classmethod def setUpClass(cls, chart_template_ref='be_comp'): super().setUpClass(chart_template_ref) - cls.company_data['company'].country_id = cls.env.ref('base.be') - cls.company_data['company']._map_eu_taxes() + cls.root_company = cls.company_data['company'] + cls.root_company.country_id = cls.env.ref('base.be') + cls.root_company.child_ids = [Command.create({'name': 'Branch A'})] + cls.cr.precommit.run() # load the CoA + cls.child_company = cls.root_company.child_ids + cls.child_company.child_ids = [Command.create({'name': 'sub Branch B'})] + cls.sub_child_company = cls.root_company.child_ids.child_ids + cls.cr.precommit.run() # load the CoA + + cls.sub_child_company._map_eu_taxes() + + def test_oss_tax_should_be_instantiated_on_root_company(self): + # simulate sub child selection in the switcher + self.env.user.company_id, self.env.user.company_ids = self.sub_child_company, self.sub_child_company + + another_eu_country_code = (self.env.ref('base.europe').country_ids - self.sub_child_company.country_id)[0].code + tax_oss = self.env['account.tax'].search([('name', 'ilike', f'%{another_eu_country_code}%')], limit=1) + self.assertTrue(tax_oss) + self.assertEqual(tax_oss.company_id, self.root_company) def test_country_tag_from_belgium(self): """