Skip to content

Commit

Permalink
added support for 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
satcfdi committed Mar 15, 2024
1 parent 86ebe24 commit 5685032
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion satcfdi/accounting/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def format_fecha_pago(payment: PaymentsDetails):
if payment.pago:
return payment.pago["FechaPago"]

def_pagado = payment.comprobante.saldo_pendiente == 0
def_pagado = payment.comprobante.saldo_pendiente() == 0
if def_pagado:
return payment.comprobante["Fecha"]
else:
Expand Down
13 changes: 7 additions & 6 deletions satcfdi/accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ def uuid(self):
def name(self):
return self.get("Serie", "") + self.get("Folio", "")

@property
def saldo_pendiente(self) -> Decimal | None:
def saldo_pendiente(self, date=None) -> Decimal | None:
if self["TipoDeComprobante"] == TipoDeComprobante.INGRESO:
# Nota de crédito de los documentos relacionados
credit_notes = sum(
c.comprobante["Total"]
for c in self.relations
if c.cfdi_relacionados["TipoRelacion"] == TipoRelacion.NOTA_DE_CREDITO_DE_LOS_DOCUMENTOS_RELACIONADOS
and c.comprobante['TipoDeComprobante'] == TipoDeComprobante.EGRESO
and c.comprobante.estatus == EstadoComprobante.VIGENTE
and c.comprobante.estatus() == EstadoComprobante.VIGENTE
and (not date or c.comprobante['Fecha'] <= date)
)
insoluto = min(
(c.docto_relacionado['ImpSaldoInsoluto']
for c in self.payments
if c.comprobante.estatus == EstadoComprobante.VIGENTE),
if c.comprobante.estatus() == EstadoComprobante.VIGENTE
and (not date or c.pago['FechaPago'] <= date)
),
default=None
)
if insoluto is not None:
Expand All @@ -62,12 +64,11 @@ def saldo_pendiente(self) -> Decimal | None:

@property
def ultima_num_parcialidad(self) -> int:
return max((c.docto_relacionado['NumParcialidad'] for c in self.payments), default=0)
return max((c.docto_relacionado['NumParcialidad'] for c in self.payments if c.comprobante.estatus() == EstadoComprobante.VIGENTE), default=0)

def consulta_estado(self) -> dict:
raise NotImplementedError()

@property
def estatus(self) -> EstadoComprobante:
raise NotImplementedError()

Expand Down
6 changes: 3 additions & 3 deletions satcfdi/accounting/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def filter_invoices_iter(
for r in invoices:
if _compare(r["Emisor"]["Rfc"], rfc_emisor) \
and _compare(r["Receptor"]["Rfc"], rfc_receptor) \
and _compare(r.estatus, estatus) \
and _compare(r.estatus(), estatus) \
and _compare(r["Fecha"], fecha) \
and _compare(r.get("MetodoPago"), payment_method) \
and _compare(r["TipoDeComprobante"], invoice_type) \
and _compare(r.saldo_pendiente, pending_balance):
and _compare(r.saldo_pendiente(), pending_balance):
yield r


Expand Down Expand Up @@ -122,7 +122,7 @@ def invoice_def():
'IVA Ret': (12, True, lambda i: i.get("Impuestos", {}).get("Retenciones", {}).get(Impuesto.IVA, {}).get("Importe")),
'ISR Ret': (12, True, lambda i: i.get("Impuestos", {}).get("Retenciones", {}).get(Impuesto.ISR, {}).get("Importe")),
'Total': (12, True, lambda i: i["Total"]),
'Pendiente': (12, True, lambda i: i.saldo_pendiente or None),
'Pendiente': (12, True, lambda i: i.saldo_pendiente() or None),
'Pagos': (35, False, format_pagos),
'Relaciones': (35, False, format_relaciones),
'Estado CFDI': (35, False, format_estado_cfdi),
Expand Down
21 changes: 17 additions & 4 deletions tests/test_accounting.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import glob
import os
from unittest import mock

from uuid import UUID
from datetime import datetime
import xlsxwriter

from satcfdi.accounting._ansi_colors import *
from satcfdi.accounting.formatters import SatCFDI
from satcfdi.create.catalogos import EstadoComprobante
from satcfdi.accounting.process import filter_invoices_iter, invoices_export, invoices_print, payments_print, \
complement_invoices_data, payments_export, num2col, filter_payments_iter, payments_retentions_export, filter_retenciones_iter, retenciones_print, payments_groupby_receptor
from satcfdi.models import DatePeriod
Expand All @@ -24,9 +26,8 @@ def test_ansi():


class myCFDI(SatCFDI):
@SatCFDI.estatus.getter
def estatus(self) -> str:
return '1'
def estatus(self) -> EstadoComprobante:
return EstadoComprobante.VIGENTE

def consulta_estado(self):
return {}
Expand All @@ -48,6 +49,18 @@ def test_cfdi():
d = c.ultima_num_parcialidad
assert d >= 0

cfdi_pagado = all_invoices[UUID("6d7434a6-e3f2-47ad-9e4c-08849946afa0")]

assert cfdi_pagado.ultima_num_parcialidad == 1
assert cfdi_pagado.saldo_pendiente() == 0
assert cfdi_pagado.saldo_pendiente(datetime(2020, 1, 2)) == cfdi_pagado['Total']
assert cfdi_pagado.saldo_pendiente(datetime(2020, 1, 3)) == 0

cfdi_pagado.payments[0].comprobante.estatus = lambda: EstadoComprobante.CANCELADO

assert cfdi_pagado.ultima_num_parcialidad == 0
assert cfdi_pagado.saldo_pendiente() == cfdi_pagado['Total']

with mock.patch('builtins.print') as p:
ingresos_pendientes = list(filter_invoices_iter(invoices=all_invoices.values(), fecha=dp, rfc_emisor=rfc, invoice_type="I", pending_balance=lambda x: x > 0))
invoices_print(ingresos_pendientes)
Expand Down

0 comments on commit 5685032

Please sign in to comment.