Files
notifications-api/app/notifications/process_letter_notifications.py
T

28 lines
1.1 KiB
Python
Raw Normal View History

2017-07-26 15:57:30 +01:00
from app import create_random_identifier
2017-09-26 09:56:09 +01:00
from app.models import LETTER_TYPE
2017-07-26 15:57:30 +01:00
from app.notifications.process_notifications import persist_notification
def create_letter_notification(letter_data, template, api_key, status, reply_to_text=None, billable_units=None):
2017-07-26 15:57:30 +01:00
notification = persist_notification(
template_id=template.id,
template_version=template.version,
template_postage=template.postage,
2017-07-27 11:10:22 +01:00
# we only accept addresses_with_underscores from the API (from CSV we also accept dashes, spaces etc)
recipient=letter_data['personalisation']['address_line_1'],
2017-09-26 09:56:09 +01:00
service=template.service,
2017-07-26 15:57:30 +01:00
personalisation=letter_data['personalisation'],
notification_type=LETTER_TYPE,
api_key_id=api_key.id,
key_type=api_key.key_type,
job_id=None,
job_row_number=None,
2017-07-26 15:57:30 +01:00
reference=create_random_identifier(),
2017-09-26 09:56:09 +01:00
client_reference=letter_data.get('reference'),
status=status,
reply_to_text=reply_to_text,
billable_units=billable_units,
postage=letter_data.get('postage')
2017-07-26 15:57:30 +01:00
)
return notification