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

Transport permit report template and generation setup. #1607

Merged
merged 3 commits into from
Oct 30, 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
11 changes: 7 additions & 4 deletions mhr_api/report-templates/registrationCoverV2.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,19 @@
{{ documentDescription }}
{% endif %}
</div>
<div class="cover-data"><span class="cover-data-bold">Document Registration Number:</span>
<div class="cover-data"><span class="cover-data-bold">
{% if registrationType is defined and registrationType == 'PERMIT' %}Transport Permit Number:{% else %}Document Registration Number:{% endif %}
</span>
{% if documentRegistrationNumber is defined and documentRegistrationNumber != '' %}
{{ documentRegistrationNumber }}
{% elif note is defined and note.documentRegistrationNumber is defined and note.documentRegistrationNumber != '' %}
{{ note.documentRegistrationNumber }}
{% else %}
N/A
{% endif %}
</div>
<div class="cover-data"><span class="cover-data-bold">Document Registration Date and Time:</span> {{ createDateTime }}</div>
<div class="cover-data"><span class="cover-data-bold">
{% if registrationType is defined and registrationType == 'PERMIT' %}Date of Issue:{% else %}Document Registration Date and Time:{% endif %}
</span> {{ createDateTime }}
</div>
<div class="cover-data mt-4"><span class="cover-data-bold">Toll-Free Phone:</span> 1-877-526-1526</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% if location is defined %}
<div class="no-page-break">
{% if registrationType not in ('EXEMPTION_RES', 'EXEMPTION_NON_RES') %}
{% if registrationType == 'PERMIT' %}
<div class="section-title mt-5">New Registered Location</div>
{% elif registrationType not in ('EXEMPTION_RES', 'EXEMPTION_NON_RES') %}
<div class="separator mt-5"></div>
<div class="section-title mt-3">Registered Location</div>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% if submittingParty is defined %}
<div class="no-page-break">
{% if not (registrationType == 'EXEMPTION_RES' and usergroup is defined and usergroup != 'ppr_staff') %}
<div class="separator mt-5"></div>
{% if registrationType != 'PERMIT' %}
<div class="separator mt-5"></div>
{% endif %}
{% endif %}
<div class="section-title mt-3">Submitting Party Information</div>
<table class="section-data section-data-table-new mt-4" role="presentation">
Expand Down
15 changes: 15 additions & 0 deletions mhr_api/report-templates/template-parts/v2/style.html
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,21 @@
padding-right: 25px;
}

.section-data-table-base {
width: 100%;
border-collapse: collapse;
}

.section-data-table-base td {
vertical-align: top;
overflow-wrap: break-word;
word-wrap: break-word;
}

.section-data-table-base td:nth-child(1) {
padding-left: 8px;
}

.cover-data-table {
width: 100%;
margin: 0px;
Expand Down
88 changes: 57 additions & 31 deletions mhr_api/report-templates/transportPermitV2.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
<td>{{status|title}}</td>
</tr>
<tr>
<td>Document Registration Number:</td>
<td>Transport Permit Number:</td>
<td>{{documentRegistrationNumber}}</td>
</tr>
<tr>
<td>Document Registration Date and Time:</td>
<td>Date of Issue:</td>
<td>{{createDateTime}}</td>
</tr>
<tr>
<td>Expiry Date:</td>
<td>{% if note is defined and note.expiryDateTime is defined %} {{note.expiryDateTime}} {% endif %}</td>
</tr>
<tr>
<td>Folio Number:</td>
<td>
Expand All @@ -42,39 +46,61 @@
</div>

<div class="container pt-4">
<div class="section-data mt-1">
Under section 17 of the Manufactured Home Act, the Registrar hereby permits the movement of the manufactured home registered
under {{mhrNumber}} with Serial Number(s)
{% if description is defined and description.sections is defined %}
{% for section in description.sections %}{{section.serialNumber}}{% if not loop.last %}, {% endif %}{% endfor %}
{% endif %}
to:
</div>

[[registration/location.html]]

{% if note is defined %}
<div class="no-page-break">
<div class="separator-header mt-6"></div>
<div class="section-title-centre mt-2">UNIT NOTE</div>
<div class="separator-header mt-0"></div>
</div>
<table class="no-page-break section-data details-table mt-4" role="presentation">
<tr>
<td class="section-sub-title">Expired Date:</td>
<td>{% if note.expiryDate is defined and note.expiryDate != '' %}
{{note.expiryDate}}
{% else %}
N/A
{% endif %}
</td>
</tr>
<tr>
<td class="section-sub-title">Remarks:</td>
<td>
{% if note.remarks is defined and note.remarks != '' %}
{{note.remarks}}
{% else %}
N/A
{% endif %}
</td>
</tr>
</table>

{% endif %}
<div class="separator mt-5"></div>
<div class="section-title mt-5">Transport Permit Conditions</div>
<table class="no-page-break section-data section-data-table-base mt-2" role="presentation">
<tr>
<td>1.</td>
<td class="pl-2">
<div>If the manufactured home is permanently placed on a location other than specifically described on the transport permit,
the owner must advise the Registrar and provide full details of the location either</div>
<div>(a) within 3 days after the manufactured home was transported to the new location</div>
<div>or</div>
<div>(b) within 3 days after the expiration of the transport permit which ever occurs first.</div>
</td>
</tr>
<tr>
<td class="pt-2">2.</td>
<td class="pl-2 pt-2">
This permit expires 30 days after the date of issue. If the manufactured home is NOT MOVED within this time,
you must report the physical location of the manufactured home within 3 days after the expiration of the permit.
</td>
</tr>
<tr>
<td class="pt-2">3.</td>
<td class="pl-2 pt-2">
This permit may be used for one (1) move only. A new permit must be obtained for subsequent moves.
</td>
</tr>
<tr>
<td class="pt-2">4.</td>
<td class="pl-2 pt-2">
Upon leaving British Columbia, this home is Exempted from the Manufactured Home Act. The home is required to be
re-registered under the same number if it re-enters the Province of British Columbia.
</td>
</tr>
</table>

[[registration/submittingParty.html]]

<div class="separator mt-5"></div>

{% if status == 'EXEMPT' %}
<div class="section-data mt-5">
Upon leaving British Columbia, this home is Exempted from the Manufactured Home Act. The home is required to be re-registered under the same number if it re-enters the Province of British Columbia.
</div>
{% endif %}
</div>
<p class="last-page"></p>
</body>
Expand Down
4 changes: 4 additions & 0 deletions mhr_api/src/mhr_api/models/db2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ def __build_summary(row, add_in_user_list: bool = True, mhr_list=None):
summary = __get_cancel_info(summary, row)
elif summary['documentType'] in (MhrDocumentTypes.CAU, MhrDocumentTypes.CAUC, MhrDocumentTypes.CAUE):
summary = __get_caution_info(summary, row)
elif summary['documentType'] in (Db2Document.DocumentTypes.PERMIT,
Db2Document.DocumentTypes.PERMIT_TRIM) and row[12]:
expiry = row[12]
summary['expireDays'] = model_utils.expiry_date_days(expiry)
summary = __set_frozen_status(summary, row)
return summary

Expand Down
3 changes: 3 additions & 0 deletions mhr_api/src/mhr_api/models/registration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,9 @@ def __build_summary(row, account_id: str, staff: bool, add_in_user_list: bool =
summary = __get_cancel_info(summary, row)
elif doc_type in (MhrDocumentTypes.CAU, MhrDocumentTypes.CAUC, MhrDocumentTypes.CAUE):
summary = __get_caution_info(summary, row, doc_type)
elif doc_type == MhrDocumentTypes.REG_103 and row[12]:
expiry = row[12]
summary['expireDays'] = model_utils.expiry_date_days(expiry.date())
summary = __set_frozen_status(summary, row, staff)
return summary

Expand Down
7 changes: 4 additions & 3 deletions mhr_api/src/mhr_api/reports/v2/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def get_registration_staff_pdf(self):
elif self._report_data.get('registrationType', '') in (MhrRegistrationTypes.EXEMPTION_RES,
MhrRegistrationTypes.EXEMPTION_NON_RES):
self._report_key = ReportTypes.MHR_EXEMPTION
elif self._report_data.get('registrationType', '') == MhrRegistrationTypes.PERMIT:
self._report_key = ReportTypes.MHR_TRANSPORT_PERMIT
elif self._report_data.get('registrationType', '') == MhrRegistrationTypes.REG_NOTE:
if self._report_data.get('documentType'):
self._report_key = ReportTypes.MHR_ADMIN_REGISTRATION
Expand Down Expand Up @@ -390,8 +392,7 @@ def _get_template_data(self):
self._set_addresses()
self._set_owner_groups()
if self._report_key not in (ReportTypes.MHR_REGISTRATION,
ReportTypes.MHR_TRANSFER,
ReportTypes.MHR_TRANSPORT_PERMIT):
ReportTypes.MHR_TRANSFER):
self._set_notes()
if self._report_key == ReportTypes.SEARCH_DETAIL_REPORT:
self._set_selected()
Expand Down Expand Up @@ -568,7 +569,7 @@ def _set_search_additional_message(self):
message = {
'messageType': note.get('documentType'),
'messageId': note.get('documentRegistrationNumber', ''),
'messageDate': Report._to_report_datetime(note['createDateTime'], False)
'messageDate': Report._to_report_datetime(note['createDateTime'], True)
}
messages.append(message)
if not has_exempt_note and detail.get('status') == 'EXEMPT':
Expand Down
30 changes: 19 additions & 11 deletions mhr_api/src/mhr_api/resources/v1/permits.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from http import HTTPStatus

from flask import Blueprint
from flask import current_app, request, jsonify
from flask import current_app, request, jsonify, g
from flask_cors import cross_origin
from registry_schemas import utils as schema_utils

Expand Down Expand Up @@ -70,25 +70,24 @@ def post_permits(mhr_number: str): # pylint: disable=too-many-return-statements
return resource_utils.validation_error_response(errors, reg_utils.VAL_ERROR, extra_validation_msg)
# Set up the registration, pay, and save the data.
# current_app.logger.debug(f'Pay and save transport permit request for {mhr_number}')
group: str = get_group(jwt)
registration = reg_utils.pay_and_save_permit(request,
current_reg,
request_json,
account_id,
get_group(jwt),
group,
TransactionTypes.TRANSPORT_PERMIT)
current_app.logger.debug(f'building transport permit response json for {mhr_number}')
response_json = registration.json
if request_json.get('owner'):
response_json['owner'] = request_json.get('owner')
if request_json.get('existingLocation'):
response_json['existingLocation'] = request_json.get('existingLocation')
# Return report if request header Accept MIME type is application/pdf.
if resource_utils.is_pdf(request):
current_app.logger.info('Report not yet available: returning JSON.')
# Report data include all active owners.
setup_report(registration, response_json)
# Add current description for reporting
current_reg.current_view = True
current_json = current_reg.new_registration_json
response_json['description'] = current_json.get('description')
setup_report(registration, response_json, group, jwt)
return jsonify(response_json), HTTPStatus.CREATED

except DatabaseException as db_exception:
return resource_utils.db_exception_response(db_exception, account_id,
'POST mhr registration id=' + account_id)
Expand All @@ -100,6 +99,15 @@ def post_permits(mhr_number: str): # pylint: disable=too-many-return-statements
return resource_utils.default_exception_response(default_exception)


def setup_report(registration: MhrRegistration, response_json):
def setup_report(registration: MhrRegistration, response_json, group: str, j_token):
"""Perform all extra set up of the transfer report request data and add it to the queue."""
reg_utils.enqueue_registration_report(registration, response_json, ReportTypes.MHR_TRANSPORT_PERMIT)
response_json['usergroup'] = group
if is_staff(j_token):
response_json['username'] = reg_utils.get_affirmby(g.jwt_oidc_token_info)
reg_utils.enqueue_registration_report(registration, response_json, ReportTypes.MHR_REGISTRATION_STAFF)
del response_json['username']
else:
if not response_json.get('affirmbyName'):
response_json['affirmByName'] = reg_utils.get_affirmby(g.jwt_oidc_token_info)
reg_utils.enqueue_registration_report(registration, response_json, ReportTypes.MHR_TRANSPORT_PERMIT)
del response_json['usergroup']
2 changes: 2 additions & 0 deletions mhr_api/tests/unit/api/test_permits.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def test_create(session, client, jwt, desc, mhr_num, roles, status, account):
else:
assert response.status_code == status
if response.status_code == HTTPStatus.CREATED:
resp_json = response.json
assert resp_json.get('description')
registration: MhrRegistration = MhrRegistration.find_by_mhr_number(response.json['mhrNumber'],
account)
assert registration
2 changes: 2 additions & 0 deletions mhr_api/tests/unit/models/db2/test_db2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ def test_find_account_registrations(session, account_id, has_results):
desc: str = reg['registrationDescription']
if reg.get('registrationType') == MhrRegistrationTypes.REG_NOTE and desc.find('CAUTION') > 0:
assert reg.get('expireDays')
elif reg.get('registrationType') == MhrRegistrationTypes.PERMIT:
assert reg.get('expireDays')
else:
assert not reg_list

Expand Down
2 changes: 2 additions & 0 deletions mhr_api/tests/unit/models/test_mhr_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ def test_find_account_registrations(session, account_id, has_results):
desc: str = reg['registrationDescription']
if reg.get('registrationType') == MhrRegistrationTypes.REG_NOTE and desc.find('CAUTION') > 0:
assert reg.get('expireDays')
elif reg.get('registrationType') == MhrRegistrationTypes.PERMIT:
assert reg.get('expireDays')
else:
assert not reg_list

Expand Down