[FIX] l10n_es,l10n_eu_service: OSS with Spain

The aim of this commit is to:
- allow OSS to use tax that aren't declare by TaxReportLine
- have the oss tax automatically populated with the correct tags for spanish
  tax report
- Add taxes specific to the spanish OSS : No sujeto y acogidas a la OSS (Servicios) and No sujeto y acogidas a la OSS (Bienes)
  using the official modulo 124 tag

closes odoo/odoo#101121

Community-pr: https://github.com/odoo/odoo/pull/99273
Task: 2930758
X-original-commit: 2a21e4c084ba952eba1b4a7bb6f6ee31875d70ea
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Camille Spiritus (casp) <casp@odoo.com>
Co-authored-by: Camille Casp Spiritus <casp@odoo.com>
This commit is contained in:
Brice bib Bartoletti
2022-09-26 14:43:27 +02:00
co-authored by Camille Casp Spiritus
parent 291d752ad5
commit 5e7da9c8ca
4 changed files with 121 additions and 13 deletions
+68
View File
@@ -1004,6 +1004,40 @@
(0,0, {'repartition_type': 'tax'}),
]"/>
</record>
<record id="account_tax_template_oss_s_iva_ns" model="account.tax.template">
<field name="description">No sujeto y acogidas a la OSS (Servicios)</field>
<field name="type_tax_use">sale</field>
<field name="name">No sujeto y acogidas a la OSS (Servicios)</field>
<field name="chart_template_id" ref="l10n_es.account_chart_template_common"/>
<field name="amount" eval="0"/>
<field name="amount_type">percent</field>
<field name="tax_group_id" ref="tax_group_iva_0"/>
<field name="invoice_repartition_line_ids" eval="[(5, 0, 0),
(0,0, {
'factor_percent': 100,
'repartition_type': 'base',
'tag_ids': [ref('mod_303_123')],
}),
(0,0, {
'factor_percent': 100,
'repartition_type': 'tax',
}),
]"/>
<field name="refund_repartition_line_ids" eval="[(5, 0, 0),
(0,0, {
'factor_percent': 100,
'repartition_type': 'base',
'tag_ids': [ref('mod_303_123')],
}),
(0,0, {
'factor_percent': 100,
'repartition_type': 'tax',
}),
]"/>
</record>
<record id="account_tax_template_s_iva_ns_b" model="account.tax.template">
<field name="description">No sujeto (Bienes)</field>
<field name="type_tax_use">sale</field>
@@ -1027,6 +1061,40 @@
(0,0, {'repartition_type': 'tax'}),
]"/>
</record>
<record id="account_tax_template_oss_s_iva_ns_b" model="account.tax.template">
<field name="description">No sujeto y acogidas a la OSS (Bienes)</field>
<field name="type_tax_use">sale</field>
<field name="name">No sujeto y acogidas a la OSS (Bienes)</field>
<field name="chart_template_id" ref="l10n_es.account_chart_template_common"/>
<field name="amount" eval="0"/>
<field name="amount_type">percent</field>
<field name="tax_group_id" ref="tax_group_iva_0"/>
<field name="invoice_repartition_line_ids" eval="[(5, 0, 0),
(0,0, {
'factor_percent': 100,
'repartition_type': 'base',
'tag_ids': [ref('mod_303_123')],
}),
(0,0, {
'factor_percent': 100,
'repartition_type': 'tax',
}),
]"/>
<field name="refund_repartition_line_ids" eval="[(5, 0, 0),
(0,0, {
'factor_percent': 100,
'repartition_type': 'base',
'tag_ids': [ref('mod_303_123')],
}),
(0,0, {
'factor_percent': 100,
'repartition_type': 'tax',
}),
]"/>
</record>
<record id="account_tax_template_s_iva_e" model="account.tax.template">
<field name="description">Extracomunitario (Servicios)</field>
<field name="type_tax_use">sale</field>
+1 -1
View File
@@ -199,7 +199,7 @@ EU_TAG_MAP = {
},
# Spain
'l10n_es.account_chart_template_common': {
'invoice_base_tag': None,
'invoice_base_tag': "l10n_es.mod_303_124",
'invoice_tax_tag': None,
'refund_base_tag': None,
'refund_tax_tag': None,
+11 -11
View File
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, Command
from .eu_tax_map import EU_TAX_MAP
from odoo import Command, api, models
from .eu_tag_map import EU_TAG_MAP
from .eu_tax_map import EU_TAX_MAP
class Company(models.Model):
@@ -127,7 +127,7 @@ class Company(models.Model):
def _get_oss_tags(self):
oss_tag = self.env.ref('l10n_eu_oss.tag_oss')
[chart_template_xml_id] = self.chart_template_id.get_external_id().values()
[chart_template_xml_id] = self.chart_template_id.parent_id.get_external_id().values() or self.chart_template_id.get_external_id().values()
tag_for_country = EU_TAG_MAP.get(chart_template_xml_id, {
'invoice_base_tag': None,
'invoice_tax_tag': None,
@@ -135,11 +135,11 @@ class Company(models.Model):
'refund_tax_tag': None,
})
return {
repartition_line_key: (
self.env.ref(tag_xml_id)._get_matching_tags().filtered(lambda t: not t.tax_negate)
if tag_xml_id
else self.env['account.account.tag']
) + oss_tag
for repartition_line_key, tag_xml_id in tag_for_country.items()
}
mapping = {}
for repartition_line_key, tag_xml_id in tag_for_country.items():
tag = self.env.ref(tag_xml_id) if tag_xml_id else self.env['account.account.tag']
if tag and tag._name == "account.report.expression":
tag = tag._get_matching_tags().filtered(lambda t: not t.tax_negate)
mapping[repartition_line_key] = tag + oss_tag
return mapping
+41 -1
View File
@@ -21,6 +21,10 @@ class TestOSSBelgium(AccountTestInvoicingCommon):
cls.company_data['company']._map_eu_taxes()
def test_country_tag_from_belgium(self):
"""
This test ensure that xml_id from `account.tax.report.line` in the EU_TAG_MAP are processed correctly by the oss
tax creation mechanism.
"""
# get an eu country which isn't the current one:
another_eu_country_code = (self.env.ref('base.europe').country_ids - self.company_data['company'].country_id)[0].code
tax_oss = self.env['account.tax'].search([('name', 'ilike', f'%{another_eu_country_code}%')], limit=1)
@@ -41,6 +45,43 @@ class TestOSSBelgium(AccountTestInvoicingCommon):
self.assertIn(expected_tag_id, oss_tag_id, f"{doc_type} tag from Belgian CoA not correctly linked")
@tagged('post_install', 'post_install_l10n', '-at_install')
class TestOSSSpain(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls, chart_template_ref='l10n_es.account_chart_template_common'):
try:
super().setUpClass(chart_template_ref=chart_template_ref)
except ValueError as e:
if e.args[0] == "External ID not found in the system: l10n_es.account_chart_template_data":
cls.skipTest(cls, reason="Spanish CoA is required for this testSuite but l10n_es isn't installed")
else:
raise e
cls.company_data['company'].country_id = cls.env.ref('base.es')
cls.company_data['company']._map_eu_taxes()
def test_country_tag_from_spain(self):
"""
This test ensure that xml_id from `account.account.tag` in the EU_TAG_MAP are processed correctly by the oss
tax creation mechanism.
"""
# get an eu country which isn't the current one:
another_eu_country_code = (self.env.ref('base.europe').country_ids - self.company_data['company'].country_id)[0].code
tax_oss = self.env['account.tax'].search([('name', 'ilike', f'%{another_eu_country_code}%')], limit=1)
for doc_type, tag_xml_id in (
("invoice", "l10n_es.mod_303_124"),
):
with self.subTest(doc_type=doc_type, report_line_xml_id=tag_xml_id):
oss_tag_id = tax_oss[f"{doc_type}_repartition_line_ids"]\
.filtered(lambda x: x.repartition_type == 'base')\
.tag_ids
expected_tag_id = self.env.ref(tag_xml_id)
self.assertIn(expected_tag_id, oss_tag_id, f"{doc_type} tag from Spanish CoA not correctly linked")
@tagged('post_install', 'post_install_l10n', '-at_install')
class TestOSSUSA(AccountTestInvoicingCommon):
@@ -58,7 +99,6 @@ class TestOSSUSA(AccountTestInvoicingCommon):
self.assertFalse(len(tax_oss), "OSS tax shouldn't be instanced on a US company")
@tagged('post_install', 'post_install_l10n', '-at_install')
class TestOSSMap(AccountTestInvoicingCommon):