From a761459a568cd4bd48c1f57aade4ff4639e668d5 Mon Sep 17 00:00:00 2001 From: Doug Lovett Date: Fri, 13 Oct 2023 10:26:49 -0700 Subject: [PATCH] Unit note updates from review. Signed-off-by: Doug Lovett --- .../template-parts/search-result/notes.html | 15 +----------- mhr_api/src/mhr_api/models/db2/utils.py | 2 +- .../src/mhr_api/models/registration_utils.py | 2 +- .../src/mhr_api/reports/v2/report_utils.py | 2 ++ mhr_api/src/mhr_api/resources/v1/notes.py | 14 +++++++---- .../src/mhr_api/services/payment/__init__.py | 1 + .../services/payment/client/__init__.py | 1 + mhr_api/tests/unit/api/test_notes.py | 24 +++++++++++++++++++ mhr_api/tests/unit/services/test_payment.py | 3 ++- 9 files changed, 42 insertions(+), 22 deletions(-) diff --git a/mhr_api/report-templates/template-parts/search-result/notes.html b/mhr_api/report-templates/template-parts/search-result/notes.html index da0d9f30a..5e10eb361 100755 --- a/mhr_api/report-templates/template-parts/search-result/notes.html +++ b/mhr_api/report-templates/template-parts/search-result/notes.html @@ -106,22 +106,9 @@ {% endif %} - - Phone: - {% if note.contactPhoneNumber is defined and note.contactPhoneNumber != '' %} - {{note.contactPhoneNumber}} - {% elif note.givingNoticeParty is defined and note.givingNoticeParty.phoneNumber is defined and note.givingNoticeParty.phoneNumber != '' %} - {{note.givingNoticeParty.phoneNumber}} - {% else %} - N/A - {% endif %} - - {% endif %} - {% if not loop.last %} -
- {% endif %} +
{% endfor %} {% endif %} diff --git a/mhr_api/src/mhr_api/models/db2/utils.py b/mhr_api/src/mhr_api/models/db2/utils.py index 20a717c7a..692cd3e6b 100755 --- a/mhr_api/src/mhr_api/models/db2/utils.py +++ b/mhr_api/src/mhr_api/models/db2/utils.py @@ -817,7 +817,7 @@ def get_search_json(registration): include: bool = True doc_type = note.get('documentType', '') current_app.logger.debug('updating doc type=' + doc_type) - if doc_type in ('103', '103E', 'STAT', 'EXRE'): # Always exclude + if doc_type in ('103', '103E', 'STAT', 'EXRE', 'NCAN'): # Always exclude include = False elif not registration.staff and doc_type in ('102', 'NCON'): # Always exclude for non-staff include = False diff --git a/mhr_api/src/mhr_api/models/registration_utils.py b/mhr_api/src/mhr_api/models/registration_utils.py index 9e3d28fb5..ed2a305f5 100644 --- a/mhr_api/src/mhr_api/models/registration_utils.py +++ b/mhr_api/src/mhr_api/models/registration_utils.py @@ -454,7 +454,7 @@ def update_notes_search_json(notes_json: dict, staff: bool) -> dict: for note in notes_json: include: bool = True doc_type = note.get('documentType', '') - if doc_type in ('REG_103', 'REG_103E', 'STAT', 'EXRE'): # Always exclude + if doc_type in ('REG_103', 'REG_103E', 'STAT', 'EXRE', 'NCAN'): # Always exclude include = False elif not staff and doc_type in ('REG_102', 'NCON'): # Always exclude for non-staff include = False diff --git a/mhr_api/src/mhr_api/reports/v2/report_utils.py b/mhr_api/src/mhr_api/reports/v2/report_utils.py index 1a819ba94..2f526aaf8 100755 --- a/mhr_api/src/mhr_api/reports/v2/report_utils.py +++ b/mhr_api/src/mhr_api/reports/v2/report_utils.py @@ -310,6 +310,8 @@ def get_report_files(request_data: dict, report_type: str, mail: bool = False) - title_text = request_data['templateVars'].get('meta_title', '') elif report_type == ReportTypes.MHR_NOTE: title_text = str(request_data['templateVars']['note'].get('documentDescription', '')).upper() + if title_text == 'CANCEL NOTE' and request_data['templateVars']['note'].get('cancelledDocumentDescription'): + title_text += ' (' + request_data['templateVars']['note'].get('cancelledDocumentDescription') + ')' else: title_text = str(request_data['templateVars'].get('documentDescription', '')).upper() subtitle_text = request_data['templateVars'].get('meta_subtitle', '') diff --git a/mhr_api/src/mhr_api/resources/v1/notes.py b/mhr_api/src/mhr_api/resources/v1/notes.py index 7ed756ec0..7149d6141 100644 --- a/mhr_api/src/mhr_api/resources/v1/notes.py +++ b/mhr_api/src/mhr_api/resources/v1/notes.py @@ -112,10 +112,14 @@ def post_notes(mhr_number: str): # pylint: disable=too-many-return-statements,t def get_transaction_type(request_json) -> str: - """Try and obtain an optional boolean parameter value from the request parameters.""" + """Derive the payment transaction type from unit note document type.""" tran_type: str = TransactionTypes.UNIT_NOTE - if request_json.get('note') and request_json['note'].get('documentType', '') == MhrDocumentTypes.TAXN: - tran_type = TransactionTypes.UNIT_NOTE_TAXN - elif request_json.get('note') and request_json['note'].get('documentType', '') == MhrDocumentTypes.REG_102: - tran_type = TransactionTypes.UNIT_NOTE_102 + if request_json.get('note') and request_json['note'].get('documentType', ''): + doc_type: str = request_json['note'].get('documentType') + if doc_type == MhrDocumentTypes.TAXN: + tran_type = TransactionTypes.UNIT_NOTE_TAXN + elif doc_type == MhrDocumentTypes.REG_102: + tran_type = TransactionTypes.UNIT_NOTE_102 + elif doc_type in (MhrDocumentTypes.REST, MhrDocumentTypes.NPUB, MhrDocumentTypes.NCON): + tran_type = TransactionTypes.UNIT_NOTE_OTHER return tran_type diff --git a/mhr_api/src/mhr_api/services/payment/__init__.py b/mhr_api/src/mhr_api/services/payment/__init__.py index d7a97e56f..16b4c4300 100644 --- a/mhr_api/src/mhr_api/services/payment/__init__.py +++ b/mhr_api/src/mhr_api/services/payment/__init__.py @@ -34,3 +34,4 @@ class TransactionTypes(str, Enum): UNIT_NOTE_TAXN = 'UNIT_NOTE_TAXN' UNIT_NOTE_102 = 'UNIT_NOTE_102' DECAL_REPLACE = 'DECAL_REPLACE' + UNIT_NOTE_OTHER = 'UNIT_NOTE_OTHER' diff --git a/mhr_api/src/mhr_api/services/payment/client/__init__.py b/mhr_api/src/mhr_api/services/payment/client/__init__.py index b3d76d480..8d1f2403f 100644 --- a/mhr_api/src/mhr_api/services/payment/client/__init__.py +++ b/mhr_api/src/mhr_api/services/payment/client/__init__.py @@ -44,6 +44,7 @@ 'TRANSPORT_PERMIT_EXT': 'TRAPP', 'UNIT_NOTE': 'CCONT', 'UNIT_NOTE_TAXN': 'TXSNT', + 'UNIT_NOTE_OTHER': 'MHROT', 'UNIT_NOTE_102': 'MHDEC', 'DECAL_REPLACE': 'MHDEC' } diff --git a/mhr_api/tests/unit/api/test_notes.py b/mhr_api/tests/unit/api/test_notes.py index 673c54313..ce4de39fd 100644 --- a/mhr_api/tests/unit/api/test_notes.py +++ b/mhr_api/tests/unit/api/test_notes.py @@ -23,7 +23,9 @@ from flask import current_app from mhr_api.models import MhrRegistration +from mhr_api.resources.v1.notes import get_transaction_type from mhr_api.services.authz import MHR_ROLE, STAFF_ROLE, COLIN_ROLE, TRANSFER_DEATH_JT +from mhr_api.services.payment import TransactionTypes from tests.unit.services.utils import create_header, create_header_account @@ -80,6 +82,18 @@ ('Valid missing note remarks', '000900', [MHR_ROLE, STAFF_ROLE], HTTPStatus.CREATED, 'PS12345'), ('Valid staff', '000900', [MHR_ROLE, STAFF_ROLE], HTTPStatus.CREATED, 'PS12345') ] +# testdata pattern is ({doc_type}, {transaction_type}) +TEST_TRANSACTION_DATA = [ + ('CAU', TransactionTypes.UNIT_NOTE), + ('CAUC', TransactionTypes.UNIT_NOTE), + ('CAUE', TransactionTypes.UNIT_NOTE), + ('NCAN', TransactionTypes.UNIT_NOTE), + ('REG_102', TransactionTypes.UNIT_NOTE_102), + ('TAXN', TransactionTypes.UNIT_NOTE_TAXN), + ('NPUB', TransactionTypes.UNIT_NOTE_OTHER), + ('REST', TransactionTypes.UNIT_NOTE_OTHER), + ('NCON', TransactionTypes.UNIT_NOTE_OTHER) +] @pytest.mark.parametrize('desc,mhr_num,roles,status,account', TEST_CREATE_DATA) @@ -139,3 +153,13 @@ def test_create(session, client, jwt, desc, mhr_num, roles, status, account): assert notice_json['address']['region'] assert notice_json['address']['country'] assert notice_json['address']['postalCode'] is not None + + +@pytest.mark.parametrize('doc_type,trans_type', TEST_TRANSACTION_DATA) +def test_get_transaction_type(session, client, jwt, doc_type, trans_type): + """Assert that the document type to payment transaction type mapping works as expected.""" + # setup + json_data = copy.deepcopy(NOTE_REGISTRATION) + json_data['note']['documentType'] = doc_type + transaction_type: str = get_transaction_type(json_data) + assert transaction_type == trans_type diff --git a/mhr_api/tests/unit/services/test_payment.py b/mhr_api/tests/unit/services/test_payment.py index acb7032a4..5d8f1247b 100644 --- a/mhr_api/tests/unit/services/test_payment.py +++ b/mhr_api/tests/unit/services/test_payment.py @@ -144,7 +144,8 @@ ('MHR Transport Permit Extension', TransactionTypes.TRANSPORT_PERMIT_EXT, '1234', 'UT-00001', 1), ('MHR Decal Replacement', TransactionTypes.DECAL_REPLACE, '1234', 'UT-00001', 1), ('MHR Unit Note 102', TransactionTypes.UNIT_NOTE_102, '1234', 'UT-00001', 1), - ('MHR Unit Note TAXN', TransactionTypes.UNIT_NOTE_TAXN, '1234', 'UT-00001', 1) + ('MHR Unit Note TAXN', TransactionTypes.UNIT_NOTE_TAXN, '1234', 'UT-00001', 1), + ('MHR Unit Note Other', TransactionTypes.UNIT_NOTE_OTHER, '1234', 'UT-00001', 1) ] # testdata pattern is ({type}, {trans_id}, {client_id}, {routingSlip}, {bcolNum}, {datNum}, {waiveFees}, {priority}) TEST_PAYMENT_DATA_STAFF = [