Add financial year filter

Otherwise this page will become less useful come April 1st…
This commit is contained in:
Chris Hill-Scott
2020-02-28 12:32:47 +00:00
parent df5b2f00ef
commit 408fcf05eb
4 changed files with 88 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
from collections import OrderedDict
from functools import partial
from flask import flash, redirect, render_template, request, session, url_for
from flask_login import current_user
@@ -33,6 +34,10 @@ from app.main.forms import (
SetEmailBranding,
SetLetterBranding,
)
from app.main.views.dashboard import (
get_tuples_of_financial_years,
requested_and_current_financial_year,
)
from app.main.views.service_settings import get_branding_as_value_and_label
from app.models.organisation import Organisation, Organisations
from app.models.user import InvitedOrgUser, User
@@ -125,10 +130,19 @@ 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']
year, current_financial_year = requested_and_current_financial_year(request)
services = current_organisation.services_and_usage(
financial_year=year
)['services']
return render_template(
'views/organisations/organisation/index.html',
services=services,
years=get_tuples_of_financial_years(
partial(url_for, '.organisation_dashboard', org_id=current_organisation.id),
start=current_financial_year - 1,
end=current_financial_year + 1,
),
selected_year=year,
**{
f'total_{key}': sum(service[key] for service in services)
for key in ('emails_sent', 'sms_cost', 'letter_cost')

View File

@@ -5,7 +5,6 @@ from app.models import JSONModel, ModelList
from app.notify_client.email_branding_client import email_branding_client
from app.notify_client.letter_branding_client import letter_branding_client
from app.notify_client.organisations_api_client import organisations_client
from app.utils import get_current_financial_year
class Organisation(JSONModel):
@@ -199,8 +198,8 @@ class Organisation(JSONModel):
self.id
)
def services_and_usage(self):
return organisations_client.get_services_and_usage(self.id, get_current_financial_year())
def services_and_usage(self, financial_year):
return organisations_client.get_services_and_usage(self.id, financial_year)
class Organisations(ModelList):

View File

@@ -1,4 +1,5 @@
{% from "components/big-number.html" import big_number %}
{% from "components/pill.html" import pill %}
{% extends "org_template.html" %}
{% block org_page_title %}
@@ -11,32 +12,41 @@
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 class="bottom-gutter-3-2">
{{ pill(years, selected_year, big_number_args={'smallest': True}) }}
</div>
<div class="grid-row bottom-gutter">
<div class="column-one-third">
<div class="keyline-block">
{{ big_number(
total_emails_sent,
label='emails sent',
smaller=True
) }}
</div>
</div>
<div class="column-one-third">
<div class="keyline-block">
{{ big_number(
total_sms_cost,
'spent on text messages',
currency="£",
smaller=True
) }}
</div>
</div>
<div class="column-one-third">
<div class="keyline-block">
{{ big_number(
total_letter_cost,
'spent on letters',
currency="£",
smaller=True
) }}
</div>
</div>
</div>
<ul>
{% for service in services %}
<div class="keyline-block govuk-!-margin-top-2">