Skip to content

Commit ef58b5a

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 bd4cb9c commit ef58b5a

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
@@ -218,16 +218,6 @@ def _get_tax_info(self):
218218
# Use the method at l10n_es_aeat that returns the needed info
219219
return self._get_aeat_tax_info()
220220

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

l10n_es_aeat_sii_oca/models/sii_mixin.py

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

478+
@api.model
479+
def _merge_tax_dict(self, vat_list, tax_dict, comp_key, merge_keys):
480+
"""Helper method for merging values in an existing tax dictionary."""
481+
for existing_dict in vat_list:
482+
if existing_dict.get(comp_key, "-99") == tax_dict.get(comp_key, "-99"):
483+
for key in merge_keys:
484+
existing_dict[key] += tax_dict[key]
485+
return True
486+
return False
487+
478488
def _is_sii_type_breakdown_required(self, taxes_dict):
479489
"""Calculates if the block 'DesgloseTipoOperacion' is required for
480490
the invoice communication."""
@@ -562,9 +572,15 @@ def _get_sii_out_taxes(self): # noqa: C901
562572
is_s3 = not_ex_type == "S2"
563573
if is_s3:
564574
sub_dict["NoExenta"]["TipoNoExenta"] = "S3"
565-
sub_dict["NoExenta"]["DesgloseIVA"]["DetalleIVA"].append(
566-
self._get_sii_tax_dict(tax_line, tax_lines),
567-
)
575+
sub = sub_dict["NoExenta"]["DesgloseIVA"]["DetalleIVA"]
576+
tax_dict = self._get_sii_tax_dict(tax_line, tax_lines)
577+
if not self._merge_tax_dict(
578+
sub,
579+
tax_dict,
580+
"TipoImpositivo",
581+
["BaseImponible", "CuotaRepercutida"],
582+
):
583+
sub.append(tax_dict)
568584
# No sujetas
569585
if tax in taxes_sfens:
570586
# ImporteTAIReglasLocalizacion or ImportePorArticulos7_14_Otros
@@ -606,7 +622,14 @@ def _get_sii_out_taxes(self): # noqa: C901
606622
{"TipoNoExenta": "S1", "DesgloseIVA": {"DetalleIVA": []}},
607623
)
608624
sub = not_exempt["DesgloseIVA"]["DetalleIVA"]
609-
sub.append(self._get_sii_tax_dict(tax_line, tax_lines))
625+
tax_dict = self._get_sii_tax_dict(tax_line, tax_lines)
626+
if not self._merge_tax_dict(
627+
sub,
628+
tax_dict,
629+
"TipoImpositivo",
630+
["BaseImponible", "CuotaRepercutida"],
631+
):
632+
sub.append(tax_dict)
610633
if tax in taxes_sfesns:
611634
default_no_taxable_cause = self._get_no_taxable_cause()
612635
nsub_dict = service_dict.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)