Choose postage when persisting a notification

This commit is contained in:
Pea Tyczynska
2018-12-17 17:49:51 +00:00
parent 19f7678b05
commit e6524af89c
4 changed files with 51 additions and 4 deletions

View File

@@ -23,7 +23,8 @@ from app.models import (
LETTER_TYPE,
NOTIFICATION_CREATED,
Notification,
ScheduledNotification
ScheduledNotification,
CHOOSE_POSTAGE
)
from app.dao.notifications_dao import (
dao_create_notification,
@@ -31,6 +32,8 @@ from app.dao.notifications_dao import (
dao_created_scheduled_notification
)
from app.dao.templates_dao import dao_get_template_by_id
from app.v2.errors import BadRequestError
from app.utils import (
cache_key_for_service_template_counter,
@@ -109,7 +112,11 @@ def persist_notification(
elif notification_type == EMAIL_TYPE:
notification.normalised_to = format_email_address(notification.to)
elif notification_type == LETTER_TYPE:
notification.postage = service.postage
template = dao_get_template_by_id(template_id, template_version)
if service.has_permission(CHOOSE_POSTAGE) and template.postage:
notification.postage = template.postage
else:
notification.postage = service.postage
# if simulated create a Notification model to return but do not persist the Notification to the dB
if not simulated: