Fix keys used to render monthly usage

These were out-of-sync with the API.
This commit is contained in:
Ben Thorner
2022-05-11 13:28:33 +01:00
parent 84dde0f824
commit 4abb6110c8
3 changed files with 30 additions and 38 deletions

View File

@@ -398,12 +398,12 @@ def get_monthly_usage_breakdown(year, monthly_usage):
for month in get_months_for_financial_year(year): for month in get_months_for_financial_year(year):
monthly_sms = [row for row in sms if row['month'] == month] monthly_sms = [row for row in sms if row['month'] == month]
sms_free_allowance_used = sum(row['sms_free_allowance_used'] for row in monthly_sms) sms_free_allowance_used = sum(row['free_allowance_used'] for row in monthly_sms)
sms_cost = sum(row['sms_cost'] for row in monthly_sms) sms_cost = sum(row['cost'] for row in monthly_sms)
sms_breakdown = [row for row in monthly_sms if row['sms_charged']] sms_breakdown = [row for row in monthly_sms if row['charged_units']]
monthly_letters = [row for row in letters if row['month'] == month] monthly_letters = [row for row in letters if row['month'] == month]
letter_cost = sum(row['letter_cost'] for row in monthly_letters) letter_cost = sum(row['cost'] for row in monthly_letters)
letter_breakdown = get_monthly_usage_breakdown_for_letters(monthly_letters) letter_breakdown = get_monthly_usage_breakdown_for_letters(monthly_letters)
yield { yield {
@@ -436,7 +436,7 @@ def get_monthly_usage_breakdown_for_letters(monthly_letters):
yield { yield {
"sent": sum(x['notifications_sent'] for x in rate_group), "sent": sum(x['notifications_sent'] for x in rate_group),
"rate": rate_group[0]['rate'], "rate": rate_group[0]['rate'],
"cost": sum(x['letter_cost'] for x in rate_group), "cost": sum(x['cost'] for x in rate_group),
"postage_description": get_monthly_usage_postage_description(rate_group[0]) "postage_description": get_monthly_usage_postage_description(rate_group[0])
} }

View File

@@ -108,7 +108,7 @@
<li class="tabular-numbers">{{ item.sms_free_allowance_used|format_thousands }} free {{ item.sms_free_count|message_count_label('sms', suffix='') }}</li> <li class="tabular-numbers">{{ item.sms_free_allowance_used|format_thousands }} free {{ item.sms_free_count|message_count_label('sms', suffix='') }}</li>
{% endif %} {% endif %}
{% for sms in item.sms_breakdown %} {% for sms in item.sms_breakdown %}
<li class="tabular-numbers">{{ sms.sms_charged|message_count('sms') }} at <li class="tabular-numbers">{{ sms.charged_units|message_count('sms') }} at
{{- ' {:.2f}p'.format(sms.rate * 100) }}</li> {{- ' {:.2f}p'.format(sms.rate * 100) }}</li>
{% endfor %} {% endfor %}
{% for letter in item.letter_breakdown %} {% for letter in item.letter_breakdown %}

View File

@@ -2365,10 +2365,9 @@ def mock_get_monthly_usage_for_service(mocker):
'chargeable_units': 1230, 'chargeable_units': 1230,
'notifications_sent': 1234, 'notifications_sent': 1234,
'postage': 'none', 'postage': 'none',
'sms_charged': 1230, 'charged_units': 1230,
'sms_free_allowance_used': 0, 'free_allowance_used': 0,
'sms_cost': 20.91, 'cost': 20.91,
'letter_cost': 0,
}, },
{ {
'month': 'February', 'month': 'February',
@@ -2377,10 +2376,9 @@ def mock_get_monthly_usage_for_service(mocker):
'chargeable_units': 33, 'chargeable_units': 33,
'notifications_sent': 1234, 'notifications_sent': 1234,
'postage': 'none', 'postage': 'none',
'sms_charged': 33, 'charged_units': 33,
'sms_free_allowance_used': 0, 'free_allowance_used': 0,
'sms_cost': 0.561, 'cost': 0.561,
'letter_cost': 0,
}, },
{ {
'month': 'February', 'month': 'February',
@@ -2389,10 +2387,9 @@ def mock_get_monthly_usage_for_service(mocker):
'chargeable_units': 1100, 'chargeable_units': 1100,
'notifications_sent': 1234, 'notifications_sent': 1234,
'postage': 'none', 'postage': 'none',
'sms_charged': 960, 'charged_units': 960,
'sms_free_allowance_used': 140, 'free_allowance_used': 140,
'sms_cost': 15.84, 'cost': 15.84,
'letter_cost': 0,
}, },
{ {
'month': 'February', 'month': 'February',
@@ -2401,10 +2398,9 @@ def mock_get_monthly_usage_for_service(mocker):
'chargeable_units': 10, 'chargeable_units': 10,
'notifications_sent': 10, 'notifications_sent': 10,
'postage': 'second', 'postage': 'second',
'sms_charged': 0, 'charged_units': 10,
'sms_free_allowance_used': 0, 'free_allowance_used': 0,
'sms_cost': 0, 'cost': 3.1,
'letter_cost': 3.1,
}, },
{ {
'month': 'February', 'month': 'February',
@@ -2413,10 +2409,9 @@ def mock_get_monthly_usage_for_service(mocker):
'chargeable_units': 5, 'chargeable_units': 5,
'notifications_sent': 5, 'notifications_sent': 5,
'postage': 'first', 'postage': 'first',
'sms_charged': 0, 'charged_units': 5,
'sms_free_allowance_used': 0, 'free_allowance_used': 0,
'sms_cost': 0, 'cost': 1.65,
'letter_cost': 1.65,
}, },
{ {
'month': 'February', 'month': 'February',
@@ -2425,10 +2420,9 @@ def mock_get_monthly_usage_for_service(mocker):
'chargeable_units': 3, 'chargeable_units': 3,
'notifications_sent': 3, 'notifications_sent': 3,
'postage': 'europe', 'postage': 'europe',
'sms_charged': 0, 'charged_units': 3,
'sms_free_allowance_used': 0, 'free_allowance_used': 0,
'sms_cost': 0, 'cost': 2.52,
'letter_cost': 2.52,
}, },
{ {
'month': 'February', 'month': 'February',
@@ -2437,10 +2431,9 @@ def mock_get_monthly_usage_for_service(mocker):
'chargeable_units': 7, 'chargeable_units': 7,
'notifications_sent': 7, 'notifications_sent': 7,
'postage': 'rest-of-world', 'postage': 'rest-of-world',
'sms_charged': 0, 'charged_units': 7,
'sms_free_allowance_used': 0, 'free_allowance_used': 0,
'sms_cost': 0, 'cost': 5.88,
'letter_cost': 5.88,
}, },
{ {
'month': 'April', 'month': 'April',
@@ -2449,10 +2442,9 @@ def mock_get_monthly_usage_for_service(mocker):
'chargeable_units': 249860, 'chargeable_units': 249860,
'notifications_sent': 1234, 'notifications_sent': 1234,
'postage': 'none', 'postage': 'none',
'sms_charged': 0, 'charged_units': 0,
'sms_free_allowance_used': 249860, 'free_allowance_used': 249860,
'sms_cost': 0, 'cost': 0,
'letter_cost': 0,
}, },
] ]