mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
Fix calculating remaining free allowance for SMS
The way it was done before, the remainder was incorrect in the billing report and in the org usage query - it was the sms remainder left at the start of the report period, not at the end of that period. This became apparent when we tried to show sms_remainder on the org usage report, where start date is always the start of the financial year. We saw that sms sent by services did not reduce their free allowance remainder according to the report. As a result of this, we had to temporarily remove of sms_remainder column from the report, until we fix the bug - it has been fixed now, yay! I think the bug has snuck in partially because our fixtures for testing this part of the code are quite complex, so it was harder to see that numbers don't add up. I have added comments to the tests to try and make it a bit clearer why the results are as they are. I also added comments to the code, and renamed some variables, to make it easier to understand, as there are quite a few moving parts in it - subqueries and the like. I also renamed the fetch_sms_free_allowance_remainder method to fetch_sms_free_allowance_remainder_until_date so it is clearer what it does.
This commit is contained in:
@@ -831,7 +831,7 @@ def test_get_organisation_services_usage(admin_request, notify_db_session):
|
||||
assert service_usage['free_sms_limit'] == 10
|
||||
assert service_usage['letter_cost'] == 0
|
||||
assert service_usage['sms_billable_units'] == 19
|
||||
assert service_usage['sms_remainder'] == 10
|
||||
assert service_usage['sms_remainder'] == 0
|
||||
assert service_usage['sms_cost'] == 0.54
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user