mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-04 12:28:24 -04:00
Wire in the new API method that calculates the total cost and total billable units.
- Used on dashboard to calculate free tier/cost - Update tests to mock new method - Two new tests to check output on dashboard page
This commit is contained in:
@@ -186,7 +186,7 @@ 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(
|
||||
**calculate_fee_tier_usage(service_api_client.get_yearly_sms_unit_count_and_cost(
|
||||
service_id,
|
||||
get_current_financial_year(),
|
||||
))
|
||||
@@ -201,6 +201,18 @@ def get_dashboard_totals(statistics):
|
||||
return statistics
|
||||
|
||||
|
||||
def calculate_fee_tier_usage(usage):
|
||||
# TODO: Don't hardcode these - get em from the API
|
||||
sms_free_allowance = 250000
|
||||
|
||||
return({
|
||||
'sms_chargeable': max(0, usage['billable_sms_units'] - sms_free_allowance),
|
||||
'total_sms_bill': usage['billable_sms_units'],
|
||||
'total_sms_cost': usage['total_cost'],
|
||||
'sms_allowance_remaining': sms_free_allowance - int(usage['billable_sms_units'])
|
||||
})
|
||||
|
||||
|
||||
def calculate_usage(usage):
|
||||
# TODO: Don't hardcode these - get em from the API
|
||||
sms_free_allowance = 250000
|
||||
|
||||
@@ -221,6 +221,12 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
||||
params=dict(year=year)
|
||||
)
|
||||
|
||||
def get_yearly_sms_unit_count_and_cost(self, service_id, year=None):
|
||||
return self.get(
|
||||
'/service/{0}/yearly-sms-billable-units'.format(service_id),
|
||||
params=dict(year=year)
|
||||
)
|
||||
|
||||
def get_monthly_notification_stats(self, service_id, year):
|
||||
return self.get(url='/service/{}/notifications/monthly?year={}'.format(service_id, year))
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<div class="keyline-block">
|
||||
{% if sms_chargeable %}
|
||||
{{ big_number(
|
||||
(sms_chargeable * sms_rate),
|
||||
total_sms_cost,
|
||||
'spent on text messages',
|
||||
currency="£",
|
||||
smaller=True
|
||||
|
||||
Reference in New Issue
Block a user