Skip to content

Commit 702b542

Browse files
committed
[FIX] l10n_es_aeat_sii_oca: Merge dicts when no breakdown
After not doing breakdown, a problem has been discovered if there are 2 taxes of the same percentage, like 21% services and 21% goods. For solving it, we move the `_merge_tax_dict` auxiliar method to the mixin, and using it for the out taxes dictionary generation. It includes an extra JSON file for tests for exercizing the problem.
1 parent 48c3d55 commit 702b542

4 files changed

Lines changed: 61 additions & 14 deletions

File tree

l10n_es_aeat_sii_oca/models/account_move.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,6 @@ def _get_tax_info(self):
220220
# Use the method at l10n_es_aeat that returns the needed info
221221
return self._get_aeat_tax_info()
222222

223-
@api.model
224-
def _merge_tax_dict(self, vat_list, tax_dict, comp_key, merge_keys):
225-
"""Helper method for merging values in an existing tax dictionary."""
226-
for existing_dict in vat_list:
227-
if existing_dict.get(comp_key, "-99") == tax_dict.get(comp_key, "-99"):
228-
for key in merge_keys:
229-
existing_dict[key] += tax_dict[key]
230-
return True
231-
return False
232-
233223
def _get_sii_in_taxes(self):
234224
"""Get the taxes for purchase invoices.
235225

l10n_es_aeat_sii_oca/models/sii_mixin.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,16 @@ def _get_no_taxable_cause(self):
474474
or "ImporteTAIReglasLocalizacion"
475475
)
476476

477+
@api.model
478+
def _merge_tax_dict(self, vat_list, tax_dict, comp_key, merge_keys):
479+
"""Helper method for merging values in an existing tax dictionary."""
480+
for existing_dict in vat_list:
481+
if existing_dict.get(comp_key, "-99") == tax_dict.get(comp_key, "-99"):
482+
for key in merge_keys:
483+
existing_dict[key] += tax_dict[key]
484+
return True
485+
return False
486+
477487
def _is_sii_type_breakdown_required(self):
478488
"""Calculates if the block 'DesgloseTipoOperacion' is required for
479489
the invoice communication."""
@@ -565,9 +575,15 @@ def _get_sii_out_taxes(self): # noqa: C901
565575
is_s3 = not_ex_type == "S2"
566576
if is_s3:
567577
sub_dict["NoExenta"]["TipoNoExenta"] = "S3"
568-
sub_dict["NoExenta"]["DesgloseIVA"]["DetalleIVA"].append(
569-
self._get_sii_tax_dict(tax_line, tax_lines),
570-
)
578+
sub = sub_dict["NoExenta"]["DesgloseIVA"]["DetalleIVA"]
579+
tax_dict = self._get_sii_tax_dict(tax_line, tax_lines)
580+
if not self._merge_tax_dict(
581+
sub,
582+
tax_dict,
583+
"TipoImpositivo",
584+
["BaseImponible", "CuotaRepercutida"],
585+
):
586+
sub.append(tax_dict)
571587
# No sujetas
572588
if tax in taxes_sfens:
573589
# ImporteTAIReglasLocalizacion or ImportePorArticulos7_14_Otros
@@ -598,7 +614,14 @@ def _get_sii_out_taxes(self): # noqa: C901
598614
{"TipoNoExenta": "S1", "DesgloseIVA": {"DetalleIVA": []}},
599615
)
600616
sub = not_exempt["DesgloseIVA"]["DetalleIVA"]
601-
sub.append(self._get_sii_tax_dict(tax_line, tax_lines))
617+
tax_dict = self._get_sii_tax_dict(tax_line, tax_lines)
618+
if not self._merge_tax_dict(
619+
sub,
620+
tax_dict,
621+
"TipoImpositivo",
622+
["BaseImponible", "CuotaRepercutida"],
623+
):
624+
sub.append(tax_dict)
602625
if tax in taxes_sfesns:
603626
default_no_taxable_cause = self._get_no_taxable_cause()
604627
nsub_dict = service_breakdown.setdefault(
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"IDFactura": {
3+
"IDEmisorFactura": {"NIF": "U2687761C"},
4+
"NumSerieFacturaEmisor": "TEST001",
5+
"FechaExpedicionFacturaEmisor": "01-01-2020"
6+
},
7+
"PeriodoLiquidacion": {"Ejercicio": 2020, "Periodo": "01"},
8+
"FacturaExpedida": {
9+
"TipoFactura": "F1",
10+
"ClaveRegimenEspecialOTrascendencia": "01",
11+
"DescripcionOperacion": "/",
12+
"TipoDesglose": {
13+
"DesgloseFactura": {
14+
"Sujeta": {
15+
"NoExenta": {
16+
"TipoNoExenta": "S1",
17+
"DesgloseIVA": {
18+
"DetalleIVA": [
19+
{
20+
"TipoImpositivo": "21.0",
21+
"BaseImponible": 300.0,
22+
"CuotaRepercutida": 63.0
23+
}
24+
]
25+
}
26+
}
27+
}
28+
}
29+
},
30+
"ImporteTotal": 363.0,
31+
"Contraparte": {"NombreRazon": "Test partner", "NIF": "F35999705"}
32+
}
33+
}

l10n_es_aeat_sii_oca/tests/test_l10n_es_aeat_sii.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def test_partner_sii_enabled(self):
247247

248248
def test_get_invoice_data(self):
249249
mapping = [
250+
("out_invoice", [(100, ["s_iva21b"]), (200, ["s_iva21s"])], {}, False),
250251
("out_invoice", [(100, ["s_iva10b"]), (200, ["s_iva21s"])], {}, False),
251252
("out_invoice", [(100, ["s_iva10b"]), (200, ["s_iva0_ns"])], {}, False),
252253
(

0 commit comments

Comments
 (0)