diff --git a/app/celery/reporting_tasks.py b/app/celery/reporting_tasks.py index 20aa6c66f..c60afa373 100644 --- a/app/celery/reporting_tasks.py +++ b/app/celery/reporting_tasks.py @@ -1,4 +1,3 @@ -import random from datetime import datetime, timedelta from app.models import (Notification, Rate, @@ -44,14 +43,14 @@ def create_nightly_billing(day_start=None): Notification.template_id, Notification.service_id, Notification.notification_type, - case( - [ - (Notification.notification_type == 'letter', func.coalesce(Notification.sent_by, 'dvla')), - (Notification.notification_type == 'sms', - func.coalesce(Notification.sent_by, random.choice(['mmg', 'firetext']))) - ], - else_='ses' - ).label('sent_by'), # This could be null - this is a bug to be fixed. + func.coalesce(Notification.sent_by, + case( + [ + (Notification.notification_type == 'letter', 'dvla'), + (Notification.notification_type == 'sms', 'unknown'), + (Notification.notification_type == 'email', 'ses') + ]), + ).label('sent_by'), func.coalesce(Notification.rate_multiplier, 1).label('rate_multiplier'), func.coalesce(Notification.international, False).label('international'), func.sum(Notification.billable_units).label('billable_units'), diff --git a/tests/app/celery/test_reporting_tasks.py b/tests/app/celery/test_reporting_tasks.py index 3b3fcdacb..eb4c8453c 100644 --- a/tests/app/celery/test_reporting_tasks.py +++ b/tests/app/celery/test_reporting_tasks.py @@ -261,7 +261,7 @@ def test_create_nightly_billing_null_sent_by_sms( assert record.rate == Decimal(1.33) assert record.billable_units == 1 assert record.rate_multiplier == 1 - assert record.provider in ['mmg', 'firetext'] + assert record.provider == 'unknown' @freeze_time('2018-01-15T03:30:00')