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 00a04ebf54
commit 9310d9e6a3
2 changed files with 42 additions and 12 deletions

View File

@@ -764,6 +764,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()
"""
@@ -815,7 +821,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,
)