Add letter status received to data model

- in order to reduce the number of statuses in the database the letter status `received` will be mapped to `delivered` internally
This commit is contained in:
Ken Tsang
2017-10-23 15:57:00 +01:00
parent adfc3b0801
commit a2b42194cd
2 changed files with 23 additions and 4 deletions

View File

@@ -876,6 +876,9 @@ NOTIFICATION_STATUS_TYPES_ENUM = db.Enum(*NOTIFICATION_STATUS_TYPES, name='notif
NOTIFICATION_STATUS_LETTER_ACCEPTED = 'accepted'
NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY = 'Accepted'
NOTIFICATION_STATUS_LETTER_RECEIVED = 'received'
DVLA_STATUS_SENT = 'Sent'
class NotificationStatusTypes(db.Model):
@@ -986,6 +989,14 @@ class Notification(db.Model):
['technical-failure', 'temporary-failure', 'permanent-failure', 'created', 'sending']
-
> IN
'delivered'
< OUT
['received']
:param status_or_statuses: a single status or list of statuses
:return: a single status or list with the current failure statuses substituted for 'failure'
"""
@@ -994,6 +1005,7 @@ class Notification(db.Model):
return (
NOTIFICATION_STATUS_TYPES_FAILED if _status == NOTIFICATION_FAILED else
[NOTIFICATION_CREATED, NOTIFICATION_SENDING] if _status == NOTIFICATION_STATUS_LETTER_ACCEPTED else
NOTIFICATION_DELIVERED if _status == NOTIFICATION_STATUS_LETTER_RECEIVED else
[_status]
)
@@ -1044,6 +1056,7 @@ class Notification(db.Model):
'technical-failure': 'Technical failure',
'sending': NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY,
'created': NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY,
'delivered': 'Received'
}
}[self.template.template_type].get(self.status, self.status)
@@ -1058,8 +1071,10 @@ class Notification(db.Model):
# get the two code flows mixed up at all
assert self.notification_type == LETTER_TYPE
if self.status == NOTIFICATION_CREATED or NOTIFICATION_SENDING:
if self.status in [NOTIFICATION_CREATED, NOTIFICATION_SENDING]:
return NOTIFICATION_STATUS_LETTER_ACCEPTED
elif self.status == NOTIFICATION_DELIVERED:
return NOTIFICATION_STATUS_LETTER_RECEIVED
else:
# Currently can only be technical-failure
return self.status