Merge pull request #3101 from alphagov/billing-for-all-services-report

Usage for all services
This commit is contained in:
Leo Hemsted
2019-09-02 16:38:23 +01:00
committed by GitHub
18 changed files with 381 additions and 333 deletions

View File

@@ -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,37 @@ 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 = [
[
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()
]
for r in result
]
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:
flash('No results for dates')
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():