From 92e488a85935ff59f992edfbe4949effa364670e Mon Sep 17 00:00:00 2001 From: SatCFDI Date: Wed, 14 Feb 2024 22:12:06 -0600 Subject: [PATCH] added export function to DIOT --- satcfdi/diot/__init__.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/satcfdi/diot/__init__.py b/satcfdi/diot/__init__.py index c7c441b..f903b13 100644 --- a/satcfdi/diot/__init__.py +++ b/satcfdi/diot/__init__.py @@ -210,6 +210,34 @@ def render(self, w: DIOTWriter): if self.devoluciones is not None: w(302261, 1, 1, self.devoluciones) + def to_list(self): + return [ + self.tipo_tercero, + self.tipo_operacion, + self.rfc, + self.id_fiscal, + self.nombre_extranjero, + self.pais, + self.nacionalidad, + self.iva16, + "", + self.iva16_na, + "", + "", + self.iva_rfn, + "", + self.iva_rfn_na, + self.iva_import16, + self.iva_import16_na, + "", + "", + self.iva_import_exento, + self.iva0, + self.iva_exento, + self.retenido, + self.devoluciones + ] + class DatosComplementaria: def __init__( @@ -338,7 +366,7 @@ def __init__( datos_identificacion: DatosIdentificacion, periodo: Periodo, complementaria: DatosComplementaria = None, - proveedores: ProveedorTercero | Sequence[ProveedorTercero] = None + proveedores: Sequence[ProveedorTercero] = None ): proveedores = list(iterate(proveedores)) @@ -398,6 +426,11 @@ def _tmp_filename(self): return f"{rfc}{v_dem}{n_formulario}{ver_clte}{ver_form}{period}{mes_inicial}{period}{mes_final}{anio}{mes}{dia}{hora}{suffix}" + def export(self, target): + for p in self.proveedores: + target.write("|".join(str(v or "") for v in p.to_list()).encode('windows-1252')) + target.write(b"|\r\n") + def plain_bytes(self) -> bytes: with BytesIO() as b: self.plain_write(b)