Migrate away from ambiguous "billing_units"

This uses two new fields in the annual usage API instead of the
old one, which was actually a mix of two kinds of data [^1].

[^1]: fc378fed96
This commit is contained in:
Ben Thorner
2022-04-26 14:40:01 +01:00
parent 0648f80b9d
commit 55ea5d90c7
2 changed files with 48 additions and 12 deletions

View File

@@ -330,14 +330,14 @@ def get_annual_usage_breakdown(usage, free_sms_fragment_limit):
sms = get_usage_breakdown_by_type(usage, 'sms')
# this relies on the assumption: only one SMS rate per financial year.
sms_rate = 0 if len(sms) == 0 else sms[0].get("rate", 0)
sms_chargeable_units = sum(row['billing_units'] for row in sms)
sms_chargeable_units = sum(row['chargeable_units'] for row in sms)
sms_free_allowance = free_sms_fragment_limit
emails = get_usage_breakdown_by_type(usage, 'email')
emails_sent = sum(row['billing_units'] for row in emails)
emails_sent = sum(row['notifications_sent'] for row in emails)
letters = get_usage_breakdown_by_type(usage, 'letter')
letters_sent = sum(row['billing_units'] for row in letters)
letters_sent = sum(row['notifications_sent'] for row in letters)
letters_cost = sum(row['letter_total'] for row in letters)
return {