[FIX] l10n_eu_oss: OSS tax on root company only

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) <wan@odoo.com>
Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
Brice bib Bartoletti
2023-11-10 13:46:57 +00:00
parent 6a729b3f13
commit 83d551e24f
2 changed files with 22 additions and 4 deletions
+1 -1
View File
@@ -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),
+21 -3
View File
@@ -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):
"""