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
|
|
|
|
|
|
|
|
|
|
|
2018-09-20 14:47:24 +01:00
|
|
|
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(
|
2017-09-20 11:12:37 +01:00
|
|
|
template_id=template.id,
|
|
|
|
|
template_version=template.version,
|
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,
|
2017-09-20 11:12:37 +01:00
|
|
|
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'),
|
2017-11-24 16:17:25 +00:00
|
|
|
status=status,
|
2018-09-20 14:47:24 +01:00
|
|
|
reply_to_text=reply_to_text,
|
2019-01-09 17:49:19 +00:00
|
|
|
billable_units=billable_units,
|
|
|
|
|
postage=letter_data.get('postage')
|
2017-07-26 15:57:30 +01:00
|
|
|
)
|
|
|
|
|
return notification
|