Sum up usage for an whole organisation

We invoice on a per organisation basis, so it’s useful to know the per
organisation figures without needing to do any spreadsheet-fu.
This commit is contained in:
Chris Hill-Scott
2020-02-27 15:21:08 +00:00
parent 4d89d36847
commit bd9e127e57
4 changed files with 48 additions and 12 deletions

View File

@@ -125,10 +125,14 @@ def add_organisation_from_nhs_local_service(service_id):
@main.route("/organisations/<uuid:org_id>", methods=['GET'])
@user_has_permissions()
def organisation_dashboard(org_id):
services = current_organisation.services_and_usage()
services = current_organisation.services_and_usage()['services']
return render_template(
'views/organisations/organisation/index.html',
services=services
services=services,
**{
f'total_{key}': sum(service[key] for service in services)
for key in ('emails_sent', 'sms_cost', 'letter_cost')
}
)

View File

@@ -11,8 +11,34 @@
Usage
</h1>
<div class="grid-row">
<div class="column-one-third">
{{ big_number(
total_emails_sent,
label='emails sent',
smaller=True
) }}
</div>
<div class="column-one-third">
{{ big_number(
total_sms_cost,
'spent on text messages',
currency="£",
smaller=True
) }}
</div>
<div class="column-one-third">
{{ big_number(
total_letter_cost,
'spent on letters',
currency="£",
smaller=True
) }}
</div>
</div>
<ul>
{% for service in services['services'] %}
{% for service in services %}
<li class="browse-list-item">
<a href="{{ url_for('main.usage', service_id=service.service_id) }}" class="govuk-link govuk-link--no-visited-state browse-list-link">{{ service.service_name }}</a>
</li>

View File

@@ -64,7 +64,7 @@ def test_view_organisation_shows_the_correct_organisation(
'app.organisations_client.get_organisation', return_value=org
)
mocker.patch(
'app.organisations_client.get_services_and_usage', return_value=[]
'app.organisations_client.get_services_and_usage', return_value={'services': {}}
)
page = client_request.get(
@@ -413,19 +413,25 @@ def test_organisation_services_shows_live_services_and_usage(
mock.assert_called_once_with(ORGANISATION_ID, 2019)
services = page.select('.browse-list-item')
usage_rows = page.find_all("div", class_="column-one-third")
assert len(services) == 2
# Totals
assert normalize_spaces(usage_rows[0].text) == "33,000 emails sent"
assert normalize_spaces(usage_rows[1].text) == "£43.93 spent on text messages"
assert normalize_spaces(usage_rows[2].text) == "£30.50 spent on letters"
assert normalize_spaces(services[0].text) == '1'
assert normalize_spaces(services[1].text) == '5'
assert services[0].find('a')['href'] == url_for('main.usage', service_id=SERVICE_ONE_ID)
usage_rows = page.find_all("div", class_="column-one-third")
assert normalize_spaces(usage_rows[0].text) == "13,000 emails sent"
assert normalize_spaces(usage_rows[1].text) == "£1.93 spent on text messages"
assert normalize_spaces(usage_rows[2].text) == "£30.50 spent on letters"
assert normalize_spaces(usage_rows[3].text) == "13,000 emails sent"
assert normalize_spaces(usage_rows[4].text) == "£1.93 spent on text messages"
assert normalize_spaces(usage_rows[5].text) == "£30.50 spent on letters"
assert services[1].find('a')['href'] == url_for('main.usage', service_id=SERVICE_TWO_ID)
assert normalize_spaces(usage_rows[3].text) == "20,000 emails sent"
assert normalize_spaces(usage_rows[4].text) == "£42.00 spent on text messages"
assert normalize_spaces(usage_rows[5].text) == "£0.00 spent on letters"
assert normalize_spaces(usage_rows[6].text) == "20,000 emails sent"
assert normalize_spaces(usage_rows[7].text) == "£42.00 spent on text messages"
assert normalize_spaces(usage_rows[8].text) == "£0.00 spent on letters"
def test_organisation_trial_mode_services_shows_all_non_live_services(

View File

@@ -150,7 +150,7 @@ def test_a_page_should_nave_selected_org_navigation_item(
mocker
):
mocker.patch(
'app.organisations_client.get_services_and_usage', return_value=[]
'app.organisations_client.get_services_and_usage', return_value={'services': {}}
)
page = client_request.get(endpoint, org_id=ORGANISATION_ID)
selected_nav_items = page.select('.navigation a.selected')