diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 06b78355b..61a5c6daa 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -332,13 +332,14 @@ def get_annual_usage_breakdown(usage, free_sms_fragment_limit): sms_rate = 0 if len(sms) == 0 else sms[0].get("rate", 0) sms_chargeable_units = sum(row['chargeable_units'] for row in sms) sms_free_allowance = free_sms_fragment_limit + sms_cost = sum(row['cost'] for row in sms) emails = get_usage_breakdown_by_type(usage, 'email') emails_sent = sum(row['notifications_sent'] for row in emails) letters = get_usage_breakdown_by_type(usage, 'letter') letters_sent = sum(row['notifications_sent'] for row in letters) - letters_cost = sum(row['letter_total'] for row in letters) + letters_cost = sum(row['cost'] for row in letters) return { 'emails_sent': emails_sent, @@ -346,6 +347,7 @@ def get_annual_usage_breakdown(usage, free_sms_fragment_limit): 'sms_sent': sms_chargeable_units, 'sms_allowance_remaining': max(0, (sms_free_allowance - sms_chargeable_units)), 'sms_chargeable': max(0, sms_chargeable_units - sms_free_allowance), + 'sms_cost': sms_cost, 'sms_rate': sms_rate, 'letter_sent': letters_sent, 'letter_cost': letters_cost diff --git a/app/templates/views/dashboard/_usage.html b/app/templates/views/dashboard/_usage.html index 6cad43324..4046e6c91 100644 --- a/app/templates/views/dashboard/_usage.html +++ b/app/templates/views/dashboard/_usage.html @@ -8,9 +8,9 @@
- {% if sms_chargeable %} + {% if sms_cost %} {{ big_number( - sms_chargeable * sms_rate, + sms_cost, 'spent on text messages', currency="£", smaller=True diff --git a/app/templates/views/usage.html b/app/templates/views/usage.html index 4479c97fa..9f0557a50 100644 --- a/app/templates/views/usage.html +++ b/app/templates/views/usage.html @@ -59,7 +59,7 @@
{{ big_number( - (sms_chargeable * sms_rate), + sms_cost, 'spent', currency="£", smaller=True diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 9dc529a96..4e2341f22 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1020,7 +1020,7 @@ def test_usage_page( assert '251,800 sent' in sms_column assert '250,000 free allowance' in sms_column assert '0 free allowance remaining' in sms_column - assert '£36.14 spent' in sms_column + assert '£29.85 spent' in sms_column assert '1,800 at 1.65 pence' in sms_column letter_column = normalize_spaces(annual_usage[2].text + annual_usage[5].text) @@ -1855,7 +1855,7 @@ def test_service_dashboard_shows_usage( ) == ( 'Unlimited ' 'free email allowance ' - '£36.14 ' + '£29.85 ' 'spent on text messages ' '£30.00 ' 'spent on letters' diff --git a/tests/conftest.py b/tests/conftest.py index 01a5a4db6..68f7b7231 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2321,28 +2321,28 @@ def mock_get_usage(mocker, service_one, fake_uuid): "chargeable_units": 1000, "notifications_sent": 1000, "rate": 0.00, - "letter_total": 0 + "cost": 0 }, { "notification_type": "sms", "chargeable_units": 251500, "notifications_sent": 105000, "rate": 0.0165, - "letter_total": 0 + "cost": 24.75 # 250K free allowance }, { "notification_type": "sms", "chargeable_units": 300, "notifications_sent": 300, "rate": 0.0165, - "letter_total": 0 + "cost": 5.1 }, { "notification_type": "letter", "chargeable_units": 300, "notifications_sent": 100, "rate": 0.1, - "letter_total": 30 + "cost": 30 }, ] @@ -2467,14 +2467,14 @@ def mock_get_future_usage(mocker, service_one, fake_uuid): 'chargeable_units': 0, 'notifications_sent': 0, 'rate': 0.0158, - 'letter_total': 0 + 'cost': 0 }, { 'notification_type': 'email', 'chargeable_units': 0, 'notifications_sent': 0, 'rate': 0.0, - 'letter_total': 0 + 'cost': 0 } ]