From 232ffa21143f878701b526a9dab8f4819a3701ad Mon Sep 17 00:00:00 2001 From: SatCFDI Date: Wed, 10 Apr 2024 16:30:28 -0600 Subject: [PATCH] updated test requirements --- satcfdi/accounting/contabilidad.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/satcfdi/accounting/contabilidad.py b/satcfdi/accounting/contabilidad.py index aa1bf29..8fea8c7 100644 --- a/satcfdi/accounting/contabilidad.py +++ b/satcfdi/accounting/contabilidad.py @@ -216,24 +216,23 @@ def validate_cuentas(cuentas): cuentas[v['SubCtaDe']]['_Lowest'] = False +def sign(cta): + if cta['Natur'] == 'D': + return 1 + return -1 + + def validate_saldos(cuentas): totales = {} for k, v in cuentas.items(): sub_cta = v.get('SubCtaDe') or '' totales.setdefault(sub_cta, 0) - if v['Natur'] == 'D': - totales[sub_cta] += v['SaldoFin'] - else: - totales[sub_cta] -= v['SaldoFin'] + totales[sub_cta] += v['SaldoFin'] * sign(v) for k, v in totales.items(): if k: - if cuentas[k]['Natur'] == 'D': - if v != cuentas[k]['SaldoFin']: - raise ValueError(f"Error in {k}: {v} != {cuentas[k]['SaldoFin']}") - else: - if v != -cuentas[k]['SaldoFin']: - raise ValueError(f"Error in {k}: {v} != {cuentas[k]['SaldoFin']}") + if v != cuentas[k]['SaldoFin'] * sign(cuentas[k]): + raise ValueError(f"Error in {k}: {v} != {cuentas[k]['SaldoFin']}") else: assert v == 0 @@ -276,7 +275,5 @@ def calcular_saldos(cuentas, polizas): # Fill SaldoFin for c in cuentas.values(): - if c["Natur"] == "D": - c["SaldoFin"] += c["SaldoIni"] + c["Debe"] - c["Haber"] - else: - c["SaldoFin"] += c["SaldoIni"] + c["Haber"] - c["Debe"] + s = sign(c) + c["SaldoFin"] += c["SaldoIni"] + c["Debe"] * s - c["Haber"] * s