-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update service free allowance when organisation type change #4371
base: main
Are you sure you want to change the base?
Conversation
ac2f126
to
bbcad60
Compare
@@ -158,6 +160,11 @@ def _update_organisation_services(organisation, attribute, only_where_none=True) | |||
db.session.add(service) | |||
|
|||
|
|||
def _update_organisation_services_free_allowance(organisation): | |||
for service in organisation.services: | |||
set_default_free_allowance_for_service(service, year_start=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function only keeps the manual free allowances if they're 0, but not if they're any other value - it sounds like this isn't what we want to happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested the changes with #4375. set_default_free_allowance_for_service
has been refactored so allowance would be updated for any value.
`test_update_free_sms_fragment_limit_data` previously stopped using the `free_sms_fragment_limit` parameter so it can be removed - it was kept temporarily since the change to remove it needed to be deployed in stages.
Annual billing now has two extra columns, defaulting to False: * high_volume_service_last_year * has_custom_allowance
* if in 2024, a service has a non-zero free allowance different to that of its org type's default, then set "has_custom_allowance = True" * if the service has a zero free allowance in 2024, check the amount of billable units they sent in 2023 to work out why they had that amount - if they sent more than 400k billable units in '23, mark them as a high volume service - otherwise, assume we set them to zero due to juggling free allowance between multiple services, so set has_custom_allowance = true instead Co-authored-by: Leo Hemsted <leo.hemsted@digital.cabinet-office.gov.uk>
This pulls the check out into its own function, since we will want to use it elsewhere.
This updates `dao_create_or_update_annual_billing_for_year` to set the `high_volume_service_last_year` and `has_custom_allowance` attributes if provided, while keeping the current behaviour if not.
If the free allowance for a service has been changed (by a platform admin user), as well as updating the free SMS fragments we should also set the `has_custom_allowance` attribute to True. The exception is if the free allowance is being changed to give it the default for its organisation type - in this case the field should be False since the service no longer has a custom allowance.
Previously, we were persisting a custom free allowance for a service if it was 0 which had a couple of issues: - services with a different custom allowance didn't have this persisted across years - services which a free allowace of 0 due to being a high volume sender never had this reset if they stopped sending so many messages We now automatically check if a service was a high volume sender in the previous financial year and set the free allowance to 0. If a service had a custom free allowance (unrelated to it being a high volume sender), we now carry that forward to subsequent years.
Update the free allowance when updating organisation type. If the service free allowance has been updated manually then it should keep the manual allowance.
bbcad60
to
d73a406
Compare
fact_billing_dao is imported into multiple other dao, creating circular dependency for to get live services and free allowance for org. So moving dao_get_organisation_live_services_and_their_free_allowance into fact_billing_dao to break circular dependancy.
Update the free allowance when updating organisation type. If the service free allowance has been updated manually then it should keep the manual allowance, this requirement should be handled as part of this story. More details on this card.
This PR needs to be merged after #4375