Save whole letter address into the to field

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.
This commit is contained in:
Chris Hill-Scott
2020-04-22 10:06:25 +01:00
parent 7897ae70ce
commit 9047b273da
4 changed files with 46 additions and 12 deletions

View File

@@ -1,3 +1,5 @@
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
@@ -9,7 +11,7 @@ def create_letter_notification(letter_data, template, api_key, status, reply_to_
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=letter_data['personalisation']['address_line_1'],
recipient=PostalAddress.from_personalisation(letter_data['personalisation']).normalised,
service=template.service,
personalisation=letter_data['personalisation'],
notification_type=LETTER_TYPE,