Refactor date handling in main.py

This commit is contained in:
GEORGE committed 2026-05-26 09:45:42 -05:00
1 parent 7470cfd9b8
commit 9ceeee0be1
1 file changed
+10 -10
+10 -10
View File
@@ -112,10 +112,10 @@ def get_report_dates():
previous_business_day = now - timedelta(days=days_back) previous_business_day = now - timedelta(days=days_back)
# Objetos .NET DateTime # Objetos .NET DateTime
dt_yesterday = DateTime(previous_business_day.year, previous_business_day.month, previous_business_day.day) dt_previous_business_day = DateTime(previous_business_day.year, previous_business_day.month, previous_business_day.day)
dt_month_start = DateTime(previous_business_day.year, previous_business_day.month, 1) dt_month_start = DateTime(previous_business_day.year, previous_business_day.month, 1)
return dt_month_start, dt_yesterday return dt_month_start, dt_previous_business_day
# --- PROCESO PRINCIPAL --- # --- PROCESO PRINCIPAL ---
######################################################## ########################################################
@@ -137,8 +137,8 @@ def main():
output_dir.mkdir(parents=True, exist_ok=True) output_dir.mkdir(parents=True, exist_ok=True)
# 3. Cálculo de Fechas # 3. Cálculo de Fechas
dt_month_start, dt_yesterday = get_report_dates() dt_month_start, dt_previous_business_day = get_report_dates()
str_ayer = dt_yesterday.ToString("dd/MM/yyyy") str_previous_business_day = dt_previous_business_day.ToString("dd/MM/yyyy")
str_inicio = dt_month_start.ToString("dd/MM/yyyy") str_inicio = dt_month_start.ToString("dd/MM/yyyy")
# 4. Generación de Reportes # 4. Generación de Reportes
@@ -146,24 +146,24 @@ def main():
adjuntos = [] adjuntos = []
# REPORTE 1: Venta del día de ayer # REPORTE 1: Venta del día de ayer
pdf_yesterday = output_dir / f"venta_presupuesto_linea_{dt_yesterday.ToString('dd_MM_yyyy')}.pdf" pdf_yesterday = output_dir / f"venta_presupuesto_linea_{dt_previous_business_day.ToString('dd_MM_yyyy')}.pdf"
if ejecutar_reporte(rpt_file, pdf_yesterday, {"FecIni": dt_yesterday, "FecFin": dt_yesterday}): if ejecutar_reporte(rpt_file, pdf_yesterday, {"FecIni": dt_previous_business_day, "FecFin": dt_previous_business_day}):
adjuntos.append(str(pdf_yesterday)) adjuntos.append(str(pdf_yesterday))
# REPORTE 2: Acumulado del mes actual (MTD) # REPORTE 2: Acumulado del mes actual (MTD)
pdf_mtd = output_dir / f"venta_presupuesto_linea_{dt_month_start.ToString('dd_MM_yyyy')}_al_{dt_yesterday.ToString('dd_MM_yyyy')}.pdf" pdf_mtd = output_dir / f"venta_presupuesto_linea_{dt_month_start.ToString('dd_MM_yyyy')}_al_{dt_previous_business_day.ToString('dd_MM_yyyy')}.pdf"
if ejecutar_reporte(rpt_file, pdf_mtd, {"FecIni": dt_month_start, "FecFin": dt_yesterday}): if ejecutar_reporte(rpt_file, pdf_mtd, {"FecIni": dt_month_start, "FecFin": dt_previous_business_day}):
adjuntos.append(str(pdf_mtd)) adjuntos.append(str(pdf_mtd))
# 5. Envío de Correo Electrónico # 5. Envío de Correo Electrónico
if adjuntos: if adjuntos:
subject = f"Informe de Venta de Presupuestos por Línea - {str_ayer}" subject = f"Informe de Venta de Presupuestos por Línea - {str_previous_business_day}"
body = f""" body = f"""
<html> <html>
<body style="font-family: Arial, sans-serif;"> <body style="font-family: Arial, sans-serif;">
<h2 style="color: #2e6c80;">Informe Automático de Ventas por Línea</h2> <h2 style="color: #2e6c80;">Informe Automático de Ventas por Línea</h2>
<p>Buenos días</p> <p>Buenos días</p>
<p>Me complace compartir con ustedes el reporte de avance de ventas por línea correspondiente al {str_ayer}.</p> <p>Me complace compartir con ustedes el reporte de avance de ventas por línea correspondiente al {str_previous_business_day}.</p>
<p>La información se encuentra disponible en el siguiente dashboard:</p> <p>La información se encuentra disponible en el siguiente dashboard:</p>
<p> <p>
<a href="{CONFIG.powerbi.url}" target="_blank"> <a href="{CONFIG.powerbi.url}" target="_blank">