mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 16:01:15 -05:00
We were using the Draft4Validator in one place, so this updates it to the Draft7Validator instead. The schemas were mostly using draft 4 of the JSON schema, though there were a couple of schemas that were already of version 7. This updates them all to version 7, which is the latest version fully supported by the jsonschema Python package. There are some breaking changes in the newer version of the schema, but I could not see anywhere would these affect us. Some of these schemas were not valid in version 4, but are now valid in version 7 because `"required": []` was not valid in earlier versions.
42 lines
1.4 KiB
Python
42 lines
1.4 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(data):
|
|
results = []
|
|
billed_notifications = [x for x in data if x.notification_type != 'email']
|
|
for notification in billed_notifications:
|
|
json_result = {
|
|
"month": (datetime.strftime(notification.month, "%B")),
|
|
"notification_type": notification.notification_type,
|
|
"billing_units": notification.billable_units,
|
|
"rate": float(notification.rate),
|
|
"postage": notification.postage,
|
|
}
|
|
results.append(json_result)
|
|
return results
|
|
|
|
|
|
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
|