Abraham03 commited on
Commit
efb323d
·
verified ·
1 Parent(s): b4490c0

Upload 2 files

Browse files
Files changed (1) hide show
  1. fill_template.py +31 -15
fill_template.py CHANGED
@@ -272,30 +272,39 @@ def extraer_nombre(concepto, tipo=''):
272
  """
273
  raw = quitar_acentos(str(concepto or '').upper())
274
 
275
- # Numero de cuenta del tercero (BBVA 'CUENTA DE TERCERO <cuenta> ...'):
276
- # identificador de la contraparte para agrupar cuando NO hay nombre legible.
277
- m_acc = re.search(r'\bTERCERO\s+(\d{6,})', raw)
278
- cuenta_tercero = m_acc.group(1) if m_acc else None
279
-
280
- # 1) contraparte explicita (Santander/Banamex)
281
  m = re.search(r'\b(?:DEL CLIENTE|AL CLIENTE|A FAVOR DE)\s+(.*)$', raw)
282
  if m:
283
  cand = _primer_nombre(m.group(1))
284
  if cand:
285
  return cand
286
 
287
- # 2) BBVA 'CUENTA DE TERCERO <cuenta> <texto>': si el texto trae un NOMBRE
288
- # (2+ palabras, p.ej. 'maria luisa', 'lucy perfumes') se usa; si solo es un
289
- # concepto ('pago de mercancia', 'compra'), se agrupa por el NUMERO DE
290
- # CUENTA del tercero -> los pagos del mismo tercero quedan juntos.
291
- if cuenta_tercero:
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  m2 = re.search(r'\bTERCERO\s+\d{6,}\s+(.*?)(?:\s+REF\b|$)', raw)
293
  cand = _primer_nombre(m2.group(1)) if m2 else ''
294
  if cand and len(cand.split()) >= 2:
295
  return cand
296
- return 'CUENTA ' + cuenta_tercero
297
 
298
- # 3) BBVA 'BNET <ref> <texto libre>' (lo que escribio quien ordena/recibe)
299
  m = re.search(r'\bBNET\s+\d+\s+(.*)$', raw)
300
  if m:
301
  cand = _primer_nombre(m.group(1))
@@ -639,10 +648,17 @@ def fill(template_path, output_path, data):
639
  from collections import Counter as _Counter
640
  _fu = _Counter(t[5] for t in saldos.values() if len(t) > 5 and t[5])
641
  _fu_txt = (' | Fuente: ' + ', '.join('%s (%d)' % (k, v) for k, v in sorted(_fu.items()))) if _fu else ''
 
 
 
 
 
 
 
642
  if bancos:
643
  ec = set_row_cells(ec, rv + 1, {
644
  'C': build_cell('C%d' % (rv + 1), s=get_style(ec, 'C%d' % (rv + 1)),
645
- text=', '.join(bancos) + _fu_txt)})
646
  if hay_rep:
647
  ec = set_row_cells(ec, rv + 3, {
648
  'D': build_cell('D%d' % (rv + 3), s=get_style(ec, 'D%d' % (rv + 3)), num=round(dep_rep_tot, 2))})
@@ -737,4 +753,4 @@ def main():
737
 
738
 
739
  if __name__ == '__main__':
740
- main()
 
272
  """
273
  raw = quitar_acentos(str(concepto or '').upper())
274
 
275
+ # 1) contraparte explicita por NOMBRE (Santander/Banorte SPEI: 'DEL CLIENTE X',
276
+ # 'AL CLIENTE X', 'A FAVOR DE X').
 
 
 
 
277
  m = re.search(r'\b(?:DEL CLIENTE|AL CLIENTE|A FAVOR DE)\s+(.*)$', raw)
278
  if m:
279
  cand = _primer_nombre(m.group(1))
280
  if cand:
281
  return cand
282
 
283
+ # 2) Banorte orden de pago SPEI: 'BENEF:<nombre> (DATO NO VERIF...)'.
284
+ m = re.search(r'\bBENEF:?\s*(.+?)(?:\(DATO|CVE\s+RAST|\bRFC\b|$)', raw)
285
+ if m:
286
+ cand = _primer_nombre(m.group(1))
287
+ if cand:
288
+ return cand
289
+
290
+ # 3) Banorte traspaso a/desde tercero: el banco identifica al tercero por su
291
+ # NUMERO DE CUENTA ('A LA CUENTA: <cuenta>' / 'DE LA CUENTA: <cuenta>'); se
292
+ # agrupa por esa cuenta (NO por el folio generico 'TERCEROS 0000000001').
293
+ m = re.search(r'\b(?:A LA CUENTA|DE LA CUENTA)\s*:?\s*(\d{6,})', raw)
294
+ if m:
295
+ return 'CUENTA ' + m.group(1)
296
+
297
+ # 4) BBVA 'CUENTA DE TERCERO <cuenta> <texto>': nombre si lo trae (2+ palabras),
298
+ # si solo es un concepto ('pago de mercancia') se agrupa por el num. de cuenta.
299
+ m_acc = re.search(r'\bTERCERO\s+(\d{6,})', raw)
300
+ if m_acc:
301
  m2 = re.search(r'\bTERCERO\s+\d{6,}\s+(.*?)(?:\s+REF\b|$)', raw)
302
  cand = _primer_nombre(m2.group(1)) if m2 else ''
303
  if cand and len(cand.split()) >= 2:
304
  return cand
305
+ return 'CUENTA ' + m_acc.group(1)
306
 
307
+ # 5) BBVA 'BNET <ref> <texto libre>' (lo que escribio quien ordena/recibe)
308
  m = re.search(r'\bBNET\s+\d+\s+(.*)$', raw)
309
  if m:
310
  cand = _primer_nombre(m.group(1))
 
648
  from collections import Counter as _Counter
649
  _fu = _Counter(t[5] for t in saldos.values() if len(t) > 5 and t[5])
650
  _fu_txt = (' | Fuente: ' + ', '.join('%s (%d)' % (k, v) for k, v in sorted(_fu.items()))) if _fu else ''
651
+ # Comisiones/Intereses marcados Tipo='COMISION' (Banorte: van APARTE de EGRESOS;
652
+ # la plantilla ya los excluye de EGRESOS y los resta en DESCUADRE). Se anota su
653
+ # total y conteo en la linea de banco como referencia (en una celda que existe).
654
+ comi_tot = round(sum(t['retiro'] for t in txs if t['tipo'] == 'COMISION'), 2)
655
+ comi_n = sum(1 for t in txs if t['tipo'] == 'COMISION')
656
+ _comi_txt = (' | Comisiones/Intereses (aparte de egresos): $%s (%d mov)'
657
+ % ('{:,.2f}'.format(comi_tot), comi_n)) if comi_tot > 0 else ''
658
  if bancos:
659
  ec = set_row_cells(ec, rv + 1, {
660
  'C': build_cell('C%d' % (rv + 1), s=get_style(ec, 'C%d' % (rv + 1)),
661
+ text=', '.join(bancos) + _fu_txt + _comi_txt)})
662
  if hay_rep:
663
  ec = set_row_cells(ec, rv + 3, {
664
  'D': build_cell('D%d' % (rv + 3), s=get_style(ec, 'D%d' % (rv + 3)), num=round(dep_rep_tot, 2))})
 
753
 
754
 
755
  if __name__ == '__main__':
756
+ main()