Add new total_letters field to the billing report data

This adds total_letters to the data that is returned by the
`/platform-stats/data-for-billing-report` endpoint so that we can add
total letters as a column in the CSV file that can be downloaded.
This commit is contained in:
Katie Smith
2021-06-11 11:11:47 +01:00
parent 6a99a1fbc2
commit 0148b3dba6
4 changed files with 28 additions and 18 deletions

View File

@@ -114,12 +114,13 @@ def fetch_sms_billing_for_all_services(start_date, end_date):
return query.all()
def fetch_letter_costs_for_all_services(start_date, end_date):
def fetch_letter_costs_and_totals_for_all_services(start_date, end_date):
query = db.session.query(
Organisation.name.label("organisation_name"),
Organisation.id.label("organisation_id"),
Service.name.label("service_name"),
Service.id.label("service_id"),
func.sum(FactBilling.notifications_sent).label("total_letters"),
func.sum(FactBilling.notifications_sent * FactBilling.rate).label("letter_cost")
).select_from(
Service