diff --git a/backend/api/v1/modules/core/dashboard/service.py b/backend/api/v1/modules/core/dashboard/service.py index 64c00dba..f68015e1 100644 --- a/backend/api/v1/modules/core/dashboard/service.py +++ b/backend/api/v1/modules/core/dashboard/service.py @@ -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")