Merge pull request 'Refactor date handling in DashboardService for invoice queries' (#235) from fix/tendency into development

Reviewed-on: ADUANASOFT/anexo76#235
This commit is contained in:
2026-03-20 16:53:12 +00:00

View File

@@ -68,13 +68,13 @@ class DashboardService:
)
# Total del mes anterior para comparación
last_month = datetime.utcnow() - timedelta(days=30)
last_month = (datetime.utcnow() - timedelta(days=30)).date()
previous_total = (
self.db.query(func.count(InvoiceHeader.id))
.filter(
InvoiceHeader.tenant_id == self.tenant_id,
InvoiceHeader.company_id == self.company_id,
InvoiceHeader.created_at < last_month,
InvoiceHeader.invoice_date < last_month,
)
.scalar()
or 0
@@ -91,17 +91,17 @@ class DashboardService:
)
# Facturas por mes (últimos 6 meses)
six_months_ago = datetime.utcnow() - timedelta(days=180)
six_months_ago = (datetime.utcnow() - timedelta(days=180)).date()
monthly_data = (
self.db.query(
func.date_trunc("month", InvoiceHeader.created_at).label("month"),
func.date_trunc("month", InvoiceHeader.invoice_date).label("month"),
func.count(InvoiceHeader.id).label("count"),
)
.filter(
InvoiceHeader.tenant_id == self.tenant_id,
InvoiceHeader.company_id == self.company_id,
InvoiceHeader.created_at >= six_months_ago,
InvoiceHeader.invoice_date >= six_months_ago,
)
.group_by("month")
.order_by("month")