diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index fe942bf46..3e76fc0c2 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -389,8 +389,8 @@ def calculate_usage(usage, free_sms_fragment_limit): letters = [(breakdown["billing_units"], breakdown['letter_total']) for breakdown in usage if breakdown['notification_type'] == 'letter'] - letter_sent = 0 if len(letters) == 0 else letters[0][0] - letter_cost = 0 if len(letters) == 0 else letters[0][1] + letter_sent = sum(row[0] for row in letters) + letter_cost = sum(row[1] for row in letters) return { 'emails_sent': emails_sent, diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index e90a40ca0..c5fdab8c1 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -777,11 +777,12 @@ def test_usage_page_with_letters( assert 'April' in table assert 'February' in table assert 'March' in table - assert '£18.94' in table + assert '£20.59' in table assert '140 free text messages' in table assert '£20.30' in table assert '1,230 text messages at 1.65p' in table assert '10 letters at 31p' in table + assert '5 letters at 33p' in table def test_usage_page_with_year_argument( diff --git a/tests/conftest.py b/tests/conftest.py index 7fd67fac6..1797177c6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2288,6 +2288,14 @@ def mock_get_billable_units(mocker): 'notification_type': 'letter', 'rate': 0.31, 'billing_units': 10 + }, + { + 'month': 'February', + 'international': False, + 'rate_multiplier': 1, + 'notification_type': 'letter', + 'rate': 0.33, + 'billing_units': 5 } ]