From 287b7d1dec36afeb6b570cb1f93c6143026e214f Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 14 Oct 2024 11:52:42 -0700 Subject: [PATCH] update billing dao --- app/dao/fact_billing_dao.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py index 111a9a053..bd6474ac2 100644 --- a/app/dao/fact_billing_dao.py +++ b/app/dao/fact_billing_dao.py @@ -845,8 +845,8 @@ def fetch_daily_volumes_for_platform(start_date, end_date): def fetch_daily_sms_provider_volumes_for_platform(start_date, end_date): # query to return the total notifications sent per day for each channel. NB start and end dates are inclusive - daily_volume_stats = ( - db.session.query( + stmt = ( + select( FactBilling.local_date, FactBilling.provider, func.sum(FactBilling.notifications_sent).label("sms_totals"), @@ -860,6 +860,7 @@ def fetch_daily_sms_provider_volumes_for_platform(start_date, end_date): * FactBilling.rate ).label("sms_cost"), ) + .select_from(FactBilling) .filter( FactBilling.notification_type == NotificationType.SMS, FactBilling.local_date >= start_date, @@ -873,10 +874,8 @@ def fetch_daily_sms_provider_volumes_for_platform(start_date, end_date): FactBilling.local_date, FactBilling.provider, ) - .all() ) - - return daily_volume_stats + return db.session.execute(stmt).scalars().all() def fetch_volumes_by_service(start_date, end_date): @@ -885,7 +884,7 @@ def fetch_volumes_by_service(start_date, end_date): year_end_date = int(end_date.strftime("%Y")) volume_stats = ( - db.session.query( + select( FactBilling.local_date, FactBilling.service_id, func.sum( @@ -916,6 +915,7 @@ def fetch_volumes_by_service(start_date, end_date): ) ).label("email_totals"), ) + .select_from(FactBilling) .filter( FactBilling.local_date >= start_date, FactBilling.local_date <= end_date ) @@ -928,18 +928,18 @@ def fetch_volumes_by_service(start_date, end_date): ) annual_billing = ( - db.session.query( + select( func.max(AnnualBilling.financial_year_start).label("financial_year_start"), AnnualBilling.service_id, AnnualBilling.free_sms_fragment_limit, ) + .select_from(AnnualBilling) .filter(AnnualBilling.financial_year_start <= year_end_date) .group_by(AnnualBilling.service_id, AnnualBilling.free_sms_fragment_limit) .subquery() ) - - results = ( - db.session.query( + stmt = ( + select( Service.name.label("service_name"), Service.id.label("service_id"), Service.organization_id.label("organization_id"), @@ -977,7 +977,7 @@ def fetch_volumes_by_service(start_date, end_date): Organization.name, Service.name, ) - .all() ) + results = db.session.execute(stmt).scalars().all() return results