Merge pull request #1241 from alphagov/letter-received

Letters are accepted, not created or sending
This commit is contained in:
Leo Hemsted
2017-09-20 16:51:31 +01:00
committed by GitHub
7 changed files with 110 additions and 40 deletions

View File

@@ -1,3 +1,4 @@
import itertools
import time
import uuid
import datetime
@@ -797,6 +798,9 @@ NOTIFICATION_STATUS_TYPES_NON_BILLABLE = list(set(NOTIFICATION_STATUS_TYPES) - s
NOTIFICATION_STATUS_TYPES_ENUM = db.Enum(*NOTIFICATION_STATUS_TYPES, name='notify_status_type')
NOTIFICATION_STATUS_LETTER_ACCEPTED = 'accepted'
NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY = 'Accepted'
class NotificationStatusTypes(db.Model):
__tablename__ = 'notification_status_types'
@@ -900,10 +904,10 @@ class Notification(db.Model):
-
> IN
['failed', 'created']
['failed', 'created', 'accepted']
< OUT
['technical-failure', 'temporary-failure', 'permanent-failure', 'created']
['technical-failure', 'temporary-failure', 'permanent-failure', 'created', 'sending']
:param status_or_statuses: a single status or list of statuses
@@ -911,18 +915,17 @@ class Notification(db.Model):
"""
def _substitute_status_str(_status):
return NOTIFICATION_STATUS_TYPES_FAILED if _status == NOTIFICATION_FAILED else _status
return (
NOTIFICATION_STATUS_TYPES_FAILED if _status == NOTIFICATION_FAILED else
[NOTIFICATION_CREATED, NOTIFICATION_SENDING] if _status == NOTIFICATION_STATUS_LETTER_ACCEPTED else
[_status]
)
def _substitute_status_seq(_statuses):
if NOTIFICATION_FAILED in _statuses:
_statuses = list(set(
NOTIFICATION_STATUS_TYPES_FAILED + [_s for _s in _statuses if _s != NOTIFICATION_FAILED]
))
return _statuses
return list(set(itertools.chain.from_iterable(_substitute_status_str(status) for status in _statuses)))
if isinstance(status_or_statuses, str):
return _substitute_status_str(status_or_statuses)
return _substitute_status_seq(status_or_statuses)
@property
@@ -962,17 +965,29 @@ class Notification(db.Model):
'sent': 'Sent internationally'
},
'letter': {
'failed': 'Failed',
'technical-failure': 'Technical failure',
'temporary-failure': 'Temporary failure',
'permanent-failure': 'Permanent failure',
'delivered': 'Delivered',
'sending': 'Sending',
'created': 'Sending',
'sent': 'Delivered'
'sending': NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY,
'created': NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY,
}
}[self.template.template_type].get(self.status, self.status)
def get_letter_status(self):
"""
Return the notification_status, as we should present for letters. The distinction between created and sending is
a bit more confusing for letters, not to mention that there's no concept of temporary or permanent failure yet.
"""
# this should only ever be called for letter notifications - it makes no sense otherwise and I'd rather not
# get the two code flows mixed up at all
assert self.notification_type == LETTER_TYPE
if self.status == NOTIFICATION_CREATED or NOTIFICATION_SENDING:
return NOTIFICATION_STATUS_LETTER_ACCEPTED
else:
# Currently can only be technical-failure
return status
def serialize_for_csv(self):
created_at_in_bst = convert_utc_to_bst(self.created_at)
serialized = {
@@ -1007,7 +1022,7 @@ class Notification(db.Model):
"line_6": None,
"postcode": None,
"type": self.notification_type,
"status": self.status,
"status": self.get_letter_status() if self.notification_type == LETTER_TYPE else self.status,
"template": template_dict,
"body": self.content,
"subject": self.subject,