Handle future dates

This commit is contained in:
Ken Tsang
2017-05-02 14:10:56 +01:00
parent 53e78c2b60
commit 829bcd632f
3 changed files with 43 additions and 2 deletions

View File

@@ -204,9 +204,11 @@ def get_dashboard_totals(statistics):
def calculate_usage(usage):
# TODO: Don't hardcode these - get em from the API
sms_free_allowance = 250000
sms_rate = usage[0].get("rate", 0)
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')
emails_sent = [breakdown["billing_units"] for breakdown in usage if breakdown['notification_type'] == 'email'][0]
emails = [breakdown["billing_units"] for breakdown in usage if breakdown['notification_type'] == 'email']
emails_sent = 0 if len(emails) == 0 else emails[0]
return {
'emails_sent': emails_sent,