diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py index 5fc8a7904..f69df16f3 100644 --- a/app/dao/fact_billing_dao.py +++ b/app/dao/fact_billing_dao.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta, time from flask import current_app -from sqlalchemy import func, case, desc +from sqlalchemy import func, case, desc, Date from app import db from app.dao.date_util import get_financial_year @@ -33,7 +33,7 @@ def fetch_monthly_billing_for_year(service_id, year): update_fact_billing(data=d, process_day=day) yearly_data = db.session.query( - func.date_trunc('month', FactBilling.bst_date).label("month"), + func.date_trunc('month', FactBilling.bst_date).cast(Date).label("month"), func.sum(FactBilling.notifications_sent).label("notifications_sent"), func.sum(FactBilling.billable_units * FactBilling.rate_multiplier).label("billable_units"), FactBilling.service_id, diff --git a/tests/app/dao/test_ft_billing_dao.py b/tests/app/dao/test_ft_billing_dao.py index 2f7eef368..216caa447 100644 --- a/tests/app/dao/test_ft_billing_dao.py +++ b/tests/app/dao/test_ft_billing_dao.py @@ -221,14 +221,14 @@ def test_fetch_monthly_billing_for_year(notify_db_session): results = fetch_monthly_billing_for_year(service_id=service.id, year=2018) assert len(results) == 2 - assert str(results[0].month.date()) == "2018-06-01" + assert str(results[0].month) == "2018-06-01" assert results[0].notifications_sent == 30 assert results[0].billable_units == Decimal('60') assert results[0].service_id == service.id assert results[0].rate == Decimal('0.162') assert results[0].notification_type == 'sms' - assert str(results[1].month.date()) == "2018-07-01" + assert str(results[1].month) == "2018-07-01" assert results[1].notifications_sent == 31 assert results[1].billable_units == Decimal('31') assert results[1].service_id == service.id @@ -287,20 +287,20 @@ def test_fetch_monthly_billing_for_year_return_financial_year(notify_db_session) # Orders by Month assert len(results) == 36 - assert str(results[0].month.date()) == "2016-04-01" + assert str(results[0].month) == "2016-04-01" assert results[0].notification_type == 'email' assert results[0].notifications_sent == 30 assert results[0].billable_units == 30 assert results[0].rate == Decimal('0') - assert str(results[1].month.date()) == "2016-04-01" + assert str(results[1].month) == "2016-04-01" assert results[1].notification_type == 'letter' assert results[1].notifications_sent == 30 assert results[1].billable_units == 30 assert results[1].rate == Decimal('0.33') - assert str(results[2].month.date()) == "2016-04-01" + assert str(results[2].month) == "2016-04-01" assert results[2].notification_type == 'sms' assert results[2].notifications_sent == 30 assert results[2].billable_units == 30 assert results[2].rate == Decimal('0.162') - assert str(results[3].month.date()) == "2016-05-01" - assert str(results[35].month.date()) == "2017-03-01" + assert str(results[3].month) == "2016-05-01" + assert str(results[35].month) == "2017-03-01"