mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
This represents the number of chargeable_units that were actually free due to the free allowance - they won't be included in "cost". Although the existing calculations in Admin [^1][^2] will still be correct with a change in SMS rates - it's cost that's the problem - it makes sense to have all the knowledge about calculating usage consistently in these two APIs. Note that the Integer casting is covered by the API-level tests in test_rest. [^1]:474d7dfda8/app/main/views/dashboard.py (L490)[^2]:c63660d56d/app/main/views/dashboard.py (L350)
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from datetime import datetime
|
|
|
|
create_or_update_free_sms_fragment_limit_schema = {
|
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
"description": "POST annual billing schema",
|
|
"type": "object",
|
|
"title": "Create",
|
|
"properties": {
|
|
"free_sms_fragment_limit": {"type": "integer", "minimum": 0},
|
|
},
|
|
"required": ["free_sms_fragment_limit"]
|
|
}
|
|
|
|
|
|
def serialize_ft_billing_remove_emails(rows):
|
|
return [
|
|
{
|
|
"month": (datetime.strftime(row.month, "%B")),
|
|
"notification_type": row.notification_type,
|
|
# TEMPORARY: while we migrate away from "billing_units"
|
|
"billing_units": row.billable_units,
|
|
"chargeable_units": row.chargeable_units,
|
|
"notifications_sent": row.notifications_sent,
|
|
"rate": float(row.rate),
|
|
"postage": row.postage,
|
|
"cost": float(row.cost),
|
|
"free_allowance_used": row.free_allowance_used,
|
|
}
|
|
for row in rows
|
|
if row.notification_type != 'email'
|
|
]
|
|
|
|
|
|
def serialize_ft_billing_yearly_totals(rows):
|
|
return [
|
|
{
|
|
"notification_type": row.notification_type,
|
|
# TEMPORARY: while we migrate away from "billing_units"
|
|
"billing_units": row.billable_units,
|
|
"chargeable_units": row.chargeable_units,
|
|
"notifications_sent": row.notifications_sent,
|
|
"rate": float(row.rate),
|
|
# TEMPORARY: while we migrate to "cost" in the Admin app
|
|
"letter_total": float(row.billable_units * row.rate) if row.notification_type == 'letter' else 0,
|
|
"cost": float(row.cost),
|
|
"free_allowance_used": row.free_allowance_used,
|
|
}
|
|
for row in rows
|
|
]
|