Merge pull request #1288 from alphagov/add-new-rate-logic

Wire in the new API method that calculates the total cost and total billable units
This commit is contained in:
minglis
2017-06-02 09:52:19 +01:00
committed by GitHub
7 changed files with 87 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ from datetime import datetime
from functools import partial
from flask import (
render_template,
current_app,
url_for,
session,
jsonify,
@@ -186,7 +187,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_free_tier_usage(service_api_client.get_yearly_sms_unit_count_and_cost(
service_id,
get_current_financial_year(),
))
@@ -201,9 +202,19 @@ def get_dashboard_totals(statistics):
return statistics
def calculate_free_tier_usage(usage):
sms_free_allowance = current_app.config['SMS_FREE_TIER_AMOUNT']
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
sms_free_allowance = current_app.config['SMS_FREE_TIER_AMOUNT']
sms_rate = 0 if len(usage) == 0 else usage[0].get("rate", 0)
sms_sent = get_sum_billing_units(breakdown for breakdown in usage if breakdown['notification_type'] == 'sms')