split out org sms usage into separate function

this'll allow us to reuse the complex sql query for the platform admin
report, which doesn't care about organisations
This commit is contained in:
Leo Hemsted
2022-05-20 12:45:16 +01:00
parent 6495b192a6
commit 9e84f4e0b9
2 changed files with 42 additions and 12 deletions

View File

@@ -762,6 +762,12 @@ def fetch_sms_billing_for_organisation(organisation_id, financial_year):
def query_organisation_sms_usage_for_year(organisation_id, year):
return query_sms_usage_for_year_per_service(year).filter(
Service.organisation_id == organisation_id
)
def query_sms_usage_for_year_per_service(year):
"""
See docstring for query_service_sms_usage_for_year()
"""
@@ -813,7 +819,6 @@ def query_organisation_sms_usage_for_year(organisation_id, year):
FactBilling.notification_type == SMS_TYPE,
)
).filter(
Service.organisation_id == organisation_id,
AnnualBilling.financial_year_start == year,
)