mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 09:28:27 -04:00
New report on platform-admin/reports page to get the usage for all services.
This commit is contained in:
@@ -8,6 +8,7 @@ from notifications_python_client.errors import HTTPError
|
||||
from requests import RequestException
|
||||
|
||||
from app import (
|
||||
billing_api_client,
|
||||
complaint_api_client,
|
||||
format_date_numeric,
|
||||
letter_jobs_client,
|
||||
@@ -292,6 +293,34 @@ def notifications_sent_by_service():
|
||||
return render_template('views/platform-admin/notifications_by_service.html', form=form)
|
||||
|
||||
|
||||
@main.route("/platform-admin/reports/usage-for-all-services", methods=['GET', 'POST'])
|
||||
@user_is_platform_admin
|
||||
def usage_for_all_services():
|
||||
form = RequiredDateFilterForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
start_date = form.start_date.data
|
||||
end_date = form.end_date.data
|
||||
headers = ["organisation_id", "organisation_name", "service_id", "service_name",
|
||||
"sms_cost", "sms_fragments", "letter_cost", "letter_breakdown"]
|
||||
|
||||
result = billing_api_client.get_usage_for_all_services(start_date, end_date)
|
||||
rows = []
|
||||
for r in result:
|
||||
rows.append([r['organisation_id'], r["organisation_name"], r["service_id"], r["service_name"],
|
||||
r["sms_cost"], r['sms_fragments'], r["letter_cost"], r["letter_breakdown"].strip()])
|
||||
if rows:
|
||||
return Spreadsheet.from_rows([headers] + rows).as_csv_data, 200, {
|
||||
'Content-Type': 'text/csv; charset=utf-8',
|
||||
'Content-Disposition': 'attachment; filename="Usage for all services from {} to {}.csv"'.format(
|
||||
start_date, end_date
|
||||
)
|
||||
}
|
||||
else:
|
||||
form.errors['start_date'] = 'no results for date'
|
||||
return render_template('views/platform-admin/usage_for_all_services.html', form=form)
|
||||
|
||||
|
||||
@main.route("/platform-admin/complaints")
|
||||
@user_is_platform_admin
|
||||
def platform_admin_list_complaints():
|
||||
|
||||
Reference in New Issue
Block a user