Skip to content

Commit

Permalink
New extend transport permit registration. Update search report home d… (
Browse files Browse the repository at this point in the history
#2031)

* New extend transport permit registration. Update search report home declared value.

Signed-off-by: Doug Lovett <[email protected]>

* New extend transport permit registration. Update search report

Signed-off-by: Doug Lovett <[email protected]>

* Fix NOC location report template type.

Signed-off-by: Doug Lovett <[email protected]>

* UXA REG_103E report update.

Signed-off-by: Doug Lovett <[email protected]>

* New extend transport permit registration. Update search report

Signed-off-by: Doug Lovett <[email protected]>

---------

Signed-off-by: Doug Lovett <[email protected]>
  • Loading branch information
doug-lovett authored Oct 8, 2024
1 parent f241654 commit 1ee37df
Show file tree
Hide file tree
Showing 20 changed files with 354 additions and 84 deletions.
2 changes: 1 addition & 1 deletion mhr_api/report-templates/adminRegistrationV2.html
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@
{% endif %}
</div>

<div class="section-title mt-5">{{ documentDescription }} Applicatant Name:</div>
<div class="section-title mt-5">{{ documentDescription }} Applicant Name:</div>
<div class="section-data pt-3">
{% if submittingParty.businessName is defined %}
{{ submittingParty.businessName }}
Expand Down
4 changes: 4 additions & 0 deletions mhr_api/report-templates/registrationCoverV2.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
<div class="cover-data"><span class="cover-data-bold">Transport Permit Number:</span>
{{ permitRegistrationNumber }}
</div>
{% elif extension is defined and extension and permitRegistrationNumber is defined %}
<div class="cover-data"><span class="cover-data-bold">Transport Permit Number:</span>
{{ permitRegistrationNumber }}
</div>
{% endif %}
<div class="cover-data"><span class="cover-data-bold">
{% if registrationType is defined and registrationType == 'PERMIT' %}Transport Permit Number:{% else %}Document Registration Number:{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@
<td>Home Registration Status:</td>
<td>{{detail.status|title}}</td>
</tr>
<tr>
<td>Declared Value:</td>
<td>
{% if detail.declaredValue is defined and detail.declaredValue != '' %}
{{detail.declaredValue}}
{% if detail.declaredDateTime is defined and detail.declaredDateTime != '' %} as of {{detail.declaredDateTime}}{% endif %}
{% else %}
N/A
{% endif %}
</td>
</tr>
{% if not detail.location.dealerName and detail.location.locationType != 'MANUFACTURER' %}
<tr>
<td>Declared Value:</td>
<td>
{% if detail.declaredValue is defined and detail.declaredValue != '' %}
{{detail.declaredValue}}
{% if detail.declaredDateTime is defined and detail.declaredDateTime != '' %} as of {{detail.declaredDateTime}}{% endif %}
{% else %}
N/A
{% endif %}
</td>
</tr>
{% endif %}
</table>
</div>

Expand Down
13 changes: 13 additions & 0 deletions mhr_api/report-templates/template-parts/v2/style.html
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,19 @@
background-color:#CBD5E0; /* #E2E7ED; */
}

.extended-label {
font-size: 7pt;
line-height: 13px !important;
font-family: 'BC Sans', sans-serif !important;
font-weight: bold;
color: #FFFFFF;
vertical-align: 15% !important;
padding: 3px 8px !important;
margin: 0px 3px 0px 0px !important;
border-radius: 4px;
background-color:#1669BB;
}

.tocpagenr {
float:right;
}
Expand Down
13 changes: 13 additions & 0 deletions mhr_api/report-templates/transportPermitV2.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
<td>Transport Permit Expiry Date:</td>
<td> {{permitExpiryDateTime}} </td>
</tr>
{% elif extension is defined and extension %}
<tr>
<td>Transport Permit Number:</td>
<td>{{permitRegistrationNumber}}</td>
</tr>
<tr>
<td>Transport Permit Date and Time of Issue:</td>
<td>{{permitDateTime}}</td>
</tr>
<tr>
<td>Transport Permit Expiry Date:</td>
<td> {{permitExpiryDateTime}} <span class="pl-1">&nbsp;</span><span class="extended-label">EXTENDED</span></td>
</tr>
{% else %}
<tr>
<td>Transport Permit Number:</td>
Expand Down
8 changes: 5 additions & 3 deletions mhr_api/src/mhr_api/models/batch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from mhr_registrations r, mhr_registration_reports rr, mhr_documents d
where r.id = rr.registration_id
and r.id = d.registration_id
and d.document_type in ('EXRE', 'REG_103', 'STAT', 'PUBA', 'REGC_STAFF', 'REGC_CLIENT', 'AMEND_PERMIT',
and d.document_type in ('EXRE', 'REG_103', 'REG_103E', 'STAT', 'PUBA', 'REGC_STAFF', 'REGC_CLIENT', 'AMEND_PERMIT',
'CANCEL_PERMIT')
and rr.batch_report_data is not null
and json_typeof(rr.batch_report_data) != 'null'
Expand All @@ -42,7 +42,7 @@
from mhr_registrations r, mhr_registration_reports rr, mhr_documents d
where r.id = rr.registration_id
and r.id = d.registration_id
and d.document_type in ('EXRE', 'REG_103', 'STAT', 'PUBA', 'REGC_STAFF', 'REGC_CLIENT', 'AMEND_PERMIT',
and d.document_type in ('EXRE', 'REG_103', 'REG_103E', 'STAT', 'PUBA', 'REGC_STAFF', 'REGC_CLIENT', 'AMEND_PERMIT',
'CANCEL_PERMIT')
and rr.batch_report_data is not null
and json_typeof(rr.batch_report_data) != 'null'
Expand Down Expand Up @@ -77,6 +77,7 @@
MhrDocumentTypes.ABAN.value,
MhrDocumentTypes.REG_101.value,
MhrDocumentTypes.REG_103.value,
MhrDocumentTypes.REG_103E.value,
MhrDocumentTypes.REGC_CLIENT.value,
MhrDocumentTypes.REGC_STAFF.value,
MhrDocumentTypes.AFFE.value,
Expand Down Expand Up @@ -156,6 +157,7 @@
PREVIOUS_LOCATION_DOC_TYPES = [
MhrDocumentTypes.EXRE.value,
MhrDocumentTypes.REG_103.value,
MhrDocumentTypes.REG_103E.value,
MhrDocumentTypes.AMEND_PERMIT.value,
MhrDocumentTypes.CANCEL_PERMIT.value,
MhrDocumentTypes.PUBA.value,
Expand Down Expand Up @@ -432,7 +434,7 @@ def get_batch_registration_data(start_ts: str = None, end_ts: str = None):
if start_ts and end_ts:
start: str = get_query_ts(start_ts)
end: str = get_query_ts(end_ts)
current_app.logger.debug(f'start={start} end={end}')
current_app.logger.debug(f'query parameters start={start} end={end}')
result = db.session.execute(query, {'query_val1': start, 'query_val2': end})
else:
result = db.session.execute(query)
Expand Down
60 changes: 15 additions & 45 deletions mhr_api/src/mhr_api/models/mhr_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from mhr_api.models import utils as model_utils, Db2Manuhome
from mhr_api.models.mhr_extra_registration import MhrExtraRegistration
from mhr_api.models.db2 import utils as legacy_utils
import mhr_api.models.registration_change_utils as change_utils
import mhr_api.models.registration_utils as reg_utils
import mhr_api.models.registration_json_utils as reg_json_utils
from mhr_api.services.authz import STAFF_ROLE
Expand All @@ -42,7 +43,6 @@
MhrPartyTypes,
MhrRegistrationTypes,
MhrRegistrationStatusTypes,
MhrStatusTypes,
MhrTenancyTypes
)

Expand Down Expand Up @@ -150,6 +150,8 @@ def json(self) -> dict:
reg_json = reg_json_utils.set_note_json(self, reg_json)
if doc_json.get('documentType') == MhrDocumentTypes.AMEND_PERMIT:
reg_json['amendment'] = True
elif doc_json.get('documentType') == MhrDocumentTypes.REG_103E:
reg_json['extension'] = True
elif self.is_transfer():
if doc_json.get('transferDate'):
reg_json['transferDate'] = doc_json.get('transferDate')
Expand Down Expand Up @@ -320,7 +322,7 @@ def save_exemption(self, new_reg_id: int):
self.status_type = MhrRegistrationStatusTypes.EXEMPT
if self.change_registrations: # Close out active transport permit without reverting location.
for reg in self.change_registrations:
if reg.notes and reg.notes[0].document_type in (MhrDocumentTypes.REG_103,
if reg.notes and reg.notes[0].document_type in (MhrDocumentTypes.REG_103, MhrDocumentTypes.REG_103E,
MhrDocumentTypes.AMEND_PERMIT) and \
reg.notes[0].status_type == MhrNoteStatusTypes.ACTIVE:
note: MhrNote = reg.notes[0]
Expand All @@ -333,46 +335,6 @@ def save_transfer(self, json_data, new_reg_id):
self.remove_groups(json_data, new_reg_id)
db.session.commit()

def save_permit(self, json_data, new_reg_id):
"""Update the existing location state to historical."""
if self.locations and self.locations[0].status_type == MhrStatusTypes.ACTIVE:
self.locations[0].status_type = MhrStatusTypes.HISTORICAL
self.locations[0].change_registration_id = new_reg_id
elif self.change_registrations:
for reg in self.change_registrations: # Updating a change registration location.
for existing in reg.locations:
if existing.status_type == MhrStatusTypes.ACTIVE and existing.registration_id != new_reg_id:
existing.status_type = MhrStatusTypes.HISTORICAL
existing.change_registration_id = new_reg_id
if reg.notes:
note: MhrNote = reg.notes[0]
if json_data.get('moveCompleted') and note.document_type == MhrDocumentTypes.REG_103 and \
note.status_type == MhrNoteStatusTypes.ACTIVE and not note.is_expired():
note.status_type = MhrNoteStatusTypes.COMPLETED
note.change_registration_id = new_reg_id
current_app.logger.debug(f'save_permit setting note status to completed reg id={new_reg_id}')
elif note.document_type in (MhrDocumentTypes.REG_103,
MhrDocumentTypes.REG_103E,
MhrDocumentTypes.AMEND_PERMIT) and \
note.status_type == MhrNoteStatusTypes.ACTIVE and not note.is_expired():
note.status_type = MhrNoteStatusTypes.CANCELLED
note.change_registration_id = new_reg_id
if json_data and json_data.get('documentType') == MhrDocumentTypes.CANCEL_PERMIT:
if self.status_type and self.status_type == MhrRegistrationStatusTypes.EXEMPT and \
json_data.get('location') and json_data['location']['address']['region'] == model_utils.PROVINCE_BC:
self.status_type = MhrRegistrationStatusTypes.ACTIVE
current_app.logger.info('Cancel Transport Permit new location in BC, updating EXEMPT status to ACTIVE.')
elif json_data and json_data.get('amendment') and \
self.status_type == MhrRegistrationStatusTypes.EXEMPT and \
json_data['newLocation']['address']['region'] == model_utils.PROVINCE_BC:
self.status_type = MhrRegistrationStatusTypes.ACTIVE
current_app.logger.info('Amend Transport Permit new location in BC, updating EXEMPT status to ACTIVE.')
elif json_data and json_data['newLocation']['address']['region'] != model_utils.PROVINCE_BC and \
json_data.get('documentType', '') != MhrDocumentTypes.CANCEL_PERMIT:
self.status_type = MhrRegistrationStatusTypes.EXEMPT
current_app.logger.info('Transport Permit new location out of province, updating status to EXEMPT.')
db.session.commit()

def is_transfer(self) -> bool:
"""Determine if the registration is one of the transfer types."""
return self.registration_type in (MhrRegistrationTypes.TRANS, MhrRegistrationTypes.TRAND,
Expand Down Expand Up @@ -791,6 +753,9 @@ def create_permit_from_json(base_reg,
json_data['registrationType'] = MhrRegistrationTypes.AMENDMENT
doc.document_type = MhrDocumentTypes.AMEND_PERMIT
registration.registration_type = MhrRegistrationTypes.AMENDMENT
elif json_data.get('extension'):
doc.document_type = MhrDocumentTypes.REG_103E
registration.registration_type = MhrRegistrationTypes.PERMIT_EXTENSION
# Save permit expiry date as a note.
note: MhrNote = MhrNote(registration_id=base_reg.id,
document_id=doc.id,
Expand All @@ -805,11 +770,16 @@ def create_permit_from_json(base_reg,
for reg in base_reg.change_registrations: # Updating a change registration location.
if reg.notes and reg.notes[0] and reg.notes[0].status_type == MhrNoteStatusTypes.ACTIVE and \
reg.notes[0].expiry_date and \
reg.notes[0].document_type in (MhrDocumentTypes.REG_103, MhrDocumentTypes.AMEND_PERMIT):
reg.notes[0].document_type in (MhrDocumentTypes.REG_103, MhrDocumentTypes.REG_103E,
MhrDocumentTypes.AMEND_PERMIT):
note.expiry_date = reg.notes[0].expiry_date
if doc.document_type == MhrDocumentTypes.REG_103E: # Same location with optional updated tax info.
change_utils.setup_permit_extension_location(base_reg, registration, json_data.get('newLocation'))
if account_id == STAFF_ROLE and json_data.get('note') and json_data['note'].get('remarks'):
note.remarks = json_data['note'].get('remarks')
else: # New location
registration.locations.append(MhrLocation.create_from_json(json_data.get('newLocation'), registration.id))
registration.notes = [note]
# New location
registration.locations.append(MhrLocation.create_from_json(json_data.get('newLocation'), registration.id))
if base_reg:
registration.manuhome = base_reg.manuhome
return registration
Expand Down
2 changes: 1 addition & 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,7 @@
FROM mhr_extra_registrations mer
WHERE mer.mhr_number = arv.mhr_number
AND mer.account_id = arv.account_id
AND (mer.removed_ind IS NULL OR mer.removed_ind != 'Y')) AS reg_count,
AND (mer.removed_ind IS NOT NULL AND mer.removed_ind = 'Y')) AS removed_count,
(SELECT COUNT(mer.id)
FROM mhr_extra_registrations mer
WHERE mer.mhr_number = arv.mhr_number
Expand Down
111 changes: 111 additions & 0 deletions mhr_api/src/mhr_api/models/registration_change_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Copyright © 2019 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=too-few-public-methods

"""This module holds additional methods to support registration model updates."""
from flask import current_app
from mhr_api.models import utils as model_utils
from mhr_api.models import (
MhrLocation
)
from mhr_api.models.db import db
from mhr_api.models.type_tables import (
MhrDocumentTypes,
MhrNoteStatusTypes,
MhrRegistrationStatusTypes,
MhrStatusTypes
)


def save_exemption(registration, new_reg_id: int):
"""Set the state of the original MH registration to exempt."""
registration.status_type = MhrRegistrationStatusTypes.EXEMPT
if registration.change_registrations: # Close out active transport permit without reverting location.
for reg in registration.change_registrations:
if reg.notes and reg.notes[0].document_type in (MhrDocumentTypes.REG_103, MhrDocumentTypes.REG_103E,
MhrDocumentTypes.AMEND_PERMIT) and \
reg.notes[0].status_type == MhrNoteStatusTypes.ACTIVE:
note = reg.notes[0]
note.status_type = MhrNoteStatusTypes.CANCELLED
note.change_registration_id = new_reg_id
db.session.commit()


def save_transfer(registration, json_data, new_reg_id):
"""Update the original MH removed owner groups."""
registration.remove_groups(json_data, new_reg_id)
db.session.commit()


def save_permit(registration, json_data, new_reg_id):
"""Update the existing location state to historical."""
if registration.locations and registration.locations[0].status_type == MhrStatusTypes.ACTIVE:
registration.locations[0].status_type = MhrStatusTypes.HISTORICAL
registration.locations[0].change_registration_id = new_reg_id
elif registration.change_registrations:
for reg in registration.change_registrations: # Updating a change registration location.
for existing in reg.locations:
if existing.status_type == MhrStatusTypes.ACTIVE and existing.registration_id != new_reg_id:
existing.status_type = MhrStatusTypes.HISTORICAL
existing.change_registration_id = new_reg_id
if reg.notes:
note = reg.notes[0]
if json_data.get('moveCompleted') and note.document_type == MhrDocumentTypes.REG_103 and \
note.status_type == MhrNoteStatusTypes.ACTIVE and not note.is_expired():
note.status_type = MhrNoteStatusTypes.COMPLETED
note.change_registration_id = new_reg_id
current_app.logger.debug(f'save_permit setting note status to completed reg id={new_reg_id}')
elif note.document_type in (MhrDocumentTypes.REG_103,
MhrDocumentTypes.REG_103E,
MhrDocumentTypes.AMEND_PERMIT) and \
note.status_type == MhrNoteStatusTypes.ACTIVE and not note.is_expired():
note.status_type = MhrNoteStatusTypes.CANCELLED
note.change_registration_id = new_reg_id
if json_data and json_data.get('documentType') == MhrDocumentTypes.CANCEL_PERMIT:
if registration.status_type and registration.status_type == MhrRegistrationStatusTypes.EXEMPT and \
json_data.get('location') and json_data['location']['address']['region'] == model_utils.PROVINCE_BC:
registration.status_type = MhrRegistrationStatusTypes.ACTIVE
current_app.logger.info('Cancel Transport Permit new location in BC, updating EXEMPT status to ACTIVE.')
elif json_data and json_data.get('amendment') and \
registration.status_type == MhrRegistrationStatusTypes.EXEMPT and \
json_data['newLocation']['address']['region'] == model_utils.PROVINCE_BC:
registration.status_type = MhrRegistrationStatusTypes.ACTIVE
current_app.logger.info('Amend Transport Permit new location in BC, updating EXEMPT status to ACTIVE.')
elif json_data and json_data['newLocation']['address']['region'] != model_utils.PROVINCE_BC and \
json_data.get('documentType', '') != MhrDocumentTypes.CANCEL_PERMIT:
registration.status_type = MhrRegistrationStatusTypes.EXEMPT
current_app.logger.info('Transport Permit new location out of province, updating status to EXEMPT.')
db.session.commit()


def setup_permit_extension_location(base_reg, registration, new_loc_json: dict):
"""REG_103E location does not change so clone the active location."""
if not base_reg.change_registrations:
return
current_app.logger.info('Permit extension looking up existing location.')
for reg in base_reg.change_registrations:
if reg.locations and reg.locations[0].status_type == MhrStatusTypes.ACTIVE:
current_loc = reg.locations[0]
location: MhrLocation = MhrLocation.create_from_json(current_loc.json, registration.id)
location.registration_id = registration.id
location.change_registration_id = registration.id
current_app.logger.info('Permit extension cloned existing location.')
if new_loc_json:
if 'taxCertificate' in new_loc_json:
location.tax_certification = 'Y' if new_loc_json.get('taxCertificate') else 'N'
if new_loc_json.get('taxExpiryDate', None):
location.tax_certification_date = model_utils.ts_from_iso_format(new_loc_json.get('taxExpiryDate'))
registration.locations.append(location)
break
3 changes: 2 additions & 1 deletion mhr_api/src/mhr_api/models/registration_json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def set_permit_json(registration, reg_json: dict) -> dict: # pylint: disable=to
permit_ts = reg.registration_ts
# current_app.logger.debug(f'set_permit # {permit_number}')
# Registrations are in chronological order: get the latest permit, use latest amendment status, expiry.
if reg.documents[0].document_type in (MhrDocumentTypes.REG_103, MhrDocumentTypes.AMEND_PERMIT):
if reg.documents[0].document_type in (MhrDocumentTypes.REG_103, MhrDocumentTypes.REG_103E,
MhrDocumentTypes.AMEND_PERMIT):
if reg.notes:
permit_status = reg.notes[0].status_type
expiry_ts = reg.notes[0].expiry_date
Expand Down
Loading

0 comments on commit 1ee37df

Please sign in to comment.