diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py index 367b3e628..3719cc06c 100644 --- a/app/dao/fact_billing_dao.py +++ b/app/dao/fact_billing_dao.py @@ -195,7 +195,7 @@ def fetch_billing_data_for_day(process_day, service_id=None): def get_rates_for_billing(): non_letter_rates = [(r.notification_type, r.valid_from, r.rate) for r in Rate.query.order_by(desc(Rate.valid_from)).all()] - letter_rates = [(r.start_date, r.crown, r.sheet_count, r.rate) for r in + letter_rates = [(r.start_date, r.crown, r.sheet_count, r.rate, r.post_class) for r in LetterRate.query.order_by(desc(LetterRate.start_date)).all()] return non_letter_rates, letter_rates @@ -211,11 +211,16 @@ def get_service_ids_that_need_billing_populated(start_date, end_date): ).distinct().all() -def get_rate(non_letter_rates, letter_rates, notification_type, date, crown=None, letter_page_count=None): +def get_rate( + non_letter_rates, letter_rates, notification_type, date, crown=None, letter_page_count=None, post_class='second' +): if notification_type == LETTER_TYPE: if letter_page_count == 0: return 0 - return next(r[3] for r in letter_rates if date > r[0] and crown == r[1] and letter_page_count == r[2]) + return next( + r[3] for r in letter_rates if date > r[0] and crown == r[1] + and letter_page_count == r[2] and post_class == r[4] + ) elif notification_type == SMS_TYPE: return next(r[2] for r in non_letter_rates if notification_type == r[0] and date > r[1]) else: @@ -229,7 +234,8 @@ def update_fact_billing(data, process_day): data.notification_type, process_day, data.crown, - data.letter_page_count) + data.letter_page_count, + "second") billing_record = create_billing_record(data, rate, process_day) table = FactBilling.__table__ ''' diff --git a/migrations/versions/0226_new_letter_rates.py b/migrations/versions/0226_new_letter_rates.py index 7e57d388f..54c45bacc 100644 --- a/migrations/versions/0226_new_letter_rates.py +++ b/migrations/versions/0226_new_letter_rates.py @@ -9,11 +9,12 @@ revision = '0226_new_letter_rates' down_revision = '0225_another_letter_org' import uuid +import pytz from datetime import datetime from alembic import op -start = datetime(2018, 10, 1, 0, 0, tzinfo=timezone.utc) +start = datetime(2018, 10, 1, 0, 0, tzinfo=pytz.utc) NEW_RATES = [ (uuid.uuid4(), start, 1, 0.30, True, 'second'), diff --git a/tests/app/celery/test_reporting_tasks.py b/tests/app/celery/test_reporting_tasks.py index a4a21afd7..9b371bf9d 100644 --- a/tests/app/celery/test_reporting_tasks.py +++ b/tests/app/celery/test_reporting_tasks.py @@ -23,7 +23,7 @@ def test_reporting_should_have_decorated_tasks_functions(): assert create_nightly_billing.__wrapped__.__name__ == 'create_nightly_billing' -def mocker_get_rate(non_letter_rates, letter_rates, notification_type, date, crown=None, rate_multiplier=None): +def mocker_get_rate(non_letter_rates, letter_rates, notification_type, date, crown=None, rate_multiplier=None, post_class="second"): if notification_type == LETTER_TYPE: return Decimal(2.1) elif notification_type == SMS_TYPE: @@ -319,9 +319,10 @@ def test_get_rate_for_letter_latest(notify_db_session): non_letter_rates = [(r.notification_type, r.valid_from, r.rate) for r in Rate.query.order_by(desc(Rate.valid_from)).all()] - # letter rates should be passed into the get_rate function as a tuple of start_date, crown, sheet_count & rate - new_letter_rate = (datetime(2017, 12, 1), True, 1, Decimal(0.33)) - old_letter_rate = (datetime(2016, 12, 1), True, 1, Decimal(0.30)) + # letter rates should be passed into the get_rate function as a tuple of start_date, crown, sheet_count, + # rate and post_class + new_letter_rate = (datetime(2017, 12, 1), True, 1, Decimal(0.33), 'second') + old_letter_rate = (datetime(2016, 12, 1), True, 1, Decimal(0.30), 'second') letter_rates = [new_letter_rate, old_letter_rate] rate = get_rate(non_letter_rates, letter_rates, LETTER_TYPE, datetime(2018, 1, 1), True, 1) diff --git a/tests/app/dao/test_ft_billing_dao.py b/tests/app/dao/test_ft_billing_dao.py index 1eeabeff0..a51feb2ea 100644 --- a/tests/app/dao/test_ft_billing_dao.py +++ b/tests/app/dao/test_ft_billing_dao.py @@ -228,7 +228,7 @@ def test_get_rates_for_billing(notify_db_session): non_letter_rates, letter_rates = get_rates_for_billing() assert len(non_letter_rates) == 3 - assert len(letter_rates) == 10 + assert len(letter_rates) == 30 def test_get_rate(notify_db_session):