Skip to content

Commit f2e4526

Browse files
committed
[FIX] l10n_es_aeat_sii_oca: Don't merge tax dicts with different BienInversion values
When a supplier invoice has multiple tax lines with the same tax rate (TipoImpositivo) but some are investment goods (BienInversion=S) and others are not, they should NOT be merged into a single SII entry. This fixes the bug where all tax lines were incorrectly marked as investment goods when the first tax line had BienInversion=S. MT-14523 @moduon
1 parent 711746e commit f2e4526

4 files changed

Lines changed: 62 additions & 6 deletions

File tree

l10n_es_aeat_sii_oca/models/account_move.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def _get_sii_in_taxes(self):
275275
if not self._merge_tax_dict(
276276
base_dict["DetalleIVA"],
277277
tax_dict,
278-
"TipoImpositivo",
278+
["TipoImpositivo", "BienInversion"],
279279
["BaseImponible", "CuotaSoportada"],
280280
):
281281
base_dict["DetalleIVA"].append(tax_dict)

l10n_es_aeat_sii_oca/models/sii_mixin.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,21 @@ def _get_no_taxable_cause(self):
469469
)
470470

471471
@api.model
472-
def _merge_tax_dict(self, vat_list, tax_dict, comp_key, merge_keys):
473-
"""Helper method for merging values in an existing tax dictionary."""
472+
def _merge_tax_dict(self, vat_list, tax_dict, comp_keys, merge_keys):
473+
"""Helper method for merging values in an existing tax dictionary.
474+
475+
:param vat_list: List of tax dictionaries to check for merge.
476+
:param tax_dict: Tax dictionary to merge.
477+
:param comp_keys: List of keys to compare for matching.
478+
:param merge_keys: List of keys whose values should be summed.
479+
"""
474480
for existing_dict in vat_list:
475-
if existing_dict.get(comp_key, "-99") == tax_dict.get(comp_key, "-99"):
481+
match = True
482+
for key in comp_keys:
483+
if existing_dict.get(key, "-99") != tax_dict.get(key, "-99"):
484+
match = False
485+
break
486+
if match:
476487
for key in merge_keys:
477488
existing_dict[key] += tax_dict[key]
478489
return True
@@ -571,7 +582,7 @@ def _get_sii_out_taxes(self): # noqa: C901
571582
if not self._merge_tax_dict(
572583
sub,
573584
tax_dict,
574-
"TipoImpositivo",
585+
["TipoImpositivo"],
575586
["BaseImponible", "CuotaRepercutida"],
576587
):
577588
sub.append(tax_dict)
@@ -615,7 +626,7 @@ def _get_sii_out_taxes(self): # noqa: C901
615626
if not self._merge_tax_dict(
616627
sub,
617628
tax_dict,
618-
"TipoImpositivo",
629+
["TipoImpositivo"],
619630
["BaseImponible", "CuotaRepercutida"],
620631
):
621632
sub.append(tax_dict)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"IDFactura": {
3+
"FechaExpedicionFacturaEmisor": "01-01-2020",
4+
"NumSerieFacturaEmisor": "sup0008",
5+
"IDEmisorFactura": {"NIF": "F35999705"}
6+
},
7+
"FacturaRecibida": {
8+
"TipoFactura": "F1",
9+
"Contraparte": {"NombreRazon": "Test partner", "NIF": "F35999705"},
10+
"DescripcionOperacion": "/",
11+
"ClaveRegimenEspecialOTrascendencia": "01",
12+
"ImporteTotal": 201.66,
13+
"FechaRegContable": "01-10-2020",
14+
"DesgloseFactura": {
15+
"DesgloseIVA": {
16+
"DetalleIVA": [
17+
{
18+
"TipoImpositivo": "21.0",
19+
"BaseImponible": 83.33,
20+
"CuotaSoportada": 17.5
21+
},
22+
{
23+
"TipoImpositivo": "21.0",
24+
"BaseImponible": 83.33,
25+
"CuotaSoportada": 17.5,
26+
"BienInversion": "S"
27+
}
28+
]
29+
}
30+
},
31+
"CuotaDeducible": 35.0
32+
},
33+
"PeriodoLiquidacion": {"Periodo": "01", "Ejercicio": 2020}
34+
}

l10n_es_aeat_sii_oca/tests/test_l10n_es_aeat_sii.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,17 @@ def test_get_invoice_data(self):
348348
},
349349
True,
350350
),
351+
# In invoice with same rate but different investment goods
352+
(
353+
"in_invoice",
354+
[(100, ["p_iva21_bc"]), (100, ["p_iva21_bi"])],
355+
{
356+
"ref": "sup0008",
357+
"sii_account_registration_date": "2020-10-01",
358+
"currency_id": self.usd.id,
359+
},
360+
False,
361+
),
351362
]
352363
for inv_type, lines, extra_vals, is_dua in mapping:
353364
invoice = self._create_and_test_invoice_sii_dict(

0 commit comments

Comments
 (0)