diff --git a/app/commands.py b/app/commands.py index ebdd0db07..5a9d96535 100644 --- a/app/commands.py +++ b/app/commands.py @@ -891,7 +891,7 @@ def populate_annual_billing_with_the_previous_years_allowance(year): def populate_annual_billing_with_defaults(year, missing_services_only): """ Add or update annual billing with free allowance defaults for all active services. - DEFAULT_FREE_SMS_FRAGMENT_LIMITS is the new free allowances for the financial year starting 2021. + The default free allowance limits are in: app/dao/annual_billing_dao.py:57. If missing_services_only is true then only add rows for services that do not have annual billing for that year yet. This is useful to prevent overriding any services that have a free allowance that is not the default. diff --git a/app/dao/annual_billing_dao.py b/app/dao/annual_billing_dao.py index 515d30263..36d12e540 100644 --- a/app/dao/annual_billing_dao.py +++ b/app/dao/annual_billing_dao.py @@ -90,6 +90,10 @@ def set_default_free_allowance_for_service(service, year_start=None): } if not year_start: year_start = get_current_financial_year_start_year() + if year_start < 2020: + year_start = 2020 + if year_start > 2021: + year_start = 2021 if service.organisation_type: free_allowance = default_free_sms_fragment_limits[service.organisation_type][year_start] else: diff --git a/tests/app/dao/test_annual_billing_dao.py b/tests/app/dao/test_annual_billing_dao.py index 580102a59..37e8e4fb2 100644 --- a/tests/app/dao/test_annual_billing_dao.py +++ b/tests/app/dao/test_annual_billing_dao.py @@ -9,7 +9,7 @@ from app.dao.annual_billing_dao import ( ) from app.dao.date_util import get_current_financial_year_start_year from app.models import AnnualBilling -from tests.app.db import create_annual_billing, create_service_with_organisation +from tests.app.db import create_annual_billing, create_service def test_dao_update_free_sms_fragment_limit(notify_db_session, sample_service): @@ -65,10 +65,12 @@ def test_dao_update_annual_billing_for_future_years(notify_db_session, sample_se ('school_or_college', 2020, 25000), ('other', 2020, 25000), (None, 2020, 25000), + ('central', 2019, 250000), + ('school_or_college', 2022, 10000) ]) def test_set_default_free_allowance_for_service(notify_db_session, org_type, year, expected_default): - service = create_service_with_organisation(org_type=org_type) + service = create_service(organisation_type=org_type) set_default_free_allowance_for_service(service=service, year_start=year) diff --git a/tests/app/db.py b/tests/app/db.py index 3947a5afe..2338a62ec 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -199,14 +199,6 @@ def create_service_with_defined_sms_sender( return service -def create_service_with_organisation(org_type): - service = create_service(service_name=f'{org_type} service') - org = create_organisation(name=f'{org_type} org', organisation_type=org_type) - dao_add_service_to_organisation(service=service, organisation_id=org.id) - - return service - - def create_template( service, template_type=SMS_TYPE,