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 = {
|
|
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
|
"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
|
|
|
|
|
|
|
|
|
|
|
|
|
def serialize_ft_billing_remove_emails(data):
|
|
|
|
|
results = []
|
|
|
|
|
billed_notifications = [x for x in data if x.notification_type != 'email']
|
2018-05-16 12:21:59 +01:00
|
|
|
for notification in billed_notifications:
|
2018-05-08 12:09:29 +01:00
|
|
|
json_result = {
|
2018-05-16 12:21:59 +01:00
|
|
|
"month": (datetime.strftime(notification.month, "%B")),
|
|
|
|
|
"notification_type": notification.notification_type,
|
|
|
|
|
"billing_units": notification.billable_units,
|
|
|
|
|
"rate": float(notification.rate),
|
2018-09-27 13:58:01 +01:00
|
|
|
"postage": notification.postage,
|
2018-05-08 12:09:29 +01:00
|
|
|
}
|
|
|
|
|
results.append(json_result)
|
|
|
|
|
return results
|
2018-05-11 16:25:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def serialize_ft_billing_yearly_totals(data):
|
|
|
|
|
yearly_totals = []
|
|
|
|
|
for total in data:
|
|
|
|
|
json_result = {
|
|
|
|
|
"notification_type": total.notification_type,
|
|
|
|
|
"billing_units": total.billable_units,
|
|
|
|
|
"rate": float(total.rate),
|
|
|
|
|
"letter_total": float(total.billable_units * total.rate) if total.notification_type == 'letter' else 0
|
|
|
|
|
}
|
|
|
|
|
yearly_totals.append(json_result)
|
|
|
|
|
|
|
|
|
|
return yearly_totals
|