From 83d551e24f1a95b3ab50833bb805ac60f76f5b91 Mon Sep 17 00:00:00 2001 From: Brice bib Bartoletti Date: Mon, 30 Oct 2023 12:55:50 +0100 Subject: [PATCH] [FIX] l10n_eu_oss: OSS tax on root company only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The aim of this commit is to make the OSS feature instanciate the taxes on the the root company . Context: currently, when a company has a branch, the OSS feature tries to instanciate the taxes on both the root company and the branch company. This was brought up by a constrains that prevents you from instanciating 2 tax with the same name on the same company. Before the commit: The feature tries to instanciate the OSS taxes on both the root and branch company. After the commit: The taxes are only instanciated on the root company. closes odoo/odoo#141347 Task-id: 3573252 Signed-off-by: William André (wan) Signed-off-by: Brice Bartoletti (bib) --- addons/l10n_eu_oss/models/res_company.py | 2 +- addons/l10n_eu_oss/tests/test_oss.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) 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): """