From 4020237f680799f5fa007b5ce0f76fc71552e8d5 Mon Sep 17 00:00:00 2001 From: el Mau Date: Fri, 17 Feb 2023 13:43:43 -0600 Subject: [PATCH] Fix in tax object 04 --- source/app/models/main.py | 84 ++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/source/app/models/main.py b/source/app/models/main.py index 2d8e5df..caae2c1 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -5777,6 +5777,9 @@ class Facturas(BaseModel): rows = FacturasDetalle.select().where(FacturasDetalle.factura==invoice) for row in rows: + + object_tax = row.producto.objeto_impuesto + if is_global: key_sat = row.clave_sat key = row.clave @@ -5830,49 +5833,50 @@ class Facturas(BaseModel): else: product_taxes = row.producto.impuestos - for impuesto in product_taxes: - base = float(row.importe - row.descuento) - if is_global: - base = float(impuesto.base) - impuesto = impuesto.impuesto + if object_tax == '02': + for impuesto in product_taxes: + base = float(row.importe - row.descuento) + if is_global: + base = float(impuesto.base) + impuesto = impuesto.impuesto - if impuesto.tipo == 'E': + if impuesto.tipo == 'E': + tax = { + 'Base': FORMAT.format(base), + 'Impuesto': '002', + 'TipoFactor': 'Exento', + } + traslados.append(tax) + base_iva_exento += base + continue + + if impuesto.key == '000': + continue + + tasa = float(impuesto.tasa) + + if tax_decimals: + import_tax = round(tasa * base, DECIMALES_TAX) + tmp += import_tax + xml_importe = FORMAT_TAX.format(import_tax) + else: + import_tax = round(tasa * base, DECIMALES) + xml_importe = FORMAT.format(import_tax) + + tipo_factor = 'Tasa' + if impuesto.factor != 'T': + tipo_factor = 'Cuota' tax = { - 'Base': FORMAT.format(base), - 'Impuesto': '002', - 'TipoFactor': 'Exento', + "Base": FORMAT.format(base), + "Impuesto": impuesto.key, + "TipoFactor": tipo_factor, + "TasaOCuota": str(impuesto.tasa), + "Importe": xml_importe, } - traslados.append(tax) - base_iva_exento += base - continue - - if impuesto.key == '000': - continue - - tasa = float(impuesto.tasa) - - if tax_decimals: - import_tax = round(tasa * base, DECIMALES_TAX) - tmp += import_tax - xml_importe = FORMAT_TAX.format(import_tax) - else: - import_tax = round(tasa * base, DECIMALES) - xml_importe = FORMAT.format(import_tax) - - tipo_factor = 'Tasa' - if impuesto.factor != 'T': - tipo_factor = 'Cuota' - tax = { - "Base": FORMAT.format(base), - "Impuesto": impuesto.key, - "TipoFactor": tipo_factor, - "TasaOCuota": str(impuesto.tasa), - "Importe": xml_importe, - } - if impuesto.tipo == 'T': - traslados.append(tax) - else: - retenciones.append(tax) + if impuesto.tipo == 'T': + traslados.append(tax) + else: + retenciones.append(tax) if traslados: taxes['traslados'] = traslados