Save the first non-empty line as recipient

Since we now allow the address to be populated from any three lines, we
can’t guarantee that the recipient will be in the `addressline1` field.
This commit is contained in:
Chris Hill-Scott
2020-04-04 17:31:24 +01:00
parent 7032bac178
commit 36e61272c5
2 changed files with 26 additions and 12 deletions

View File

@@ -3,6 +3,8 @@ from datetime import datetime
from collections import namedtuple, defaultdict
from flask import current_app
from notifications_utils.columns import Columns
from notifications_utils.postal_address import PostalAddress
from notifications_utils.recipients import RecipientCSV
from notifications_utils.statsd_decorators import statsd
from notifications_utils.timezones import convert_utc_to_bst
@@ -341,7 +343,9 @@ def save_letter(
notification = encryption.decrypt(encrypted_notification)
# we store the recipient as just the first item of the person's address
recipient = notification['personalisation']['addressline1']
recipient = PostalAddress.from_personalisation(
Columns(notification['personalisation'])
).normalised_lines[0]
service = dao_fetch_service_by_id(service_id)
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])