Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit note updates from review. #1582

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions mhr_api/report-templates/template-parts/search-result/notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,9 @@
{% endif %}
</td>
</tr>
<tr>
<td class="section-sub-title">Phone:</td>
<td>{% 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 %}
</td>
</tr>
{% endif %}
</table>
</div>
{% if not loop.last %}
<div class="separator mt-4 mb-1"></div>
{% endif %}
<div class="separator mt-4 mb-1"></div>
{% endfor %}
{% endif %}
2 changes: 1 addition & 1 deletion mhr_api/src/mhr_api/models/db2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mhr_api/src/mhr_api/models/registration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mhr_api/src/mhr_api/reports/v2/report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Expand Down
14 changes: 9 additions & 5 deletions mhr_api/src/mhr_api/resources/v1/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions mhr_api/src/mhr_api/services/payment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
1 change: 1 addition & 0 deletions mhr_api/src/mhr_api/services/payment/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
24 changes: 24 additions & 0 deletions mhr_api/tests/unit/api/test_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion mhr_api/tests/unit/services/test_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down