mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Merge pull request #2338 from alphagov/expected-letter-rate
1st class expected letter delivery
This commit is contained in:
@@ -12,6 +12,7 @@ from flask import (
|
||||
url_for,
|
||||
)
|
||||
from flask_login import current_user, login_required
|
||||
from notifications_utils.letter_timings import get_letter_timings
|
||||
from notifications_utils.template import Template, WithSubjectTemplate
|
||||
|
||||
from app import (
|
||||
@@ -28,7 +29,6 @@ from app.utils import (
|
||||
generate_next_dict,
|
||||
generate_notifications_csv,
|
||||
generate_previous_dict,
|
||||
get_letter_timings,
|
||||
get_page_from_request,
|
||||
get_time_left,
|
||||
parse_filter_args,
|
||||
@@ -380,10 +380,16 @@ def get_job_partials(job, template):
|
||||
)
|
||||
|
||||
if template['template_type'] == 'letter':
|
||||
# there might be no notifications if the job has only just been created and the tasks haven't run yet
|
||||
if notifications['notifications']:
|
||||
postage = notifications['notifications'][0]['postage']
|
||||
else:
|
||||
postage = current_service.postage
|
||||
|
||||
counts = render_template(
|
||||
'partials/jobs/count-letters.html',
|
||||
total=job.get('notification_count', 0),
|
||||
delivery_estimate=get_letter_timings(job['created_at']).earliest_delivery,
|
||||
delivery_estimate=get_letter_timings(job['created_at'], postage=postage).earliest_delivery,
|
||||
)
|
||||
else:
|
||||
counts = render_template(
|
||||
|
||||
@@ -16,6 +16,7 @@ from flask import (
|
||||
)
|
||||
from flask_login import login_required
|
||||
from notifications_python_client.errors import APIError
|
||||
from notifications_utils.letter_timings import get_letter_timings
|
||||
from notifications_utils.pdf import pdf_page_count
|
||||
|
||||
from app import (
|
||||
@@ -33,7 +34,6 @@ from app.utils import (
|
||||
FAILURE_STATUSES,
|
||||
generate_notifications_csv,
|
||||
get_help_argument,
|
||||
get_letter_timings,
|
||||
get_template,
|
||||
parse_filter_args,
|
||||
set_status_filters,
|
||||
@@ -90,7 +90,10 @@ def view_notification(service_id, notification_id):
|
||||
created_by=notification.get('created_by'),
|
||||
created_at=notification['created_at'],
|
||||
help=get_help_argument(),
|
||||
estimated_letter_delivery_date=get_letter_timings(notification['created_at']).earliest_delivery,
|
||||
estimated_letter_delivery_date=get_letter_timings(
|
||||
notification['created_at'],
|
||||
postage=notification['postage']
|
||||
).earliest_delivery,
|
||||
notification_id=notification['id'],
|
||||
postage=notification['postage'],
|
||||
can_receive_inbound=(current_service.has_permission('inbound_sms')),
|
||||
|
||||
32
app/utils.py
32
app/utils.py
@@ -2,7 +2,6 @@ import csv
|
||||
import os
|
||||
import re
|
||||
import unicodedata
|
||||
from collections import namedtuple
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from functools import wraps
|
||||
from io import StringIO
|
||||
@@ -356,37 +355,6 @@ def email_or_sms_not_enabled(template_type, permissions):
|
||||
return (template_type in ['email', 'sms']) and (template_type not in permissions)
|
||||
|
||||
|
||||
def get_letter_timings(upload_time):
|
||||
|
||||
LetterTimings = namedtuple(
|
||||
'LetterTimings',
|
||||
'printed_by, is_printed, earliest_delivery, latest_delivery'
|
||||
)
|
||||
|
||||
# shift anything after 5pm to the next day
|
||||
processing_day = gmt_timezones(upload_time) + timedelta(hours=(7))
|
||||
|
||||
print_day, earliest_delivery, latest_delivery = (
|
||||
processing_day + timedelta(days=days)
|
||||
for days in {
|
||||
'Wednesday': (1, 3, 5),
|
||||
'Thursday': (1, 4, 5),
|
||||
'Friday': (3, 5, 6),
|
||||
'Saturday': (2, 4, 5),
|
||||
}.get(processing_day.strftime('%A'), (1, 3, 4))
|
||||
)
|
||||
|
||||
printed_by = print_day.astimezone(pytz.timezone('Europe/London')).replace(hour=15, minute=0)
|
||||
now = datetime.utcnow().replace(tzinfo=pytz.timezone('Europe/London'))
|
||||
|
||||
return LetterTimings(
|
||||
printed_by=printed_by,
|
||||
is_printed=(now > printed_by),
|
||||
earliest_delivery=earliest_delivery,
|
||||
latest_delivery=latest_delivery,
|
||||
)
|
||||
|
||||
|
||||
def gmt_timezones(date):
|
||||
date = dateutil.parser.parse(date)
|
||||
forced_utc = date.replace(tzinfo=pytz.utc)
|
||||
|
||||
Reference in New Issue
Block a user