Skip to content

Commit

Permalink
[11.0][FIX] l10n_es_ticketbai_api: Correción agrupación impuestos
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanHRN committed Jan 21, 2025
1 parent 7273c8e commit 05f58fc
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions l10n_es_ticketbai_api/models/ticketbai_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,42 @@ def build_detalle_exenta(self):
]))
return res

def group_by_tax_amount(self, tax_detail):
taxes_dict = {}
iva = []
group = False

if tax_detail.get("DesgloseIVA", False) and tax_detail.get("DesgloseIVA").get("DetalleIVA", False):
# Comprobamos si existen varias líneas con el mismo tipo impositivo
for iva_detail in tax_detail["DesgloseIVA"]["DetalleIVA"]:
if iva_detail["TipoImpositivo"] not in iva:
iva.append(iva_detail["TipoImpositivo"])
else:
group = True
break

# Comprobamos si hay que agrupar
if group:
for iva_detail in tax_detail["DesgloseIVA"]["DetalleIVA"]:
datakey = (iva_detail["TipoImpositivo"], iva_detail.get("OperacionEnRecargoDeEquivalenciaORegimenSimplificado", 'N'))
if datakey not in taxes_dict:
# Introducimos los valores del primer elemento
values = {key: item for key, item in iva_detail.items()}
taxes_dict[datakey] = values
else:
taxes_dict[datakey]["BaseImponible"] = str(float(taxes_dict[datakey]["BaseImponible"]) + float(iva_detail["BaseImponible"]))
taxes_dict[datakey]["CuotaImpuesto"] = str(float(taxes_dict[datakey]["CuotaImpuesto"]) + float(iva_detail["CuotaImpuesto"]))

# Una vez agrupados los impuestos reconstruimos el diccionario
new_iva_detail = []
for data in taxes_dict.values():
new_iva_detail.append(OrderedDict(data))

# Asignamos los nuevos valores agrupados
tax_detail["DesgloseIVA"]["DetalleIVA"] = new_iva_detail

return tax_detail

def build_detalle_no_exenta(self):
""" V 1.2
1. Inversión del Sujeto Pasivo (ISP) taxes (tax is paid by the customer).
Expand Down Expand Up @@ -888,8 +924,10 @@ def build_detalle_no_exenta(self):
tax_details
)
if not_exempted_taxes_isp:
not_exempted_taxes_isp = self.group_by_tax_amount(not_exempted_taxes_isp)
res.append(not_exempted_taxes_isp)
if not_exempted_taxes_not_isp:
not_exempted_taxes_not_isp = self.group_by_tax_amount(not_exempted_taxes_not_isp)
res.append(not_exempted_taxes_not_isp)
return res

Expand Down

0 comments on commit 05f58fc

Please sign in to comment.