From e236cc4cbe48541374d7aa1ae265fd67610e58fb Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Thu, 1 Jun 2017 17:04:41 +0100 Subject: [PATCH] Fixed typo and moved the sms free limit into the config. --- app/config.py | 2 ++ app/main/views/dashboard.py | 11 +++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/config.py b/app/config.py index 53eb1e8ac..32cbe76d4 100644 --- a/app/config.py +++ b/app/config.py @@ -59,6 +59,8 @@ class Config(object): ACTIVITY_STATS_LIMIT_DAYS = 7 TEST_MESSAGE_FILENAME = 'Test message' + SMS_FREE_TIER_AMOUNT = 250000 + STATSD_ENABLED = False STATSD_HOST = "statsd.hostedgraphite.com" STATSD_PORT = 8125 diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index d0869fdff..9091a2036 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -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_fee_tier_usage(service_api_client.get_yearly_sms_unit_count_and_cost( + **calculate_free_tier_usage(service_api_client.get_yearly_sms_unit_count_and_cost( service_id, get_current_financial_year(), )) @@ -201,9 +202,8 @@ 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 +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), @@ -214,8 +214,7 @@ def calculate_fee_tier_usage(usage): 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')