2018-05-08 12:09:29 +01:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
2017-10-24 13:23:24 +01:00
|
|
|
create_or_update_free_sms_fragment_limit_schema = {
|
2022-04-08 17:05:59 +01:00
|
|
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
2017-10-24 13:23:24 +01:00
|
|
|
"description": "POST annual billing schema",
|
|
|
|
|
"type": "object",
|
|
|
|
|
"title": "Create",
|
|
|
|
|
"properties": {
|
2022-02-25 12:01:20 +00:00
|
|
|
"free_sms_fragment_limit": {"type": "integer", "minimum": 0},
|
2017-10-24 13:23:24 +01:00
|
|
|
},
|
2017-11-02 12:19:17 +00:00
|
|
|
"required": ["free_sms_fragment_limit"]
|
2017-10-24 13:23:24 +01:00
|
|
|
}
|
2018-05-08 12:09:29 +01:00
|
|
|
|
|
|
|
|
|
2022-04-20 18:00:30 +01:00
|
|
|
def serialize_ft_billing_remove_emails(rows):
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
"month": (datetime.strftime(row.month, "%B")),
|
|
|
|
|
"notification_type": row.notification_type,
|
2022-04-20 16:55:38 +01:00
|
|
|
# TEMPORARY: while we migrate away from "billing_units"
|
2022-04-20 18:00:30 +01:00
|
|
|
"billing_units": row.billable_units,
|
2022-04-20 16:55:38 +01:00
|
|
|
"chargeable_units": row.chargeable_units,
|
|
|
|
|
"notifications_sent": row.notifications_sent,
|
2022-04-20 18:00:30 +01:00
|
|
|
"rate": float(row.rate),
|
|
|
|
|
"postage": row.postage,
|
2018-05-08 12:09:29 +01:00
|
|
|
}
|
2022-04-20 18:00:30 +01:00
|
|
|
for row in rows
|
|
|
|
|
if row.notification_type != 'email'
|
|
|
|
|
]
|
2018-05-11 16:25:16 +01:00
|
|
|
|
|
|
|
|
|
2022-04-20 18:00:30 +01:00
|
|
|
def serialize_ft_billing_yearly_totals(rows):
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
"notification_type": row.notification_type,
|
2022-04-20 16:55:38 +01:00
|
|
|
# TEMPORARY: while we migrate away from "billing_units"
|
2022-04-20 18:00:30 +01:00
|
|
|
"billing_units": row.billable_units,
|
2022-04-20 16:55:38 +01:00
|
|
|
"chargeable_units": row.chargeable_units,
|
|
|
|
|
"notifications_sent": row.notifications_sent,
|
2022-04-20 18:00:30 +01:00
|
|
|
"rate": float(row.rate),
|
|
|
|
|
"letter_total": float(row.billable_units * row.rate) if row.notification_type == 'letter' else 0,
|
2018-05-11 16:25:16 +01:00
|
|
|
}
|
2022-04-20 18:00:30 +01:00
|
|
|
for row in rows
|
|
|
|
|
]
|