Skip to content

Commit

Permalink
MHR api amend transport permit changes. (bcgov#1669)
Browse files Browse the repository at this point in the history
* MHR api amend transport permit changes.

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

* MHR api amend transport permit changes.

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

---------

Signed-off-by: Doug Lovett <[email protected]>
  • Loading branch information
doug-lovett authored Dec 22, 2023
1 parent 1178d42 commit 22cc5f3
Show file tree
Hide file tree
Showing 18 changed files with 464 additions and 75 deletions.
4 changes: 4 additions & 0 deletions mhr_api/report-templates/registrationCoverV2.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
<div class="cover-data"><span class="cover-data-bold">Transport Permit Number:</span>
{{ note.cancelledDocumentRegistrationNumber }}
</div>
{% elif amendment is defined and amendment 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' %}Date of Issue:{% else %}Document Registration Date and Time:{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<div class="section-title mt-5">New Registered Location as shown on the permit or amended location:</div>
{% elif registrationType in ('PERMIT', 'REG_STAFF_ADMIN') and (documentType is not defined or documentType != 'CANCEL_PERMIT') %}
<div class="section-title mt-5">New Registered Location</div>
{% elif amendment is defined and amendment %}
<div class="separator mt-5"></div>
<div class="section-title mt-5">New Registered Location</div>
{% elif registrationType not in ('EXEMPTION_RES', 'EXEMPTION_NON_RES') %}
{% if documentType is not defined or documentType != 'CANCEL_PERMIT' %}
<div class="separator mt-5"></div>
Expand Down
72 changes: 56 additions & 16 deletions mhr_api/report-templates/transportPermitV2.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,33 @@
<td>Home Registration Status:</td>
<td>{% if status == 'FROZEN' %} Active {% else %} {{status|title}} {% endif %}</td>
</tr>
<tr>
<td>Transport Permit Number:</td>
<td>{{documentRegistrationNumber}}</td>
</tr>
<tr>
<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>
{% if amendment is defined and amendment %}
<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>Permit Expiry Date:</td>
<td> {{permitExpiryDateTime}} </td>
</tr>
{% else %}
<tr>
<td>Transport Permit Number:</td>
<td>{{documentRegistrationNumber}}</td>
</tr>
<tr>
<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>
{% endif %}
<tr>
<td>Folio Number:</td>
<td>
Expand All @@ -46,6 +61,15 @@
</div>

<div class="container pt-4">

{% if amendment is defined and amendment %}
<div class="section-title mt-1">Amendment Information</div>
<div class="section-data mt-3">
Transport permit {{permitRegistrationNumber}} was amended under document registration number
{{documentRegistrationNumber}} on {{createDateTime}}.
</div>
<div class="separator mt-5 mb-4"></div>
{% endif %}
<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)
Expand All @@ -59,7 +83,7 @@

<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">
<table class="section-data section-data-table-base mt-2" role="presentation">
<tr>
<td>1.</td>
<td class="pl-2">
Expand Down Expand Up @@ -97,9 +121,25 @@
<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>
{% if amendment is defined and amendment and location.address.region != 'BC' %}
<div class="section-data mt-5">
The registry now records this manufactured home as moving to the location outside of British Columbia (BC) specified
in the permit. Upon leaving BC, this home is exempt from the Manufactured Home Act. If it re-enters BC, the home must be
re-registered under the same manufactured home registation number.
</div>
<div class="section-data mt-5">
Please note, if either of the following occurs, you must register the updated location of this home with the registrar
within 3 days of whichever occurs first:
<ul>
<li>The home moves to a different location other than what is stated in this permit; or</li>
<li>The home is not moved before this permit expires.</li>
</ul>
</div>
{% else %}
<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 %}
{% endif %}
</div>
<p class="last-page"></p>
Expand Down
12 changes: 10 additions & 2 deletions mhr_api/src/mhr_api/models/db2/manuhome.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,16 @@ def create_from_permit(registration, reg_json):
note: Db2Mhomnote = Db2Mhomnote.create_from_registration(note_json, doc, manuhome.id)
if doc_type == Db2Document.DocumentTypes.CORRECTION:
note.document_type = Db2Document.DocumentTypes.PERMIT # Match legacy registration behaviour.
# Use the original expiry date.
note.expiry_date = model_utils.date_offset(manuhome.update_date, 30, True)
permit_ts = None
for existing_doc in manuhome.reg_documents:
if existing_doc.document_type in (Db2Document.DocumentTypes.PERMIT,
Db2Document.DocumentTypes.PERMIT_TRIM) and \
(not permit_ts or permit_ts < existing_doc.registration_ts):
for existing_note in manuhome.reg_notes:
if existing_doc.id == existing_note.reg_document_id:
note.expiry_date = existing_note.expiry_date # Use the original expiry date.
else:
note.expiry_date = model_utils.date_offset(manuhome.update_date, 30, True)
manuhome.reg_notes.append(note)
# Update location:
manuhome.new_location = Db2Location.create_from_registration(registration, reg_json, True)
Expand Down
29 changes: 28 additions & 1 deletion mhr_api/src/mhr_api/models/db2/registration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)

from .document import Db2Document
from .mhomnote import Db2Mhomnote
from .mhomnote import Db2Mhomnote, FROM_LEGACY_STATUS
from .owngroup import Db2Owngroup


Expand Down Expand Up @@ -97,6 +97,33 @@ def update_description_json(registration, reg_json: dict) -> dict:
return reg_json


def set_permit_json(manuhome, reg_json: dict) -> dict:
"""Conditinally add the latest transport permit information if available."""
if not manuhome or not manuhome.current_view or not reg_json or not manuhome.reg_notes:
return reg_json
permit_number: str = None
permit_ts = None
expiry_dt = None
permit_status = None
for note in manuhome.reg_notes:
if note.document_type in (Db2Document.DocumentTypes.PERMIT, Db2Document.DocumentTypes.PERMIT_TRIM):
for doc in manuhome.reg_documents:
if doc.id == note.reg_document_id and doc.document_type in (Db2Document.DocumentTypes.PERMIT,
Db2Document.DocumentTypes.PERMIT_TRIM):
permit_status = FROM_LEGACY_STATUS.get(note.status)
expiry_dt = note.expiry_date
permit_number = doc.document_reg_id
permit_ts = doc.registration_ts
if permit_number:
reg_json['permitRegistrationNumber'] = permit_number
reg_json['permitDateTime'] = model_utils.format_local_ts(permit_ts)
reg_json['permitStatus'] = permit_status
if expiry_dt < model_utils.today_local().date():
reg_json['permitStatus'] = MhrNoteStatusTypes.EXPIRED
reg_json['permitExpiryDateTime'] = model_utils.format_local_date(expiry_dt)
return reg_json


def set_owner_sequence_num(owner_groups) -> int:
"""Get the next owner group sequence number."""
sequence_num: int = 1
Expand Down
3 changes: 2 additions & 1 deletion mhr_api/src/mhr_api/models/db2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def __update_summary_info(result, results, reg_summary_list, staff, account_id):
else:
result['registrationType'] = summary_result.get('registration_type')
if result['registrationType'] == MhrRegistrationTypes.REG_STAFF_ADMIN and summary_result.get('doc_description'):
result['registrationDescription'] = summary_result.get('doc_description')
result['registrationDescription'] = summary_result.get('doc_description')
elif result['registrationType'] == MhrRegistrationTypes.REG_NOTE:
doc_type = result.get('documentType')
if FROM_LEGACY_DOC_TYPE.get(doc_type):
Expand Down Expand Up @@ -886,6 +886,7 @@ def get_new_registration_json(registration):
note = legacy_reg_utils.update_note_json(registration, note)
elif reg_json.get('notes'): # Non BC Registries staff minimal information, same subset as search
reg_json['notes'] = get_non_staff_notes(reg_json)
reg_json = legacy_reg_utils.set_permit_json(registration.manuhome, reg_json)
current_app.logger.debug('Built JSON from DB2 and PostgreSQL')
return reg_json_utils.set_payment_json(registration, reg_json)

Expand Down
31 changes: 18 additions & 13 deletions mhr_api/src/mhr_api/models/mhr_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ def json(self) -> dict:
if doc_json.get('attentionReference'):
reg_json['attentionReference'] = doc_json.get('attentionReference')
reg_json = reg_json_utils.set_submitting_json(self, reg_json)
if self.registration_type in (MhrRegistrationTypes.PERMIT, MhrRegistrationTypes.PERMIT_EXTENSION):
if self.registration_type in (MhrRegistrationTypes.PERMIT, MhrRegistrationTypes.PERMIT_EXTENSION) or \
doc_json.get('documentType') == MhrDocumentTypes.AMEND_PERMIT:
reg_json = reg_json_utils.set_location_json(self, reg_json, False)
reg_json = reg_json_utils.set_note_json(self, reg_json)
if doc_json.get('documentType') == MhrDocumentTypes.AMEND_PERMIT:
reg_json['amendment'] = True
elif self.is_transfer():
reg_json['transferDate'] = doc_json.get('transferDate')
reg_json['consideration'] = doc_json.get('consideration')
Expand Down Expand Up @@ -191,17 +194,12 @@ def registration_json(self) -> dict:
reg_json = {
'mhrNumber': self.mhr_number,
'createDateTime': model_utils.format_ts(self.registration_ts),
# 'registrationType': self.registration_type,
'status': self.status_type,
# 'declaredValue': doc_json.get('declaredValue', 0),
# 'documentDescription': reg_utils.get_document_description(doc_json.get('documentType')),
'documentId': doc_json.get('documentId'),
# 'documentRegistrationNumber': doc_json.get('documentRegistrationNumber'),
'ownLand': doc_json.get('ownLand'),
'attentionReference': doc_json.get('attentionReference', ''),
'clientReferenceId': self.client_reference_id if self.client_reference_id else ''
}
# reg_json = reg_utils.set_declared_value_json(self, reg_json)
reg_json = reg_json_utils.set_submitting_json(self, reg_json)
reg_json = reg_json_utils.set_location_json(self, reg_json, self.current_view)
reg_json = reg_json_utils.set_description_json(self, reg_json, self.current_view)
Expand All @@ -211,7 +209,7 @@ def registration_json(self) -> dict:
reg_json['notes'] = notes
# reg_json = model_utils.update_reg_status(reg_json, self.current_view)
current_app.logger.debug(f'Built new search registration JSON for mhr {self.mhr_number}')
return reg_json_utils.set_current_misc_json(self, reg_json)
return reg_json_utils.set_current_misc_json(self, reg_json, True)

@property
def new_registration_json(self) -> dict:
Expand Down Expand Up @@ -250,7 +248,7 @@ def new_registration_json(self) -> dict:
reg_json = model_utils.update_reg_status(reg_json, self.current_view)
current_app.logger.debug('Built new registration JSON')
if self.current_view:
return reg_json_utils.set_current_misc_json(self, reg_json)
return reg_json_utils.set_current_misc_json(self, reg_json, False)
return reg_json_utils.set_payment_json(self, reg_json)
if model_utils.is_legacy() and self.manuhome:
reg_json = legacy_utils.get_new_registration_json(self)
Expand Down Expand Up @@ -295,7 +293,8 @@ def save(self):
elif self.registration_type in (MhrRegistrationTypes.EXEMPTION_RES, MhrRegistrationTypes.EXEMPTION_NON_RES):
self.manuhome = Db2Manuhome.create_from_exemption(self, self.reg_json)
self.manuhome.save_exemption()
elif self.registration_type == MhrRegistrationTypes.PERMIT:
elif self.registration_type == MhrRegistrationTypes.PERMIT or \
self.documents[0].document_type == MhrDocumentTypes.AMEND_PERMIT:
self.manuhome = Db2Manuhome.create_from_permit(self, self.reg_json)
self.manuhome.save_permit()
elif self.registration_type == MhrRegistrationTypes.REG_STAFF_ADMIN and self.reg_json.get('documentType'):
Expand Down Expand Up @@ -726,18 +725,17 @@ def create_permit_from_json(base_reg,
user_id: str = None,
user_group: str = None):
"""Create transfer registration objects from dict/json."""
if json_data.get('amendment'):
json_data['registrationType'] = MhrRegistrationTypes.AMENDMENT
else:
json_data['registrationType'] = MhrRegistrationTypes.PERMIT
json_data['registrationType'] = MhrRegistrationTypes.PERMIT
registration: MhrRegistration = MhrRegistration.create_change_from_json(base_reg,
json_data,
account_id,
user_id,
user_group)
doc: MhrDocument = registration.documents[0]
if json_data.get('amendment'):
json_data['registrationType'] = MhrRegistrationTypes.AMENDMENT
doc.document_type = MhrDocumentTypes.AMEND_PERMIT
registration.registration_type = MhrRegistrationTypes.AMENDMENT
# Save permit expiry date as a note.
note: MhrNote = MhrNote(registration_id=base_reg.id,
document_id=doc.id,
Expand All @@ -747,6 +745,13 @@ def create_permit_from_json(base_reg,
remarks='',
change_registration_id=registration.id,
expiry_date=model_utils.today_ts_offset(30, True))
# Amendment use existing expiry timestamp
if json_data.get('amendment'):
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):
note.expiry_date = reg.notes[0].expiry_date
registration.notes = [note]
# New location
registration.locations.append(MhrLocation.create_from_json(json_data.get('newLocation'), registration.id))
Expand Down
37 changes: 33 additions & 4 deletions mhr_api/src/mhr_api/models/registration_json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def set_payment_json(registration, reg_json: dict) -> dict:
return reg_json


def set_current_misc_json(registration, reg_json: dict) -> dict:
def set_current_misc_json(registration, reg_json: dict, search: bool = False) -> dict:
"""Add miscellaneous current view registration properties."""
dec_value: int = 0
dec_ts = None
Expand All @@ -55,10 +55,39 @@ def set_current_misc_json(registration, reg_json: dict) -> dict:
reg_json['declaredValue'] = dec_value
if dec_ts:
reg_json['declaredDateTime'] = model_utils.format_ts(dec_ts)
if not search:
reg_json = set_permit_json(registration, reg_json)
return reg_json


def set_submitting_json(registration, reg_json) -> dict:
def set_permit_json(registration, reg_json: dict) -> dict:
"""Conditinally add the latest transport permit information if available."""
if not registration or not reg_json or not registration.change_registrations:
return reg_json
permit_number: str = None
permit_ts = None
expiry_ts = None
permit_status = None
for reg in registration.change_registrations:
if reg.documents[0].document_type in (MhrDocumentTypes.REG_103, MhrDocumentTypes.AMEND_PERMIT):
permit_number = reg.documents[0].document_registration_number
permit_ts = reg.registration_ts
if reg.notes:
permit_status = reg.notes[0].status_type
expiry_ts = reg.notes[0].expiry_date
if permit_number:
reg_json['permitRegistrationNumber'] = permit_number
reg_json['permitDateTime'] = model_utils.format_ts(permit_ts)
if permit_status:
reg_json['permitStatus'] = permit_status
if expiry_ts:
if expiry_ts.timestamp() < model_utils.now_ts().timestamp():
reg_json['permitStatus'] = MhrNoteStatusTypes.EXPIRED
reg_json['permitExpiryDateTime'] = model_utils.format_ts(expiry_ts)
return reg_json


def set_submitting_json(registration, reg_json: dict) -> dict:
"""Build the submitting party JSON if available."""
if reg_json and registration.parties:
for party in registration.parties:
Expand All @@ -68,8 +97,8 @@ def set_submitting_json(registration, reg_json) -> dict:
return reg_json


def set_location_json(registration, reg_json, current: bool) -> dict:
"""Build the location JSON conditional on current."""
def set_location_json(registration, reg_json: dict, current: bool) -> dict:
"""Add location properties to the registration JSON based on current."""
location = None
if registration.locations:
loc = registration.locations[0]
Expand Down
1 change: 1 addition & 0 deletions mhr_api/src/mhr_api/models/registration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def find_cancelled_note(registration, reg_id: int):
"""Try and find the cancelled note matching the cancel registration document id."""
if not registration.change_registrations:
return None
current_app.logger.debug(f'find_cancelled_note id={reg_id}')
for reg in registration.change_registrations:
if reg.notes and reg.notes[0].change_registration_id == reg_id:
return reg.notes[0]
Expand Down
Loading

0 comments on commit 22cc5f3

Please sign in to comment.