From 057c4e4568c2e24ad1e4f0e993c9e8b88e4e86ec Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 23 Mar 2021 16:07:57 +0000 Subject: [PATCH] Quick fix to ensure that billing doesn't fail if the crown is not set for the service. The letters rates for cronw and non crown are the same. It would be nice to remove the need for crown but for now this is a quick fix. --- app/dao/fact_billing_dao.py | 2 ++ requirements.txt | 11 +++++++---- tests/app/celery/test_reporting_tasks.py | 11 +++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py index d6fa52519..97c40bf87 100644 --- a/app/dao/fact_billing_dao.py +++ b/app/dao/fact_billing_dao.py @@ -455,6 +455,8 @@ def get_rate( if notification_type == LETTER_TYPE: if letter_page_count == 0: return 0 + # if crown is not set default to true, this is okay because the rates are the same for both crown and non-crown. + crown = crown or True return next( r.rate for r in letter_rates if ( diff --git a/requirements.txt b/requirements.txt index 2a3e7ccc0..27d373238 100644 --- a/requirements.txt +++ b/requirements.txt @@ -47,14 +47,14 @@ alembic==1.5.8 amqp==1.4.9 anyjson==0.3.3 attrs==20.3.0 -awscli==1.19.35 +awscli==1.19.36 bcrypt==3.2.0 billiard==3.3.0.23 bleach==3.3.0 blinker==1.4 boto==2.49.0 -boto3==1.17.35 -botocore==1.20.35 +boto3==1.17.36 +botocore==1.20.36 certifi==2020.12.5 chardet==4.0.0 click==7.1.2 @@ -66,6 +66,7 @@ geojson==2.5.0 govuk-bank-holidays==0.8 greenlet==1.0.0 idna==2.10 +importlib-metadata==3.7.3 Jinja2==2.11.3 jmespath==0.10.0 kombu==3.0.37 @@ -87,13 +88,15 @@ pytz==2021.1 PyYAML==5.4.1 redis==3.5.3 requests==2.25.1 -rsa==4.7.2 +rsa==4.5 s3transfer==0.3.6 Shapely==1.7.1 six==1.15.0 smartypants==2.0.1 soupsieve==2.2.1 statsd==3.3.0 +typing-extensions==3.7.4.3 urllib3==1.26.4 webencodings==0.5.1 Werkzeug==1.0.1 +zipp==3.4.1 diff --git a/tests/app/celery/test_reporting_tasks.py b/tests/app/celery/test_reporting_tasks.py index 10fe41377..f8f873955 100644 --- a/tests/app/celery/test_reporting_tasks.py +++ b/tests/app/celery/test_reporting_tasks.py @@ -379,6 +379,17 @@ def test_get_rate_for_letter_latest(notify_db_session): assert rate == Decimal('0.33') +def test_get_rate_for_letter_latest_if_crown_is_none(notify_db_session): + # letter rates should be passed into the get_rate function as a tuple of start_date, crown, sheet_count, + # rate and post_class + crown = create_letter_rate(datetime(2017, 12, 1), crown=True, sheet_count=1, rate=0.33, post_class='second') + non_crown = create_letter_rate(datetime(2017, 12, 1), crown=False, sheet_count=1, rate=0.35, post_class='second') + letter_rates = [crown, non_crown] + + rate = get_rate([], letter_rates, LETTER_TYPE, date(2018, 1, 1), crown=None, letter_page_count=1) + assert rate == Decimal('0.33') + + def test_get_rate_for_sms_and_email(notify_db_session): non_letter_rates = [ create_rate(datetime(2017, 12, 1), 0.15, SMS_TYPE),