@@ -109,13 +109,13 @@ def filter_payments_iter(invoices: Mapping[UUID, SatCFDI], rfc_emisor=None, rfc_
109109 yield PaymentsDetails (comprobante = r , comprobante_pagado = r )
110110
111111
112- def filter_retenciones_iter (invoices , ejerc : int ):
112+ def filter_retenciones_iter (invoices , ejerc : int , complemento ):
113113 for a in invoices .values ():
114114 if (a ["Version" ] == "1.0" and a ["Periodo" ]["Ejerc" ] != ejerc ) or \
115115 (a ["Version" ] == "2.0" and a ["Periodo" ]["Ejercicio" ] != str (ejerc )):
116116 continue
117117
118- if "Intereses" in a ["Complemento" ]:
118+ if complemento in a ["Complemento" ]:
119119 yield a
120120
121121
@@ -195,15 +195,47 @@ def retenciones_def():
195195 return {
196196 'RFC de la Institucion' : (18 , False , lambda i : i ["Emisor" ].get ("RfcE" ) or i ["Emisor" ].get ("RFCEmisor" )),
197197 'Nombre' : (36 , False , lambda i : i ["Emisor" ].get ('NomDenRazSocE' )),
198- 'Monto de los intereses nominales' : (12 , True , lambda i : i ["Complemento" ]["Intereses" ]["MontIntNominal" ]),
199- 'Monto de los intereses reales' : (12 , True , lambda i : i ["Complemento" ]["Intereses" ]["MontIntReal" ]),
200- 'Perdida' : (12 , True , lambda i : i ["Complemento" ]["Intereses" ]["Perdida" ]),
198+ 'Monto de los intereses nominales' : (12 , True , lambda i : round ( i ["Complemento" ]["Intereses" ]["MontIntNominal" ]) ),
199+ 'Monto de los intereses reales' : (12 , True , lambda i : round ( i ["Complemento" ]["Intereses" ]["MontIntReal" ]) ),
200+ 'Perdida' : (12 , True , lambda i : round ( i ["Complemento" ]["Intereses" ]["Perdida" ]) ),
201201 'ISR Retenido' : (
202- 12 , True , lambda i : sum (x ["MontoRet" ] for x in i ["Totales" ]['ImpRetenidos' ] if x .get ("Impuesto" ) == TipoImpuesto .ISR or x .get ("ImpuestoRet" ) == '001' ) if 'ImpRetenidos' in i ["Totales" ] else None
202+ 12 , True , lambda i : round ( sum (x ["MontoRet" ] for x in i ["Totales" ]['ImpRetenidos' ] if x .get ("Impuesto" ) == TipoImpuesto .ISR or x .get ("ImpuestoRet" ) == '001' ) if 'ImpRetenidos' in i ["Totales" ] else None )
203203 )
204204 }
205205
206206
207+ def dividendos_def_nac ():
208+ return {
209+ 'RFC de la Institucion' : (18 , False , lambda i : i ["Emisor" ].get ("RfcE" ) or i ["Emisor" ].get ("RFCEmisor" )),
210+ 'Nombre' : (36 , False , lambda i : i ["Emisor" ].get ('NomDenRazSocE' )),
211+
212+ 'TipoSocDistrDiv' : (12 , False , lambda i : i ["Complemento" ]["Dividendos" ]["DividOUtil" ]["TipoSocDistrDiv" ]),
213+ 'CveTipDivOUtil' : (12 , False , lambda i : i ["Complemento" ]["Dividendos" ]["DividOUtil" ]["CveTipDivOUtil" ]),
214+
215+ 'MontISRAcredRetMexico' : (12 , True , lambda i : i ["Complemento" ]["Dividendos" ]["DividOUtil" ]["MontISRAcredRetMexico" ] or 0 ),
216+ # 'MontISRAcredRetExtranjero': (12, True, lambda i: i["Complemento"]["Dividendos"]["DividOUtil"]["MontISRAcredRetExtranjero"] or 0),
217+ # 'MontRetExtDivExt': (12, True, lambda i: i["Complemento"]["Dividendos"]["DividOUtil"].get("MontRetExtDivExt") or 0),
218+ 'MontISRAcredNal' : (12 , True , lambda i : i ["Complemento" ]["Dividendos" ]["DividOUtil" ].get ("MontISRAcredNal" ) or 0 ),
219+ 'MontDivAcumNal' : (12 , True , lambda i : i ["Complemento" ]["Dividendos" ]["DividOUtil" ]["MontDivAcumNal" ] or 0 ),
220+ # 'MontDivAcumExt': (12, True, lambda i: i["Complemento"]["Dividendos"]["DividOUtil"]["MontDivAcumExt"] or 0)
221+ }
222+
223+ def dividendos_def_ext ():
224+ return {
225+ 'RFC de la Institucion' : (18 , False , lambda i : i ["Emisor" ].get ("RfcE" ) or i ["Emisor" ].get ("RFCEmisor" )),
226+ 'Nombre' : (36 , False , lambda i : i ["Emisor" ].get ('NomDenRazSocE' )),
227+
228+ 'TipoSocDistrDiv' : (12 , False , lambda i : i ["Complemento" ]["Dividendos" ]["DividOUtil" ]["TipoSocDistrDiv" ]),
229+ 'CveTipDivOUtil' : (12 , False , lambda i : i ["Complemento" ]["Dividendos" ]["DividOUtil" ]["CveTipDivOUtil" ]),
230+
231+ #'MontISRAcredRetMexico': (12, True, lambda i: i["Complemento"]["Dividendos"]["DividOUtil"]["MontISRAcredRetMexico"] or 0),
232+ 'MontISRAcredRetExtranjero' : (12 , True , lambda i : i ["Complemento" ]["Dividendos" ]["DividOUtil" ]["MontISRAcredRetExtranjero" ] or 0 ),
233+ 'MontRetExtDivExt' : (12 , True , lambda i : i ["Complemento" ]["Dividendos" ]["DividOUtil" ].get ("MontRetExtDivExt" ) or 0 ),
234+ # 'MontISRAcredNal': (12, True, lambda i: i["Complemento"]["Dividendos"]["DividOUtil"].get("MontISRAcredNal") or 0),
235+ # 'MontDivAcumNal': (12, True, lambda i: i["Complemento"]["Dividendos"]["DividOUtil"]["MontDivAcumNal"] or 0),
236+ 'MontDivAcumExt' : (12 , True , lambda i : i ["Complemento" ]["Dividendos" ]["DividOUtil" ]["MontDivAcumExt" ] or 0 )
237+ }
238+
207239def console_print (invoices , columns ):
208240 headers = ['' , * (c for c in columns .keys ())]
209241
@@ -213,11 +245,18 @@ def row(n, i):
213245 * (f (i ) for w , s , f in columns .values ())
214246 ]
215247
248+ all_row = [
249+ row (n , i ) for n , i in enumerate (invoices )
250+ ]
251+ total_row = [
252+ paint ("Total" , COLOR_BACKGROUND_BRIGHT_BLACK if len (all_row ) % 2 == 0 else COLOR_BACKGROUND_BLACK ),
253+ * (sum (f (i ) for i in invoices ) if s else None for w , s , f in columns .values ())
254+ ]
255+ all_row .append (total_row )
256+
216257 print (
217258 tabulate (
218- [
219- row (n , i ) for n , i in enumerate (invoices )
220- ],
259+ all_row ,
221260 floatfmt = ".2f" ,
222261 headers = headers
223262 )
@@ -330,7 +369,7 @@ def payments_groupby_receptor(payments: Sequence[PaymentsDetails]):
330369 return res
331370
332371
333- def payments_retentions_export (file_name , grouped_payments : Sequence ):
372+ def payments_retentions_export (file_name , grouped_payments : Sequence , decimals = 2 ):
334373 with open (file_name , "w" , encoding = "utf-8" ) as f :
335374 def write (line ):
336375 f .write (line )
@@ -340,6 +379,7 @@ def write(line):
340379 for r in grouped_payments :
341380 write ("{receptor}|{ingreso_recibido}|{isr_retenido}" .format (
342381 receptor = r ["Receptor" ],
343- ingreso_recibido = round (r ["SubTotal" ] - r ["Descuento" ], 2 ),
344- isr_retenido = round (r ["ISR Ret" ], 2 )
382+ ingreso_recibido = round (r ["SubTotal" ] - r ["Descuento" ], decimals ),
383+ isr_retenido = round (r ["ISR Ret" ], decimals )
345384 ))
385+
0 commit comments