From a8d548d91e1934015218aecddd53575d8d662d5e Mon Sep 17 00:00:00 2001 From: AlexeerCT Date: Fri, 20 Mar 2026 11:52:47 -0500 Subject: [PATCH] Refactor date handling in DashboardService for invoice queries - Updated the date calculations in the DashboardService to use the `invoice_date` field instead of `created_at` for querying previous totals and monthly data. - Changed the date variables to return only the date part, improving clarity and consistency in date handling. These changes enhance the accuracy of invoice data retrieval in the dashboard service. --- backend/api/v1/modules/core/dashboard/service.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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")