Skip to content

Commit

Permalink
Merge branch 'main' into fix/no-certification-checkbox-error-mhr-info
Browse files Browse the repository at this point in the history
  • Loading branch information
RuoxuanPengBC authored Oct 16, 2023
2 parents 0225a45 + cf73b1d commit f6a9620
Show file tree
Hide file tree
Showing 74 changed files with 2,914 additions and 682 deletions.
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 %}
7 changes: 6 additions & 1 deletion mhr_api/src/database/postgres_views/mhr_account_reg_vw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ SELECT r.mhr_number, r.status_type, r.registration_ts,
r.id AS registration_id,
(SELECT mrr.doc_storage_url
FROM mhr_registration_reports mrr
WHERE mrr.registration_id = r.id) AS doc_storage_url
WHERE mrr.registration_id = r.id) AS doc_storage_url,
(SELECT l.location_type
FROM mhr_locations l, mhr_registrations r2
WHERE r2.mhr_number = r.mhr_number
AND r2.id = l.registration_id
AND l.status_type = 'ACTIVE') AS location_type
FROM mhr_registrations r, mhr_documents d, mhr_document_types dt
WHERE r.id = d.registration_id
AND d.document_type = dt.document_type
Expand Down
50 changes: 43 additions & 7 deletions mhr_api/src/mhr_api/models/db2/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,19 @@
WHERE n.manhomid = mh.manhomid AND n.status = 'A'
AND (n.docutype IN ('TAXN', 'NCON', 'REST') OR
(n.docutype IN ('103 ', '103E') AND n.expiryda IS NOT NULL AND n.expiryda > current date))
FETCH FIRST 1 ROWS ONLY) AS frozen_doc_type
FROM manuhome mh, document d
FETCH FIRST 1 ROWS ONLY) AS frozen_doc_type,
CASE
WHEN trim(l.mhdealer) != '' THEN 'MANUFACTURER'
WHEN trim(l.mahpname) != '' THEN 'MH_PARK'
WHEN trim(l.adddesc) != '' AND
(l.adddesc LIKE '%BAND%' OR l.adddesc LIKE '%INDIAN%' OR l.adddesc LIKE '%RESERVE%') THEN 'RESERVE'
ELSE 'OTHER'
END location_type
FROM manuhome mh, document d, location l
WHERE mh.mhregnum = :query_mhr_number
AND mh.mhregnum = d.mhregnum
AND mh.manhomid = l.manhomid
AND l.status = 'A'
"""
QUERY_ACCOUNT_ADD_REGISTRATION_DOC = """
SELECT mh.mhregnum, mh.mhstatus, d.regidate, TRIM(d.name), TRIM(d.olbcfoli), TRIM(d.docutype),
Expand Down Expand Up @@ -196,11 +205,20 @@
WHERE n.manhomid = mh.manhomid AND n.status = 'A'
AND (n.docutype IN ('TAXN', 'NCON', 'REST') OR
(n.docutype IN ('103 ', '103E') AND n.expiryda IS NOT NULL AND n.expiryda > current date))
FETCH FIRST 1 ROWS ONLY) AS frozen_doc_type
FROM manuhome mh, document d, document d2
FETCH FIRST 1 ROWS ONLY) AS frozen_doc_type,
CASE
WHEN trim(l.mhdealer) != '' THEN 'MANUFACTURER'
WHEN trim(l.mahpname) != '' THEN 'MH_PARK'
WHEN trim(l.adddesc) != '' AND
(l.adddesc LIKE '%BAND%' OR l.adddesc LIKE '%INDIAN%' OR l.adddesc LIKE '%RESERVE%') THEN 'RESERVE'
ELSE 'OTHER'
END location_type
FROM manuhome mh, document d, document d2, location l
WHERE d2.docuregi = :query_value
AND d2.mhregnum = mh.mhregnum
AND mh.mhregnum = d.mhregnum
AND mh.manhomid = l.manhomid
AND l.status = 'A'
"""
QUERY_ACCOUNT_REGISTRATIONS = """
SELECT mh.mhregnum, mh.mhstatus, d.regidate, TRIM(d.name), TRIM(d.olbcfoli), TRIM(d.docutype),
Expand Down Expand Up @@ -239,10 +257,19 @@
WHERE n.manhomid = mh.manhomid AND n.status = 'A'
AND (n.docutype IN ('TAXN', 'NCON', 'REST') OR
(n.docutype IN ('103 ', '103E') AND n.expiryda IS NOT NULL AND n.expiryda > current date))
FETCH FIRST 1 ROWS ONLY) AS frozen_doc_type
FROM manuhome mh, document d
FETCH FIRST 1 ROWS ONLY) AS frozen_doc_type,
CASE
WHEN trim(l.mhdealer) != '' THEN 'MANUFACTURER'
WHEN trim(l.mahpname) != '' THEN 'MH_PARK'
WHEN trim(l.adddesc) != '' AND
(l.adddesc LIKE '%BAND%' OR l.adddesc LIKE '%INDIAN%' OR l.adddesc LIKE '%RESERVE%') THEN 'RESERVE'
ELSE 'OTHER'
END location_type
FROM manuhome mh, document d, location l
WHERE mh.mhregnum IN (?)
AND mh.mhregnum = d.mhregnum
AND mh.manhomid = l.manhomid
AND l.status = 'A'
ORDER BY d.regidate DESC
"""
QUERY_ACCOUNT_REGISTRATIONS_SORT = """
Expand Down Expand Up @@ -283,16 +310,25 @@
AND (n.docutype IN ('TAXN', 'NCON', 'REST') OR
(n.docutype IN ('103 ', '103E') AND n.expiryda IS NOT NULL AND n.expiryda > current date))
FETCH FIRST 1 ROWS ONLY) AS frozen_doc_type,
CASE
WHEN trim(l.mhdealer) != '' THEN 'MANUFACTURER'
WHEN trim(l.mahpname) != '' THEN 'MH_PARK'
WHEN trim(l.adddesc) != '' AND
(l.adddesc LIKE '%BAND%' OR l.adddesc LIKE '%INDIAN%' OR l.adddesc LIKE '%RESERVE%') THEN 'RESERVE'
ELSE 'OTHER'
END location_type,
(SELECT TRIM(o2.ownrname)
FROM owner o2, owngroup og2
WHERE o2.manhomid = mh.manhomid
AND og2.manhomid = mh.manhomid
AND og2.owngrpid = o2.owngrpid
AND og2.regdocid = d.documtid
FETCH FIRST 1 ROWS ONLY) as owner_name_sort
FROM manuhome mh, document d
FROM manuhome mh, document d, location l
WHERE mh.mhregnum IN (?)
AND mh.mhregnum = d.mhregnum
AND mh.manhomid = l.manhomid
AND l.status = 'A'
"""
PERMIT_COUNT_QUERY = """
SELECT COUNT(documtid)
Expand Down
5 changes: 3 additions & 2 deletions mhr_api/src/mhr_api/models/db2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@ def __build_summary(row, add_in_user_list: bool = True, mhr_list=None):
'path': '',
'documentId': str(row[8]),
'documentRegistrationNumber': str(row[9]),
'documentType': str(row[5])
'documentType': str(row[5]),
'locationType': str(row[15])
}
if add_in_user_list:
summary['inUserList'] = False
Expand Down Expand Up @@ -816,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
3 changes: 2 additions & 1 deletion mhr_api/src/mhr_api/models/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
WHERE mer.mhr_number = arv.mhr_number
AND mer.account_id = :query_value1
AND mer.account_id != arv.account_id
AND (mer.removed_ind IS NULL OR mer.removed_ind != 'Y')) AS extra_reg_count
AND (mer.removed_ind IS NULL OR mer.removed_ind != 'Y')) AS extra_reg_count,
location_type
FROM mhr_account_reg_vw arv
"""
QUERY_ACCOUNT_ADD_REG_MHR = QUERY_ACCOUNT_REG_BASE + """
Expand Down
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -745,7 +745,8 @@ def __build_summary(row, account_id: str, staff: bool, add_in_user_list: bool =
'path': '',
'documentId': str(row[8]),
'documentRegistrationNumber': str(row[9]),
'registrationType': str(row[5])
'registrationType': str(row[5]),
'locationType': str(row[22])
}
if (staff or account_id == reg_account_id) and (doc_storage_url or model_utils.report_retry_elapsed(timestamp)):
if summary['registrationType'] in (MhrRegistrationTypes.MHREG, MhrRegistrationTypes.MHREG_CONVERSION):
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
2 changes: 1 addition & 1 deletion mhr_api/src/mhr_api/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '1.5.9' # pylint: disable=invalid-name
__version__ = '1.6.0' # pylint: disable=invalid-name
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
5 changes: 4 additions & 1 deletion mhr_api/tests/unit/models/test_mhr_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ def test_find_summary_by_mhr_number(session, account_id, mhr_num, exists, reg_de
assert registration['path'] is not None
assert registration['documentId'] is not None
assert registration['inUserList'] == in_list
assert registration.get('locationType')
else:
assert not registration

Expand All @@ -385,7 +386,7 @@ def test_find_summary_by_doc_reg_number(session, account_id, doc_reg_num, mhr_nu
"""Assert that finding summary MHR registration information by a document registration number works as expected."""
registration = MhrRegistration.find_summary_by_doc_reg_number(account_id, doc_reg_num)
if result_count > 0:
current_app.logger.info(registration)
# current_app.logger.info(registration)
assert registration['mhrNumber'] == mhr_num
assert registration['registrationType']
assert 'hasCaution' in registration
Expand All @@ -399,6 +400,7 @@ def test_find_summary_by_doc_reg_number(session, account_id, doc_reg_num, mhr_nu
assert registration['path'] is not None
assert registration['documentId'] is not None
assert registration['inUserList'] == in_list
assert registration.get('locationType')
if result_count == 1:
assert not registration.get('changes')
else:
Expand Down Expand Up @@ -436,6 +438,7 @@ def test_find_account_registrations(session, account_id, has_results):
assert not registration.get('inUserList')
if registration['registrationDescription'] == REG_DESCRIPTION:
assert 'lienRegistrationType' in registration
assert registration.get('locationType')
if registration.get('changes'):
for reg in registration.get('changes'):
desc: str = reg['registrationDescription']
Expand Down
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
Loading

0 comments on commit f6a9620

Please sign in to comment.