diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 748d54c36..06b78355b 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -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 { diff --git a/tests/conftest.py b/tests/conftest.py index f5e397870..721474770 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2316,11 +2316,41 @@ def mock_get_monthly_notification_stats(mocker, service_one, fake_uuid): def mock_get_usage(mocker, service_one, fake_uuid): def _get_usage(service_id, year=None): return [ - {"notification_type": "email", "billing_units": 1000, "rate": 0.00, "letter_total": 0}, - {"notification_type": "sms", "billing_units": 251500, "rate": 0.0165, "letter_total": 0}, - {"notification_type": "sms", "billing_units": 300, "rate": 0.0165, "letter_total": 0}, - {"notification_type": "sms", "billing_units": 300, "rate": 0.0165, "letter_total": 0}, - {"notification_type": "sms", "billing_units": 90, "rate": 0.0165, "letter_total": 0} + { + "notification_type": "email", + "chargeable_units": 1000, + "notifications_sent": 1000, + "rate": 0.00, + "letter_total": 0 + }, + { + "notification_type": "sms", + "chargeable_units": 251500, + "notifications_sent": 105000, + "rate": 0.0165, + "letter_total": 0 + }, + { + "notification_type": "sms", + "chargeable_units": 300, + "notifications_sent": 300, + "rate": 0.0165, + "letter_total": 0 + }, + { + "notification_type": "sms", + "chargeable_units": 300, + "notifications_sent": 150, + "rate": 0.0165, + "letter_total": 0 + }, + { + "notification_type": "sms", + "chargeable_units": 90, + "notifications_sent": 90, + "rate": 0.0165, + "letter_total": 0 + } ] return mocker.patch( @@ -2440,12 +2470,18 @@ def mock_get_future_usage(mocker, service_one, fake_uuid): def _get_usage(service_id, year=None): return [ { - 'notification_type': 'sms', 'billing_units': 0, - 'rate': 0.0158, 'letter_total': 0 + 'notification_type': 'sms', + 'chargeable_units': 0, + 'notifications_sent': 0, + 'rate': 0.0158, + 'letter_total': 0 }, { - 'notification_type': 'email', 'billing_units': 0, - 'rate': 0.0, 'letter_total': 0 + 'notification_type': 'email', + 'chargeable_units': 0, + 'notifications_sent': 0, + 'rate': 0.0, + 'letter_total': 0 } ]