Return delivery estimate for letter notifications

> For get all or get one letter the response needs to be updated so that
> it looks similar to admin app.
>
> status: created|sending --> received letter
> new column: `estimated delivery date`: derived from created at date.
> (see how the admin app is doing it)
>
> NOTE:
> At the moment we only have 2 statuses for a letter created and
> sending, but we will want to have other internal statuses that make
> sense to the Notify team but not our services. When we know those
> statuses the status map will be updated at that point.

– https://www.pivotaltracker.com/story/show/150512525

This commit implements the date (not status) part of this story.
This commit is contained in:
Chris Hill-Scott
2017-09-11 14:16:04 +01:00
parent 0029a0cc0f
commit 29a962060f
3 changed files with 38 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ from notifications_utils.recipients import (
InvalidPhoneError,
InvalidEmailError
)
from notifications_utils.letter_timings import get_letter_timings
from app.encryption import (
hashpw,
@@ -1029,6 +1030,10 @@ class Notification(db.Model):
serialized['line_5'] = self.personalisation.get('address_line_5')
serialized['line_6'] = self.personalisation.get('address_line_6')
serialized['postcode'] = self.personalisation['postcode']
serialized['estimated_delivery'] = \
get_letter_timings(serialized['created_at'])\
.earliest_delivery\
.strftime(DATETIME_FORMAT)
return serialized