From 476fed790c025c7164301a7f30bef71b0e4cf894 Mon Sep 17 00:00:00 2001 From: SatCFDI Date: Tue, 9 Apr 2024 21:19:42 -0600 Subject: [PATCH] updated test requirements --- satcfdi/accounting/contabilidad.py | 51 +++++++++++++++--- satcfdi/accounting/contabilidad_print.py | 8 +-- tests/test_contabilidad.py | 44 ++++++++++++++- .../ref/simple/CACX7605101P8202402BN.xlsx | Bin 5595 -> 5864 bytes .../ref/simple/CACX7605101P8202402BN.xml | 6 ++- .../ref/simple/CACX7605101P8202402PL.xml | 11 +++- .../ref/simple/CACX7605101P8202402XC.xml | 9 +++- .../ref/simple/CACX7605101P8202402XF.xml | 6 ++- 8 files changed, 118 insertions(+), 17 deletions(-) diff --git a/satcfdi/accounting/contabilidad.py b/satcfdi/accounting/contabilidad.py index 8e31b29..10e941c 100644 --- a/satcfdi/accounting/contabilidad.py +++ b/satcfdi/accounting/contabilidad.py @@ -1,6 +1,8 @@ import os from typing import Sequence +from satcfdi.utils import iterate + from satcfdi.create.contabilidad.AuxiliarCtas13 import AuxiliarCtas, Cuenta, DetalleAux from satcfdi.create.contabilidad.BCE13 import Balanza from satcfdi.create.contabilidad.PLZ13 import Polizas, CompNal, Poliza @@ -97,6 +99,8 @@ def generar_contabilidad( folder=None, fiel=None, generate_pdf=False): + + validate_polizas(polizas) calcular_saldos(cuentas, polizas) plz = Polizas( @@ -125,7 +129,7 @@ def generar_contabilidad( ) for k, v in cuentas.items() ] ) - output_file(cat, folder, fiel) + cato = output_file(cat, folder, fiel) ban = Balanza( rfc=rfc_emisor, @@ -138,7 +142,7 @@ def generar_contabilidad( **v, } for k, v in cuentas.items() if v["SaldoIni"] or v["Debe"] or v["Haber"] or v["SaldoFin"]], ) - output_file(ban, folder, fiel) + bano = output_file(ban, folder, fiel) aux_detalles = group_aux_cuentas(polizas) aux = AuxiliarCtas( @@ -172,8 +176,8 @@ def generar_contabilidad( output_file(auxf, folder, fiel, generate_pdf=generate_pdf) imprimir_contablidad( - catalogo_cuentas=cat, - balanza_comprobacion=ban, + catalogo_cuentas=cato, + balanza_comprobacion=bano, archivo_excel=os.path.join(folder, filename(ban)[:-4] + ".xlsx") ) @@ -189,7 +193,7 @@ def group_aux_cuentas(polizas): DetalleAux( fecha=p["Fecha"], num_un_iden_pol=p["NumUnIdenPol"], - concepto=t["Concepto"], + concepto=p["Concepto"] + " " + t["Concepto"], debe=t["Debe"], haber=t["Haber"], ) @@ -199,10 +203,30 @@ def group_aux_cuentas(polizas): def group_aux_folios(polizas): for p in polizas: + compr_nal = [] + compr_nal_otr = [] + compr_ext = [] + + for t in p["Transaccion"]: + if c := t.get('CompNal'): + for c in iterate(c): + if c not in compr_nal: + compr_nal.append(c) + if c := t.get('CompNalOtr'): + for c in iterate(c): + if c not in compr_nal_otr: + compr_nal_otr.append(c) + if c := t.get('CompExt'): + for c in iterate(c): + if c not in compr_ext: + compr_ext.append(c) + yield DetAuxFol( num_un_iden_pol=p["NumUnIdenPol"], fecha=p["Fecha"], - compr_nal=p.comp_nal, + compr_nal=compr_nal, + compr_nal_otr=compr_nal_otr, + compr_ext=compr_ext, ) @@ -225,6 +249,17 @@ def validate_saldos(cuentas): assert total == 0 for k, v in totales.items(): if cuentas[k]['Natur'] == 'D': - assert v == cuentas[k]['SaldoFin'] + if v != cuentas[k]['SaldoFin']: + raise ValueError(f"Error in {k}: {v} != {cuentas[k]['SaldoFin']}") else: - assert v == -cuentas[k]['SaldoFin'] + if v != -cuentas[k]['SaldoFin']: + raise ValueError(f"Error in {k}: {v} != {cuentas[k]['SaldoFin']}") + + +def validate_polizas(polizas): + num_un = set() + for p in polizas: + u = p['NumUnIdenPol'] + if u in num_un: + raise ValueError(f"Repeated NumUnIdenPol: {u}") + num_un.add(u) diff --git a/satcfdi/accounting/contabilidad_print.py b/satcfdi/accounting/contabilidad_print.py index 1013d37..5d75a1a 100644 --- a/satcfdi/accounting/contabilidad_print.py +++ b/satcfdi/accounting/contabilidad_print.py @@ -22,10 +22,10 @@ def imprimir_contablidad( balanza_comprobacion, archivo_excel ): - # ct = CFDI.from_file(catalogo_cuentas) - # bc = CFDI.from_file(balanza_comprobacion) - ct = catalogo_cuentas - bc = balanza_comprobacion + ct = CFDI.from_file(catalogo_cuentas) + bc = CFDI.from_file(balanza_comprobacion) + # ct = catalogo_cuentas + # bc = balanza_comprobacion ctas = { c['NumCta']: { diff --git a/tests/test_contabilidad.py b/tests/test_contabilidad.py index f9b14e2..c8fac91 100644 --- a/tests/test_contabilidad.py +++ b/tests/test_contabilidad.py @@ -1,7 +1,11 @@ +import datetime import logging import os +from uuid import UUID + import pytest import yaml +from satcfdi.create.contabilidad.PLZ13 import Poliza, Transaccion, CompNal from satcfdi.models import DatePeriod from satcfdi import render @@ -71,12 +75,50 @@ def test_generate_contabilidad_simple(): with open(os.path.join(current_dir, 'contabilidad_electronica', 'cuentas.yaml'), 'r', encoding='utf-8') as f: cuentas = yaml.load(f, Loader=yaml.SafeLoader) + polizas = [ + Poliza( + num_un_iden_pol="1", + fecha=datetime.date(2024, 2, 1), + concepto="Compra de equipo de computo", + transaccion=[ + Transaccion( + num_cta="1020.01", + des_cta="Bancos", + concepto="Nal", + debe=10000, + haber=0, + comp_nal=[ + CompNal( + uuid_cfdi='a4f4fea5-e798-4ab3-a2e5-75f741f4ecca', + rfc="CACX7605101P8", + monto_total=10000 + ) + ] + ), + Transaccion( + num_cta="1020.02", + des_cta="Bancos", + concepto="Ext", + debe=0, + haber=10000, + comp_nal=[ + CompNal( + uuid_cfdi='a4f4fea5-e798-4ab3-a2e5-75f741f4ecca', + rfc="CACX7605101P8", + monto_total=10000 + ) + ] + ) + ] + ) + ] generar_contabilidad( dp=DatePeriod(2024, 2), rfc_emisor="CACX7605101P8", cuentas=cuentas, - polizas=[], + polizas=polizas, folder=os.path.join(current_dir, 'test_contabilidad_electronica/out/simple'), + tipo_solicitud='AF' ) assert compare_directories( diff --git a/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402BN.xlsx b/tests/test_contabilidad_electronica/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000000000002CfiRQ86(=V`WN$ - + + + + + diff --git a/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402PL.xml b/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402PL.xml index 503cca6..3905e5d 100644 --- a/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402PL.xml +++ b/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402PL.xml @@ -1,2 +1,11 @@ - + + + + + + + + + + diff --git a/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402XC.xml b/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402XC.xml index 62484a2..af93dee 100644 --- a/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402XC.xml +++ b/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402XC.xml @@ -1,2 +1,9 @@ - + + + + + + + + diff --git a/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402XF.xml b/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402XF.xml index 0c674fb..ccdc7fa 100644 --- a/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402XF.xml +++ b/tests/test_contabilidad_electronica/ref/simple/CACX7605101P8202402XF.xml @@ -1,2 +1,6 @@ - + + + + +