Add "cost" field to monthly usage API

This starts to replace the calculation in Admin [^1] and, similar
to the yearly API, also correctly attributes free allowance when
we have a rate change during a month.

[^1]: 474d7dfda8/app/templates/views/usage.html (L98)
This commit is contained in:
Ben Thorner
2022-04-21 11:29:43 +01:00
parent e276e8a15c
commit ff32000180
4 changed files with 16 additions and 0 deletions

View File

@@ -175,6 +175,7 @@ def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_se
assert letter_row["chargeable_units"] == 30
assert letter_row["rate"] == 0.33
assert letter_row["postage"] == "second"
assert letter_row["cost"] == 9.9
assert sms_row["month"] == "April"
assert sms_row["notification_type"] == "sms"
@@ -182,6 +183,8 @@ def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_se
assert sms_row["chargeable_units"] == 30
assert sms_row["rate"] == 0.162
assert sms_row["postage"] == "none"
# free allowance is 4, so (30 - 4) * 0.162
assert sms_row["cost"] == 4.212
def set_up_yearly_data():