Refactor and harmonise metadata for invalid letters with those sent from admin app

This commit is contained in:
Pea Tyczynska
2019-10-16 13:35:30 +01:00
parent 0b65e75fe9
commit 6ee7ac6cac
4 changed files with 51 additions and 48 deletions

View File

@@ -1,9 +1,13 @@
import boto3
import io
import json
import math
from app.models import KEY_TYPE_TEST, SECOND_CLASS, RESOLVE_POSTAGE_FOR_FILE_NAME, NOTIFICATION_VALIDATION_FAILED
from datetime import datetime, timedelta
from enum import Enum
import boto3
from flask import current_app
from notifications_utils.letter_timings import LETTER_PROCESSING_DEADLINE
@@ -11,8 +15,6 @@ from notifications_utils.pdf import pdf_page_count
from notifications_utils.s3 import s3upload
from notifications_utils.timezones import convert_utc_to_bst
from app.models import KEY_TYPE_TEST, SECOND_CLASS, RESOLVE_POSTAGE_FOR_FILE_NAME, NOTIFICATION_VALIDATION_FAILED
class ScanErrorType(Enum):
ERROR = 1
@@ -130,9 +132,9 @@ def move_error_pdf_to_scan_bucket(source_filename):
def move_scan_to_invalid_pdf_bucket(source_filename, message=None, invalid_pages=None, page_count=None):
metadata = {}
if message:
metadata["validation_failed_message"] = message
metadata["message"] = message
if invalid_pages:
metadata["invalid_pages"] = "-".join(map(str, invalid_pages))
metadata["invalid_pages"] = json.dumps(invalid_pages)
if page_count:
metadata["page_count"] = str(page_count)
@@ -228,7 +230,12 @@ def letter_print_day(created_at):
def get_page_count(pdf):
pages = pdf_page_count(io.BytesIO(pdf))
return pdf_page_count(io.BytesIO(pdf))
def get_billable_units_for_letter_page_count(page_count):
if not page_count:
return 0
pages_per_sheet = 2
billable_units = math.ceil(pages / pages_per_sheet)
billable_units = math.ceil(page_count / pages_per_sheet)
return billable_units