From 0815ecc62af405d3bbe393395eefb0b5adae5cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20D=C3=ADaz=20Miralles?= Date: Fri, 17 Dec 2021 12:09:57 +0100 Subject: [PATCH] Fix errors when query issued and received invoices. This commit refs #21251 --- aeat.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/aeat.py b/aeat.py index 177430c..912f7d9 100644 --- a/aeat.py +++ b/aeat.py @@ -671,24 +671,25 @@ class SIIReport(Workflow, ModelSQL, ModelView): else: sujeta = tipo_desglose.DesgloseTipoOperacion.Entrega.Sujeta - if sujeta.NoExenta: - for detail in sujeta.NoExenta.DesgloseIVA.DetalleIVA: - taxes_to_create.append({ - 'base': _decimal(detail.BaseImponible), - 'rate': _decimal(detail.TipoImpositivo), - 'amount': _decimal(detail.CuotaRepercutida), - 'surcharge_rate': _decimal( - detail.TipoRecargoEquivalencia), - 'surcharge_amount': _decimal( - detail.CuotaRecargoEquivalencia), - }) - taxes = SIIReportLineTax.create(taxes_to_create) - elif sujeta.Exenta: - exemption = sujeta.Exenta.DetalleExenta[0].CausaExencion - for exempt in EXCEMPTION_CAUSE: - if exempt[0] == exemption: - exemption = exempt[1] - break + if sujeta: + if sujeta.NoExenta: + for detail in sujeta.NoExenta.DesgloseIVA.DetalleIVA: + taxes_to_create.append({ + 'base': _decimal(detail.BaseImponible), + 'rate': _decimal(detail.TipoImpositivo), + 'amount': _decimal(detail.CuotaRepercutida), + 'surcharge_rate': _decimal( + detail.TipoRecargoEquivalencia), + 'surcharge_amount': _decimal( + detail.CuotaRecargoEquivalencia), + }) + taxes = SIIReportLineTax.create(taxes_to_create) + elif sujeta.Exenta: + exemption = sujeta.Exenta.DetalleExenta[0].CausaExencion + for exempt in EXCEMPTION_CAUSE: + if exempt[0] == exemption: + exemption = exempt[1] + break sii_report_line = { 'report': self.id, @@ -843,7 +844,7 @@ class SIIReport(Workflow, ModelSQL, ModelView): _logger.debug(res) registers = res.RegistroRespuestaConsultaLRFacturasRecibidas pagination = res.IndicadorPaginacion - last_invoice = registers[-1].IDFactura + last_invoice = registers and registers[-1].IDFactura or None # FIXME: the reference is not forced to be unique lines_to_create = []