diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py index 9dd26f703..f1b1b70a6 100644 --- a/app/dao/fact_billing_dao.py +++ b/app/dao/fact_billing_dao.py @@ -118,38 +118,6 @@ def fetch_sms_billing_for_all_services(start_date, end_date): return query.all() -def fetch_letter_costs_and_totals_for_all_services(start_date, end_date): - query = db.session.query( - Organisation.name.label("organisation_name"), - Organisation.id.label("organisation_id"), - Service.name.label("service_name"), - Service.id.label("service_id"), - func.sum(FactBilling.notifications_sent).label("total_letters"), - func.sum(FactBilling.notifications_sent * FactBilling.rate).label("letter_cost") - ).select_from( - Service - ).outerjoin( - Service.organisation - ).join( - FactBilling, FactBilling.service_id == Service.id, - ).filter( - FactBilling.service_id == Service.id, - FactBilling.local_date >= start_date, - FactBilling.local_date <= end_date, - FactBilling.notification_type == LETTER_TYPE, - ).group_by( - Organisation.name, - Organisation.id, - Service.id, - Service.name, - ).order_by( - Organisation.name, - Service.name - ) - - return query.all() - - def fetch_letter_line_items_for_all_services(start_date, end_date): query = db.session.query( Organisation.name.label("organisation_name"), @@ -622,31 +590,6 @@ def create_billing_record(data, rate, process_day): return billing_record -def fetch_letter_costs_for_organisation(organisation_id, start_date, end_date): - query = db.session.query( - Service.name.label("service_name"), - Service.id.label("service_id"), - func.sum(FactBilling.notifications_sent * FactBilling.rate).label("letter_cost") - ).select_from( - Service - ).join( - FactBilling, FactBilling.service_id == Service.id, - ).filter( - FactBilling.local_date >= start_date, - FactBilling.local_date <= end_date, - FactBilling.notification_type == LETTER_TYPE, - Service.organisation_id == organisation_id, - Service.restricted.is_(False) - ).group_by( - Service.id, - Service.name, - ).order_by( - Service.name - ) - - return query.all() - - def fetch_email_usage_for_organisation(organisation_id, start_date, end_date): query = db.session.query( Service.name.label("service_name"), @@ -793,12 +736,10 @@ def fetch_usage_year_for_organisation(organisation_id, year): 'sms_billable_units': 0, 'chargeable_billable_sms': 0, 'sms_cost': 0.0, - 'letter_cost': 0.0, 'emails_sent': 0, 'active': service.active } sms_usages = fetch_sms_billing_for_organisation(organisation_id, year) - letter_usages = fetch_letter_costs_for_organisation(organisation_id, year_start, year_end) email_usages = fetch_email_usage_for_organisation(organisation_id, year_start, year_end) for usage in sms_usages: service_with_usage[str(usage.service_id)] = { @@ -809,12 +750,9 @@ def fetch_usage_year_for_organisation(organisation_id, year): 'sms_billable_units': usage.sms_billable_units, 'chargeable_billable_sms': usage.chargeable_billable_sms, 'sms_cost': float(usage.sms_cost), - 'letter_cost': 0.0, 'emails_sent': 0, 'active': usage.active } - for letter_usage in letter_usages: - service_with_usage[str(letter_usage.service_id)]['letter_cost'] = float(letter_usage.letter_cost) for email_usage in email_usages: service_with_usage[str(email_usage.service_id)]['emails_sent'] = email_usage.emails_sent @@ -863,16 +801,6 @@ def fetch_daily_volumes_for_platform(start_date, end_date): (FactBilling.notification_type == EMAIL_TYPE, FactBilling.notifications_sent) ], else_=0 )).label('email_totals'), - # func.sum(case( - # [ - # (FactBilling.notification_type == LETTER_TYPE, FactBilling.notifications_sent) - # ], else_=0 - # )).label('letter_totals'), - # func.sum(case( - # [ - # (FactBilling.notification_type == LETTER_TYPE, FactBilling.billable_units) - # ], else_=0 - # )).label('letter_sheet_totals') ).filter( FactBilling.local_date >= start_date, FactBilling.local_date <= end_date @@ -888,8 +816,6 @@ def fetch_daily_volumes_for_platform(start_date, end_date): func.sum( daily_volume_stats.c.sms_fragments_times_multiplier).label('sms_chargeable_units'), func.sum(daily_volume_stats.c.email_totals).label('email_totals'), - # func.sum(daily_volume_stats.c.letter_totals).label('letter_totals'), - # func.sum(daily_volume_stats.c.letter_sheet_totals).label('letter_sheet_totals') ).group_by( daily_volume_stats.c.local_date ).order_by( @@ -941,17 +867,6 @@ def fetch_volumes_by_service(start_date, end_date): func.sum(case([ (FactBilling.notification_type == EMAIL_TYPE, FactBilling.notifications_sent) ], else_=0)).label('email_totals'), - func.sum(case([ - (FactBilling.notification_type == LETTER_TYPE, FactBilling.notifications_sent) - ], else_=0)).label('letter_totals'), - func.sum(case([ - (FactBilling.notification_type == LETTER_TYPE, FactBilling.notifications_sent * FactBilling.rate) - ], else_=0)).label("letter_cost"), - func.sum(case( - [ - (FactBilling.notification_type == LETTER_TYPE, FactBilling.billable_units) - ], else_=0 - )).label('letter_sheet_totals') ).filter( FactBilling.local_date >= start_date, FactBilling.local_date <= end_date @@ -982,9 +897,6 @@ def fetch_volumes_by_service(start_date, end_date): func.coalesce(func.sum(volume_stats.c.sms_fragments_times_multiplier), 0 ).label("sms_chargeable_units"), func.coalesce(func.sum(volume_stats.c.email_totals), 0).label("email_totals"), - func.coalesce(func.sum(volume_stats.c.letter_totals), 0).label("letter_totals"), - func.coalesce(func.sum(volume_stats.c.letter_cost), 0).label("letter_cost"), - func.coalesce(func.sum(volume_stats.c.letter_sheet_totals), 0).label("letter_sheet_totals") ).select_from( Service ).outerjoin( diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index f952a06f0..c173a64df 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -523,7 +523,6 @@ def dao_get_notifications_processing_time_stats(start_date, end_date): Notification.created_at < end_date, Notification.api_key_id.isnot(None), Notification.key_type != KEY_TYPE_TEST, - # Notification.notification_type != LETTER_TYPE ).one() diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 0c7113101..e10a702b5 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -106,16 +106,12 @@ def dao_fetch_live_services_data(): Service.go_live_at.label("live_date"), Service.volume_sms.label('sms_volume_intent'), Service.volume_email.label('email_volume_intent'), - Service.volume_letter.label('letter_volume_intent'), case([ (this_year_ft_billing.c.notification_type == 'email', func.sum(this_year_ft_billing.c.notifications_sent)) ], else_=0).label("email_totals"), case([ (this_year_ft_billing.c.notification_type == 'sms', func.sum(this_year_ft_billing.c.notifications_sent)) ], else_=0).label("sms_totals"), - case([ - (this_year_ft_billing.c.notification_type == 'letter', func.sum(this_year_ft_billing.c.notifications_sent)) - ], else_=0).label("letter_totals"), AnnualBilling.free_sms_fragment_limit, ).join( Service.annual_billing @@ -149,7 +145,6 @@ def dao_fetch_live_services_data(): Service.go_live_at, Service.volume_sms, Service.volume_email, - Service.volume_letter, this_year_ft_billing.c.notification_type, AnnualBilling.free_sms_fragment_limit, ).order_by( @@ -162,7 +157,6 @@ def dao_fetch_live_services_data(): if existing_service is not None: existing_service["email_totals"] += row.email_totals existing_service["sms_totals"] += row.sms_totals - existing_service["letter_totals"] += row.letter_totals else: results.append(row._asdict()) return results diff --git a/tests/app/dao/test_fact_billing_dao.py b/tests/app/dao/test_fact_billing_dao.py index c5c39d600..290058921 100644 --- a/tests/app/dao/test_fact_billing_dao.py +++ b/tests/app/dao/test_fact_billing_dao.py @@ -629,7 +629,6 @@ def test_fetch_usage_year_for_organisation(notify_db_session): assert first_row['sms_remainder'] == 5 # because there are 5 billable units assert first_row['chargeable_billable_sms'] == 0 assert first_row['sms_cost'] == 0.0 - assert first_row['letter_cost'] == 0 assert first_row['emails_sent'] == 0 second_row = results[str(service_with_emails_for_org.id)] @@ -639,7 +638,6 @@ def test_fetch_usage_year_for_organisation(notify_db_session): assert second_row['sms_remainder'] == 0 assert second_row['chargeable_billable_sms'] == 0 assert second_row['sms_cost'] == 0 - assert second_row['letter_cost'] == 0 assert second_row['emails_sent'] == 1100 third_row = results[str(fixtures["service_with_out_ft_billing_this_year"].id)] @@ -649,7 +647,6 @@ def test_fetch_usage_year_for_organisation(notify_db_session): assert third_row['sms_remainder'] == 10 assert third_row['chargeable_billable_sms'] == 0 assert third_row['sms_cost'] == 0 - assert third_row['letter_cost'] == 0 assert third_row['emails_sent'] == 0 @@ -1008,9 +1005,6 @@ def test_fetch_volumes_by_service(notify_db_session): assert results[0].sms_notifications == 2 assert results[0].sms_chargeable_units == 3 assert results[0].email_totals == 0 - assert results[0].letter_totals == 0 - assert results[0].letter_sheet_totals == 0 - assert float(results[0].letter_cost) == 0 assert results[1].service_name == 'f - without ft_billing' assert results[1].organisation_name == 'Org for a - with sms and letter' @@ -1018,9 +1012,6 @@ def test_fetch_volumes_by_service(notify_db_session): assert results[1].sms_notifications == 0 assert results[1].sms_chargeable_units == 0 assert results[1].email_totals == 0 - assert results[1].letter_totals == 0 - assert results[1].letter_sheet_totals == 0 - assert float(results[1].letter_cost) == 0 assert results[3].service_name == 'b - chargeable sms' assert not results[3].organisation_name @@ -1028,9 +1019,6 @@ def test_fetch_volumes_by_service(notify_db_session): assert results[3].sms_notifications == 2 assert results[3].sms_chargeable_units == 3 assert results[3].email_totals == 0 - assert results[3].letter_totals == 0 - assert results[3].letter_sheet_totals == 0 - assert float(results[3].letter_cost) == 0 assert results[4].service_name == 'e - sms within allowance' assert not results[4].organisation_name @@ -1038,6 +1026,3 @@ def test_fetch_volumes_by_service(notify_db_session): assert results[4].sms_notifications == 1 assert results[4].sms_chargeable_units == 2 assert results[4].email_totals == 0 - assert results[4].letter_totals == 0 - assert results[4].letter_sheet_totals == 0 - assert float(results[4].letter_cost) == 0 diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index 1ff31bcab..e616cc67c 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -423,20 +423,15 @@ def test_dao_fetch_live_services_data(sample_user): 'organisation_type': 'federal', 'consent_to_research': None, 'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+12028675309', 'live_date': datetime(2014, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None, - 'letter_volume_intent': None, 'sms_totals': 2, 'email_totals': 1, 'letter_totals': 0, - 'free_sms_fragment_limit': 100}, + 'sms_totals': 2, 'email_totals': 1, 'free_sms_fragment_limit': 100}, {'service_id': mock.ANY, 'service_name': 'third', 'organisation_name': None, 'consent_to_research': None, 'organisation_type': None, 'contact_name': None, 'contact_email': None, 'contact_mobile': None, 'live_date': datetime(2016, 4, 20, 10, 0), 'sms_volume_intent': None, - 'email_volume_intent': None, 'letter_volume_intent': None, - 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 0, - 'free_sms_fragment_limit': 200}, + 'email_volume_intent': None, 'sms_totals': 0, 'email_totals': 0, 'free_sms_fragment_limit': 200}, {'service_id': mock.ANY, 'service_name': 'second', 'organisation_name': None, 'consent_to_research': None, 'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+12028675309', 'live_date': datetime(2017, 4, 20, 10, 0), 'sms_volume_intent': None, - 'organisation_type': None, 'email_volume_intent': None, 'letter_volume_intent': None, - 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 0, - 'free_sms_fragment_limit': 300} + 'organisation_type': None, 'email_volume_intent': None, 'sms_totals': 0, 'email_totals': 0, 'free_sms_fragment_limit': 300} ] diff --git a/tests/app/organisation/test_rest.py b/tests/app/organisation/test_rest.py index fa6b20c43..650bcacf0 100644 --- a/tests/app/organisation/test_rest.py +++ b/tests/app/organisation/test_rest.py @@ -841,7 +841,6 @@ def test_get_organisation_services_usage(admin_request, notify_db_session): assert service_usage['chargeable_billable_sms'] == 9.0 assert service_usage['emails_sent'] == 0 assert service_usage['free_sms_limit'] == 10 - assert service_usage['letter_cost'] == 0 assert service_usage['sms_billable_units'] == 19 assert service_usage['sms_remainder'] == 0 assert service_usage['sms_cost'] == 0.54 diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index c0de5d2b7..04203ac53 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -197,8 +197,6 @@ def test_get_live_services_data(sample_user, admin_request): 'contact_name': 'Test User', 'email_totals': 1, 'email_volume_intent': None, - 'letter_totals': 0, - 'letter_volume_intent': None, 'live_date': 'Mon, 01 Jan 2018 00:00:00 GMT', 'organisation_name': 'test_org_1', 'service_id': ANY, @@ -215,8 +213,6 @@ def test_get_live_services_data(sample_user, admin_request): 'contact_name': 'Test User', 'email_totals': 0, 'email_volume_intent': None, - 'letter_totals': 0, - 'letter_volume_intent': None, 'live_date': 'Tue, 01 Jan 2019 00:00:00 GMT', 'organisation_name': None, 'service_id': ANY,