From 00a629befc927bc820d44cafcec2908557afdb98 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Fri, 12 Nov 2021 14:35:16 +0000 Subject: [PATCH] Link to downloadable report for org usage Link is sticky so that it is easy to spot even when an org has many services. --- app/main/views/organisations.py | 12 +++++++- .../organisations/organisation/index.html | 6 ++++ .../views/organisations/test_organisations.py | 30 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/app/main/views/organisations.py b/app/main/views/organisations.py index 867337266..c1d247b5b 100644 --- a/app/main/views/organisations.py +++ b/app/main/views/organisations.py @@ -156,10 +156,20 @@ def organisation_dashboard(org_id): **{ f'total_{key}': sum(service[key] for service in services) for key in ('emails_sent', 'sms_cost', 'letter_cost') - } + }, + download_link=url_for( + '.download_services_report_for_org', + org_id=org_id, + ) ) +@main.route("/organisations/", methods=['GET']) +@user_has_permissions() +def download_services_report_for_org(org_id): + pass + + @main.route("/organisations//trial-services", methods=['GET']) @user_is_platform_admin def organisation_trial_mode_services(org_id): diff --git a/app/templates/views/organisations/organisation/index.html b/app/templates/views/organisations/organisation/index.html index 7d4818872..5309ac813 100644 --- a/app/templates/views/organisations/organisation/index.html +++ b/app/templates/views/organisations/organisation/index.html @@ -112,4 +112,10 @@
{% endif %} + + {% endblock %} diff --git a/tests/app/main/views/organisations/test_organisations.py b/tests/app/main/views/organisations/test_organisations.py index c690d5301..6cd22e0b9 100644 --- a/tests/app/main/views/organisations/test_organisations.py +++ b/tests/app/main/views/organisations/test_organisations.py @@ -624,6 +624,36 @@ def test_organisation_services_hides_search_bar_for_7_or_fewer_services( assert not page.select_one('.live-search') +def test_organisation_services_links_to_downloadable_report( + client_request, + mock_get_organisation, + mocker, + active_user_with_permissions, + fake_uuid, +): + mocker.patch( + 'app.organisations_client.get_services_and_usage', + return_value={"services": [ + { + 'service_id': SERVICE_ONE_ID, + 'service_name': 'Service 1', + 'chargeable_billable_sms': 250122, + 'emails_sent': 13000, + 'free_sms_limit': 250000, + 'letter_cost': 30.50, + 'sms_billable_units': 122, + 'sms_cost': 1.93, + 'sms_remainder': None + }, + ] * 2} + ) + client_request.login(active_user_with_permissions) + page = client_request.get('.organisation_dashboard', org_id=ORGANISATION_ID) + + link_to_report = page.find('a', text="Download this report") + assert link_to_report.attrs["href"] == url_for('.download_services_report_for_org', org_id=ORGANISATION_ID) + + def test_organisation_trial_mode_services_shows_all_non_live_services( client_request, platform_admin_user,