mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Filter and navigate usage by financial year
Right now we tell people that the usage page is for the current financial year. This is a lie – it’s for all time. So this commit calls through to the API to get the stats for (by default) the current financial year. We already do this for the monthly breakdown, this just does the same thing for the yearly totals. It also adds navigation to show the data for other financial years: - previous so you can go back and see your usage and verify that the bill you’re about to pay is correct - next so that you can check what your SMS allowance is going to be before you actually get into it
This commit is contained in:
@@ -19,7 +19,7 @@ from app import (
|
||||
template_statistics_client
|
||||
)
|
||||
from app.statistics_utils import get_formatted_percentage, add_rate_to_job
|
||||
from app.utils import user_has_permissions
|
||||
from app.utils import user_has_permissions, get_current_financial_year
|
||||
|
||||
|
||||
# This is a placeholder view method to be replaced
|
||||
@@ -79,17 +79,26 @@ def template_history(service_id):
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
def usage(service_id):
|
||||
current_financial_year = get_current_financial_year()
|
||||
try:
|
||||
year = int(request.args.get('year', 2016))
|
||||
year = int(request.args.get('year', current_financial_year))
|
||||
except ValueError:
|
||||
abort(404)
|
||||
return render_template(
|
||||
'views/usage.html',
|
||||
months=get_free_paid_breakdown_for_billable_units(
|
||||
months=list(get_free_paid_breakdown_for_billable_units(
|
||||
year, service_api_client.get_billable_units(service_id, year)
|
||||
),
|
||||
year=year,
|
||||
**calculate_usage(service_api_client.get_service_usage(service_id)['data'])
|
||||
)),
|
||||
selected_year=year,
|
||||
years=[
|
||||
(
|
||||
'financial year',
|
||||
year,
|
||||
url_for('.usage', service_id=service_id, year=year),
|
||||
'{} to {}'.format(year, year + 1),
|
||||
) for year in range(current_financial_year - 1, current_financial_year + 2)
|
||||
],
|
||||
**calculate_usage(service_api_client.get_service_usage(service_id, year)['data'])
|
||||
)
|
||||
|
||||
|
||||
@@ -156,7 +165,10 @@ def get_dashboard_partials(service_id):
|
||||
'has_jobs': bool(immediate_jobs),
|
||||
'usage': render_template(
|
||||
'views/dashboard/_usage.html',
|
||||
**calculate_usage(service_api_client.get_service_usage(service_id)['data'])
|
||||
**calculate_usage(service_api_client.get_service_usage(
|
||||
service_id,
|
||||
get_current_financial_year(),
|
||||
)['data'])
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user