mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
At the moment we’re not consistent: Precompiled (API and one-off): `to` has the whole address `normalised_to` has nothing Templated (API, CSV and one off): `to` has the first line of the address `normalised_to` has nothing This commit makes us consistently store the whole address in the `to` field. We think that people might want to search by postcode, not just first line of the address. This commit also starts to populate the normalised_to field with the address lowercased and with all spaces removed, to make it easier to search on.
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
from notifications_utils.postal_address import PostalAddress
|
|
|
|
from app import create_random_identifier
|
|
from app.models import LETTER_TYPE
|
|
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):
|
|
notification = persist_notification(
|
|
template_id=template.id,
|
|
template_version=template.version,
|
|
template_postage=template.postage,
|
|
# we only accept addresses_with_underscores from the API (from CSV we also accept dashes, spaces etc)
|
|
recipient=PostalAddress.from_personalisation(letter_data['personalisation']).normalised,
|
|
service=template.service,
|
|
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,
|
|
reference=create_random_identifier(),
|
|
client_reference=letter_data.get('reference'),
|
|
status=status,
|
|
reply_to_text=reply_to_text,
|
|
billable_units=billable_units,
|
|
postage=letter_data.get('postage')
|
|
)
|
|
return notification
|