diff --git a/mhr_api/src/mhr_api/models/batch_utils.py b/mhr_api/src/mhr_api/models/batch_utils.py index 0c9092a24..99ab05d25 100644 --- a/mhr_api/src/mhr_api/models/batch_utils.py +++ b/mhr_api/src/mhr_api/models/batch_utils.py @@ -386,6 +386,10 @@ def set_batch_json_owners(reg_json: dict, current_json: dict, doc_type: str, reg del reg_json['addOwnerGroups'] elif not reg_json.get('ownerGroups') and current_json: reg_json['ownerGroups'] = current_json.get('ownerGroups') + if reg_json.get('ownerGroups'): + for group in reg_json.get('ownerGroups'): + if group.get('groupSequenceNumber'): + del group['groupSequenceNumber'] return reg_json diff --git a/mhr_api/src/mhr_api/models/db2/descript.py b/mhr_api/src/mhr_api/models/db2/descript.py index cabb82896..24baaf4ef 100755 --- a/mhr_api/src/mhr_api/models/db2/descript.py +++ b/mhr_api/src/mhr_api/models/db2/descript.py @@ -289,6 +289,8 @@ def registration_json(self): description['engineerDate'] = model_utils.format_local_date(self.engineer_date) if self.circa == '?': description['baseInformation']['circa'] = True + else: + description['baseInformation']['circa'] = False return description @staticmethod diff --git a/mhr_api/src/mhr_api/models/db2/manuhome.py b/mhr_api/src/mhr_api/models/db2/manuhome.py index 3ef011baa..99e78c7df 100755 --- a/mhr_api/src/mhr_api/models/db2/manuhome.py +++ b/mhr_api/src/mhr_api/models/db2/manuhome.py @@ -479,6 +479,7 @@ def json(self): # pylint: disable=too-many-branches, too-many-statements elif group.status not in (Db2Owngroup.StatusTypes.PREVIOUS, Db2Owngroup.StatusTypes.DRAFT): existing_count += 1 man_home['addOwnerGroups'] = legacy_reg_utils.update_group_type(add_groups, existing_count) + man_home['addOwnerGroups'] = legacy_reg_utils.sort_owner_groups(man_home['addOwnerGroups']) man_home['deleteOwnerGroups'] = delete_groups else: if self.reg_owner_groups: @@ -491,6 +492,7 @@ def json(self): # pylint: disable=too-many-branches, too-many-statements owner['ownerId'] = owner_id groups.append(group_json) man_home['ownerGroups'] = legacy_reg_utils.update_group_type(groups, 0) + man_home['ownerGroups'] = legacy_reg_utils.sort_owner_groups(man_home['ownerGroups']) if self.reg_location: man_home['location'] = self.reg_location.registration_json if self.reg_descript: @@ -501,7 +503,6 @@ def json(self): # pylint: disable=too-many-branches, too-many-statements notes.append(note.registration_json) # Now sort in descending timestamp order. man_home['notes'] = legacy_reg_utils.sort_notes(notes) - return man_home @property @@ -545,6 +546,7 @@ def registration_json(self): # pylint: disable=too-many-branches owner['ownerId'] = owner_id groups.append(group_json) man_home['ownerGroups'] = legacy_reg_utils.update_group_type(groups, 0) + man_home['ownerGroups'] = legacy_reg_utils.sort_owner_groups(man_home['ownerGroups']) if self.reg_location: man_home['location'] = self.reg_location.registration_json if self.reg_descript: @@ -605,6 +607,7 @@ def new_registration_json(self): # pylint: disable=too-many-branches owner['ownerId'] = owner_id groups.append(group_json) man_home['ownerGroups'] = legacy_reg_utils.update_group_type(groups, 0) + man_home['ownerGroups'] = legacy_reg_utils.sort_owner_groups(man_home['ownerGroups']) if self.reg_location: man_home['location'] = self.reg_location.new_registration_json if self.reg_descript: diff --git a/mhr_api/src/mhr_api/models/db2/owngroup.py b/mhr_api/src/mhr_api/models/db2/owngroup.py index ab21ee708..e8b5726e8 100644 --- a/mhr_api/src/mhr_api/models/db2/owngroup.py +++ b/mhr_api/src/mhr_api/models/db2/owngroup.py @@ -193,6 +193,7 @@ def registration_json(self): self.strip() group = { 'groupId': self.group_id, + 'groupSequenceNumber': self.sequence_number, 'type': LEGACY_TENANCY_NEW.get(self.tenancy_type), 'status': LEGACY_STATUS_NEW.get(self.status), 'interest': self.interest, diff --git a/mhr_api/src/mhr_api/models/db2/registration_utils.py b/mhr_api/src/mhr_api/models/db2/registration_utils.py index 2f1602f81..7588275c7 100644 --- a/mhr_api/src/mhr_api/models/db2/registration_utils.py +++ b/mhr_api/src/mhr_api/models/db2/registration_utils.py @@ -494,6 +494,17 @@ def update_description(registration, return manuhome +def get_group_sequence_num(manuhome, add_count: int, group_id: int) -> int: + """Derive the group sequence number from the group id of an existing group with a default of 1.""" + sequence_num: int = add_count + if not group_id: + return sequence_num + for group in manuhome.reg_owner_groups: + if group.group_id == group_id: + return group.sequence_number + return sequence_num + + def update_owner_groups(registration, manuhome, reg_json: dict): """Update owner groups for transfer and correction/amendment registration owner changes.""" # Update owner groups: group ID increments with each change. @@ -516,10 +527,14 @@ def update_owner_groups(registration, manuhome, reg_json: dict): group = Db2Owngroup.create_from_registration(registration, new_group, group_id, group_id) group.modified = True group_id += 1 + if not group.interest or not group.interest_numerator or group.interest_numerator == 0: + group.sequence_number = 1 + else: + group.sequence_number = new_group.get('groupId') manuhome.reg_owner_groups.append(group) adjust_group_interest(manuhome.reg_owner_groups, False) registration.id = reg_id - set_owner_sequence_num(manuhome.reg_owner_groups) + # set_owner_sequence_num(manuhome.reg_owner_groups) def set_transfer_group_json(registration, reg_json) -> dict: @@ -559,26 +574,54 @@ def set_active_groups_json(registration, reg_json: dict) -> dict: return reg_json groups = [] existing_count: int = 0 - group_id: int = 1 + # group_id: int = 1 new_reg_doc_id: str = reg_json.get('documentId') for group in registration.manuhome.reg_owner_groups: if group.status in (Db2Owngroup.StatusTypes.ACTIVE, Db2Owngroup.StatusTypes.EXEMPT): if group.reg_document_id != new_reg_doc_id: existing_count += 1 group_json = group.registration_json - group_json['groupId'] = group_id - group_id += 1 + # group_json['groupId'] = group_id + # group_id += 1 group_json['existing'] = True groups.append(group_json) elif not reg_json.get('addOwnerGroups'): group_json = group.registration_json - group_json['groupId'] = group_id - group_id += 1 + # group_json['groupId'] = group_id + # group_id += 1 groups.append(group_json) if reg_json.get('addOwnerGroups'): for group in reg_json.get('addOwnerGroups'): - group['groupId'] = group_id - group_id += 1 + # group['groupId'] = group_id + # group_id += 1 groups.append(group) reg_json['ownerGroups'] = update_group_type(groups, existing_count) + reg_json['ownerGroups'] = sort_owner_groups(reg_json['ownerGroups']) return reg_json + + +def sort_key_groups_sequence(item): + """Sort the tenants in common owner groups by group sequence number.""" + return item.get('groupSequenceNumber', 1) + + +def sort_common_owner_groups(owner_groups): + """Sort tenants in common owner groups by group sequence number.""" + owner_groups.sort(key=sort_key_groups_sequence) + return owner_groups + + +def sort_owner_groups(owner_groups: dict, cleanup: bool = False) -> dict: + """Sort tenants in common owner groups by group sequence number, remove groupSequenceNumber.""" + if not owner_groups: + return owner_groups + if len(owner_groups) == 1: + if cleanup and owner_groups[0].get('groupSequenceNumber'): + del owner_groups[0]['groupSequenceNumber'] + return owner_groups + sorted_groups = sort_common_owner_groups(owner_groups) + if cleanup: + for group in sorted_groups: + if group.get('groupSequenceNumber'): + del group['groupSequenceNumber'] + return sorted_groups diff --git a/mhr_api/src/mhr_api/models/mhr_owner_group.py b/mhr_api/src/mhr_api/models/mhr_owner_group.py index 8076d6e11..a0463fbc8 100644 --- a/mhr_api/src/mhr_api/models/mhr_owner_group.py +++ b/mhr_api/src/mhr_api/models/mhr_owner_group.py @@ -34,6 +34,7 @@ class MhrOwnerGroup(db.Model): # pylint: disable=too-many-instance-attributes interest_numerator = db.mapped_column('interest_numerator', db.Integer, nullable=False) interest_denominator = db.mapped_column('interest_denominator', db.Integer, nullable=False) tenancy_specified = db.mapped_column('tenancy_specified', db.String(1), nullable=False) + group_sequence_number = db.mapped_column('group_sequence_number', db.Integer, nullable=True) # parent keys registration_id = db.mapped_column('registration_id', db.Integer, db.ForeignKey('mhr_registrations.id'), @@ -57,6 +58,7 @@ def json(self) -> dict: """Return the owner group as a json object.""" group = { 'groupId': self.group_id, + 'groupSequenceNumber': self.group_sequence_number if self.group_sequence_number else self.group_id, 'type': self.tenancy_type, 'status': self.status_type, 'tenancySpecified': True diff --git a/mhr_api/src/mhr_api/models/mhr_registration.py b/mhr_api/src/mhr_api/models/mhr_registration.py index 85caed741..f54319889 100755 --- a/mhr_api/src/mhr_api/models/mhr_registration.py +++ b/mhr_api/src/mhr_api/models/mhr_registration.py @@ -138,7 +138,7 @@ def json(self) -> dict: reg_json = reg_json_utils.set_description_json(self, reg_json, False, doc_json.get('documentType')) # Set owner groups for all registration types. if self.registration_type in (MhrRegistrationTypes.MHREG, MhrRegistrationTypes.MHREG_CONVERSION): - reg_json = reg_json_utils.set_group_json(self, reg_json, False) + reg_json = reg_json_utils.set_group_json(self, reg_json, False, True) else: reg_json = reg_json_utils.set_transfer_group_json(self, reg_json, doc_json.get('documentType')) if self.registration_type == MhrRegistrationTypes.TRANS and \ @@ -204,7 +204,7 @@ def registration_json(self) -> dict: 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) - reg_json = reg_json_utils.set_group_json(self, reg_json, self.current_view) + reg_json = reg_json_utils.set_group_json(self, reg_json, self.current_view, True) notes = reg_json_utils.get_notes_json(self, True, self.staff) if notes: reg_json['notes'] = notes @@ -884,6 +884,7 @@ def create_new_groups(self, json_data): sequence += 1 group: MhrOwnerGroup = MhrOwnerGroup.create_from_json(group_json, self.id) group.group_id = sequence + group.group_sequence_number = sequence # Add owners for owner_json in group_json.get('owners'): party_type = owner_json.get('partyType', None) @@ -906,13 +907,16 @@ def add_new_groups(self, json_data, existing_count: int): # Update owner groups: group ID increments with each change. group_id: int = existing_count + 1 if json_data.get('addOwnerGroups'): - for group_json in json_data.get('addOwnerGroups'): + for new_json in json_data.get('addOwnerGroups'): current_app.logger.info(f'Creating owner group id={group_id}') - new_group: MhrOwnerGroup = MhrOwnerGroup.create_from_change_json(group_json, self.id, self.id, - group_id) + new_group: MhrOwnerGroup = MhrOwnerGroup.create_from_change_json(new_json, self.id, self.id, group_id) group_id += 1 + if not new_group.interest or not new_group.interest_numerator or new_group.interest_numerator == 0: + new_group.group_sequence_number = 1 + else: + new_group.group_sequence_number = new_json.get('groupId') # Add owners - for owner_json in group_json.get('owners'): + for owner_json in new_json.get('owners'): party_type = owner_json.get('partyType', None) if not party_type and owner_json.get('individualName'): party_type = MhrPartyTypes.OWNER_IND diff --git a/mhr_api/src/mhr_api/models/registration_history_utils.py b/mhr_api/src/mhr_api/models/registration_history_utils.py index 7b1c3b30d..354a6e92b 100644 --- a/mhr_api/src/mhr_api/models/registration_history_utils.py +++ b/mhr_api/src/mhr_api/models/registration_history_utils.py @@ -17,7 +17,7 @@ """This module holds methods to support a manufactured home registration history model mapping to dict/json.""" from flask import current_app from mhr_api.models import utils as model_utils -from mhr_api.models.registration_json_utils import set_group_json +from mhr_api.models.registration_json_utils import set_group_json, sort_owner_groups from mhr_api.models.registration_utils import find_cancelled_note, get_document_description from mhr_api.models.type_tables import ( MhrDocumentTypes, @@ -179,7 +179,7 @@ def set_group_extra_json(base_reg: MhrRegistration, reg_id: int, group_id: int, for group in reg.owner_groups: group_count += 1 if group_id == group.id: - active_group_id = group_count + active_group_id = group.group_sequence_number group_type = group.tenancy_type elif reg.id < reg_id and reg.owner_groups: for group in reg.owner_groups: @@ -431,5 +431,5 @@ def set_change_group_json(registration: MhrRegistration, base_reg: MhrRegistrati if existing.registration_id != registration.id and existing.change_registration_id == registration.id: delete_groups.append(existing.json) reg_json['deleteOwnerGroups'] = delete_groups - reg_json['addOwnerGroups'] = add_groups + reg_json['addOwnerGroups'] = sort_owner_groups(add_groups) return reg_json diff --git a/mhr_api/src/mhr_api/models/registration_json_utils.py b/mhr_api/src/mhr_api/models/registration_json_utils.py index 785fb3f67..ee6213121 100644 --- a/mhr_api/src/mhr_api/models/registration_json_utils.py +++ b/mhr_api/src/mhr_api/models/registration_json_utils.py @@ -91,11 +91,13 @@ def set_permit_json(registration, reg_json: dict) -> dict: # pylint: disable=to if reg.documents[0].document_type == MhrDocumentTypes.REG_103: permit_number = reg.documents[0].document_registration_number 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.notes: permit_status = reg.notes[0].status_type expiry_ts = reg.notes[0].expiry_date + # current_app.logger.debug(f'set permit reg id {reg.id} set_permit status {permit_status}') permit_reg_id = reg.id if permit_number: reg_json['permitRegistrationNumber'] = permit_number @@ -282,7 +284,36 @@ def set_description_json(registration, reg_json, current: bool, doc_type: str = return reg_json -def set_group_json(registration, reg_json, current: bool) -> dict: +def sort_owner_groups(owner_groups: dict, cleanup: bool = False) -> dict: + """Sort tenants in common owner groups by group sequence number, remove groupSequenceNumber.""" + if not owner_groups: + return owner_groups + if len(owner_groups) == 1: + if cleanup and owner_groups[0].get('groupSequenceNumber'): + del owner_groups[0]['groupSequenceNumber'] + return owner_groups + sorted_groups = sort_common_owner_groups(owner_groups) + if cleanup: + for group in sorted_groups: + if group.get('groupSequenceNumber'): + del group['groupSequenceNumber'] + return sorted_groups + + +def cleanup_owner_groups(reg_json: dict) -> dict: + """Cleanup registration owner groups, removing groupSequenceNumber.""" + if reg_json.get('ownerGroups'): + for group in reg_json.get('ownerGroups'): + if group.get('groupSequenceNumber'): + del group['groupSequenceNumber'] + if reg_json.get('addOwnerGroups'): + for group in reg_json.get('addOwnerGroups'): + if group.get('groupSequenceNumber'): + del group['groupSequenceNumber'] + return reg_json + + +def set_group_json(registration, reg_json, current: bool, cleanup: bool = False) -> dict: """Build the owner group JSON conditional on current.""" owner_groups = [] if registration.owner_groups: @@ -298,7 +329,8 @@ def set_group_json(registration, reg_json, current: bool) -> dict: for group in reg.owner_groups: if group.status_type in (MhrOwnerStatusTypes.ACTIVE, MhrOwnerStatusTypes.EXEMPT): owner_groups.append(group.json) - reg_json['ownerGroups'] = owner_groups + # Sort by group sequence number, remove groupSequenceNumber after sorting. + reg_json['ownerGroups'] = sort_owner_groups(owner_groups, cleanup) return reg_json @@ -327,7 +359,9 @@ def set_transfer_group_json(registration, reg_json, doc_type: str) -> dict: reg_json['deleteOwnerGroups'] = delete_groups if not delete_groups and not add_groups and model_utils.is_legacy(): # Legacy MH home current_app.logger.debug(f'Transfer legacy MHR {registration.mhr_number} using legacy owner groups.') - return legacy_reg_utils.set_transfer_group_json(registration, reg_json) + reg_json = legacy_reg_utils.set_transfer_group_json(registration, reg_json) + if reg_json.get('addOwnerGroups'): + reg_json['addOwnerGroups'] = sort_owner_groups(reg_json.get('addOwnerGroups'), False) return reg_json @@ -390,6 +424,17 @@ def sort_notes(notes): return notes +def sort_key_groups_sequence(item): + """Sort the tenants in common owner groups by group sequence number.""" + return item.get('groupSequenceNumber', 1) + + +def sort_common_owner_groups(owner_groups): + """Sort tenants in common owner groups by group sequence number.""" + owner_groups.sort(key=sort_key_groups_sequence) + return owner_groups + + def get_notes_json(registration, search: bool, staff: bool = False) -> dict: # pylint: disable=too-many-branches; 13 """Fetch all the unit notes for the manufactured home. Search has special conditions on what is included.""" notes = [] @@ -579,9 +624,9 @@ def set_reg_groups_json(current_reg, # pylint: disable=too-many-branches if group.status_type == MhrOwnerStatusTypes.PREVIOUS and group.change_registration_id == reg_id: delete_groups.append(group.json) if groups and transfer: - reg_json['addOwnerGroups'] = groups + reg_json['addOwnerGroups'] = sort_owner_groups(groups) elif groups: - reg_json['ownerGroups'] = groups + reg_json['ownerGroups'] = sort_owner_groups(groups) if delete_groups and transfer: reg_json['deleteOwnerGroups'] = delete_groups return reg_json diff --git a/mhr_api/src/mhr_api/models/registration_utils.py b/mhr_api/src/mhr_api/models/registration_utils.py index 8068cb39c..134e34db3 100644 --- a/mhr_api/src/mhr_api/models/registration_utils.py +++ b/mhr_api/src/mhr_api/models/registration_utils.py @@ -241,7 +241,7 @@ def get_ppr_registration_type(mhr_number: str) -> str: def get_owner_group_count(base_reg) -> int: - """Derive the next owner group sequence number from the number of existing groups.""" + """Derive the next owner group id from the number of existing groups.""" count: int = len(base_reg.owner_groups) for reg in base_reg.change_registrations: if reg.owner_groups: @@ -249,18 +249,31 @@ def get_owner_group_count(base_reg) -> int: return count +def get_group_sequence_num(base_reg, add_count: int, group_id: int) -> int: + """Derive the group sequence number from the group id of an existing group with a default of 1.""" + sequence_num: int = add_count + if not group_id: + return sequence_num + for group in base_reg.owner_groups: + if group.group_id == group_id: + return group.group_sequence_number + for reg in base_reg.change_registrations: + if reg.owner_groups: + for group in reg.owner_groups: + if group.group_id == group_id: + return group.group_sequence_number + return sequence_num + + def is_transfer_due_to_death(reg_type: str) -> bool: """Return if the registration type is a type of Transfer Due to Death.""" - return reg_type and reg_type in (MhrRegistrationTypes.TRANS_ADMIN, - MhrRegistrationTypes.TRANS_AFFIDAVIT, - MhrRegistrationTypes.TRANS_WILL, - MhrRegistrationTypes.TRAND) + return reg_type and reg_type in (MhrRegistrationTypes.TRANS_ADMIN, MhrRegistrationTypes.TRANS_AFFIDAVIT, + MhrRegistrationTypes.TRANS_WILL, MhrRegistrationTypes.TRAND) def is_transfer_due_to_death_staff(reg_type: str) -> bool: """Return if the registration type is a type of Transfer Due to Death.""" - return reg_type and reg_type in (MhrRegistrationTypes.TRANS_ADMIN, - MhrRegistrationTypes.TRANS_AFFIDAVIT, + return reg_type and reg_type in (MhrRegistrationTypes.TRANS_ADMIN, MhrRegistrationTypes.TRANS_AFFIDAVIT, MhrRegistrationTypes.TRANS_WILL) @@ -491,9 +504,7 @@ def save_cancel_note(registration, json_data, new_reg_id): # pylint: disable=to if reg.notes: doc = reg.documents[0] if doc.document_id != cancel_doc_id and \ - doc.document_type in (MhrDocumentTypes.CAU, - MhrDocumentTypes.CAUC, - MhrDocumentTypes.CAUE): + doc.document_type in (MhrDocumentTypes.CAU, MhrDocumentTypes.CAUC, MhrDocumentTypes.CAUE): note = reg.notes[0] if note.status_type == MhrNoteStatusTypes.ACTIVE: note.status_type = MhrNoteStatusTypes.CANCELLED @@ -503,8 +514,7 @@ def save_cancel_note(registration, json_data, new_reg_id): # pylint: disable=to if reg.notes: doc = reg.documents[0] if doc.document_id != cancel_doc_id and \ - doc.document_type in (MhrDocumentTypes.EXNR, - MhrDocumentTypes.EXRS, + doc.document_type in (MhrDocumentTypes.EXNR, MhrDocumentTypes.EXRS, MhrDocumentTypes.EXMN): note = reg.notes[0] if note.status_type == MhrNoteStatusTypes.ACTIVE: @@ -528,8 +538,7 @@ def save_active(registration): def cancel_note_exre(registration, new_reg_id): """EXRE cancel all active exemption notes.""" for reg in registration.change_registrations: - if reg.notes and reg.notes[0].document_type in (MhrDocumentTypes.EXNR, - MhrDocumentTypes.EXRS, + if reg.notes and reg.notes[0].document_type in (MhrDocumentTypes.EXNR, MhrDocumentTypes.EXRS, MhrDocumentTypes.EXMN): note = reg.notes[0] if note.status_type == MhrNoteStatusTypes.ACTIVE: @@ -541,11 +550,8 @@ def save_admin(registration, json_data: dict, new_reg_id: int): """Admin registration updates to existing records.""" doc_type: str = json_data.get('documentType', '') current_app.logger.debug(f'save_admin doc type={doc_type}') - if doc_type not in (MhrDocumentTypes.EXRE, - MhrDocumentTypes.STAT, - MhrDocumentTypes.REGC_CLIENT, - MhrDocumentTypes.REGC_STAFF, - MhrDocumentTypes.PUBA): + if doc_type not in (MhrDocumentTypes.EXRE, MhrDocumentTypes.STAT, MhrDocumentTypes.REGC_CLIENT, + MhrDocumentTypes.REGC_STAFF, MhrDocumentTypes.PUBA): return if json_data.get('location'): if registration.locations and registration.locations[0].status_type == MhrStatusTypes.ACTIVE: diff --git a/mhr_api/src/mhr_api/reports/v2/report.py b/mhr_api/src/mhr_api/reports/v2/report.py index b7c361a8d..b7674f3dd 100755 --- a/mhr_api/src/mhr_api/reports/v2/report.py +++ b/mhr_api/src/mhr_api/reports/v2/report.py @@ -461,7 +461,8 @@ def _set_owner_groups(self): group['groupId'] = group_id group_id += 1 self._report_data['hasNA'] = has_na - elif self._report_key == ReportTypes.MHR_REGISTRATION: + elif self._report_key == ReportTypes.MHR_REGISTRATION or \ + (self._report_key == ReportTypes.MHR_ADMIN_REGISTRATION and self._report_data.get('ownerGroups')): has_na: bool = False for group in self._report_data.get('ownerGroups'): group['groupId'] = group_id diff --git a/mhr_api/src/mhr_api/resources/v1/admin_registrations.py b/mhr_api/src/mhr_api/resources/v1/admin_registrations.py index 287d7d391..108263bba 100644 --- a/mhr_api/src/mhr_api/resources/v1/admin_registrations.py +++ b/mhr_api/src/mhr_api/resources/v1/admin_registrations.py @@ -31,6 +31,7 @@ MhrRegistrationTypes, MhrRegistrationStatusTypes ) +from mhr_api.models.registration_json_utils import cleanup_owner_groups, sort_owner_groups from mhr_api.reports.v2.report_utils import ReportTypes from mhr_api.resources import utils as resource_utils, registration_utils as reg_utils from mhr_api.services.payment import TransactionTypes @@ -147,11 +148,13 @@ def save_registration(req: request, request_json: dict, current_reg: MhrRegistra current_app.logger.info('Report not yet available: returning JSON.') if request_json.get('documentType', '') == MhrDocumentTypes.EXRE: setup_report_exre(registration, response_json, current_json, group, current_reg) + response_json = cleanup_owner_groups(response_json) return jsonify(response_json), HTTPStatus.CREATED if request_json.get('documentType', '') == MhrDocumentTypes.CANCEL_PERMIT: response_json['previousLocation'] = current_json.get('location') setup_report(registration, response_json, current_json, group, current_reg) + response_json = cleanup_owner_groups(response_json) return jsonify(response_json), HTTPStatus.CREATED @@ -240,7 +243,7 @@ def get_report_groups(response_json: dict, current_json: dict, add_groups: dict) added = True if not added: new_groups.append(add_group) - return new_groups + return sort_owner_groups(new_groups, True) def get_transaction_type(request_json: dict) -> str: diff --git a/mhr_api/src/mhr_api/resources/v1/registrations.py b/mhr_api/src/mhr_api/resources/v1/registrations.py index b6d4aae19..309975d21 100755 --- a/mhr_api/src/mhr_api/resources/v1/registrations.py +++ b/mhr_api/src/mhr_api/resources/v1/registrations.py @@ -28,6 +28,7 @@ ) from mhr_api.models.type_tables import MhrNoteStatusTypes, MhrRegistrationTypes from mhr_api.models.registration_history_utils import get_history_json +from mhr_api.models.registration_json_utils import cleanup_owner_groups from mhr_api.models.registration_utils import AccountRegistrationParams from mhr_api.reports import get_callback_pdf from mhr_api.reports.v2.report import Report @@ -136,6 +137,7 @@ def post_registrations(): # pylint: disable=too-many-return-statements,too-many TransactionTypes.REGISTRATION) registration.report_view = True response_json = registration.new_registration_json + response_json = cleanup_owner_groups(response_json) # Return report if request header Accept MIME type is application/pdf. if resource_utils.is_pdf(request): @@ -202,6 +204,7 @@ def get_registrations(mhr_number: str): # pylint: disable=too-many-return-state account_id, is_all_staff_account(account_id)) response_json = registration.new_registration_json + response_json = cleanup_owner_groups(response_json) # Return report if request header Accept MIME type is application/pdf. if resource_utils.is_pdf(request): report_type = ReportTypes.MHR_REGISTRATION diff --git a/mhr_api/src/mhr_api/resources/v1/transfers.py b/mhr_api/src/mhr_api/resources/v1/transfers.py index dc94090c3..5ea5fa23a 100644 --- a/mhr_api/src/mhr_api/resources/v1/transfers.py +++ b/mhr_api/src/mhr_api/resources/v1/transfers.py @@ -32,6 +32,7 @@ from mhr_api.services.authz import TRANSFER_SALE_BENEFICIARY, TRANSFER_DEATH_JT from mhr_api.models import MhrRegistration from mhr_api.models import registration_utils as model_reg_utils, utils as model_utils +from mhr_api.models.registration_json_utils import cleanup_owner_groups, sort_owner_groups from mhr_api.models.type_tables import MhrRegistrationStatusTypes, MhrOwnerStatusTypes from mhr_api.reports.v2.report_utils import ReportTypes from mhr_api.resources import utils as resource_utils, registration_utils as reg_utils @@ -143,7 +144,7 @@ def setup_report(registration: MhrRegistration, # pylint: disable=too-many-loca added = True if not added: new_groups.append(add_group) - response_json['addOwnerGroups'] = new_groups + response_json['addOwnerGroups'] = sort_owner_groups(new_groups) # Report setup is current view except for FROZEN status: update report data. status: str = response_json.get('status') if status == model_utils.STATUS_FROZEN: @@ -168,3 +169,4 @@ def setup_report(registration: MhrRegistration, # pylint: disable=too-many-loca response_add_groups.append(add_group) response_json['addOwnerGroups'] = response_add_groups response_json['status'] = status + response_json = cleanup_owner_groups(response_json) diff --git a/mhr_api/test_data/db2_data_files/test0001.sql b/mhr_api/test_data/db2_data_files/test0001.sql index 38087c8f1..0366deb70 100644 --- a/mhr_api/test_data/db2_data_files/test0001.sql +++ b/mhr_api/test_data/db2_data_files/test0001.sql @@ -23,7 +23,7 @@ INSERT INTO amhrtdb.owngroup(MANHOMID, OWNGRPID, COPGRPID, GRPSEQNO, STATUS, REG VALUES (200000001, 1, 0, 1, '3', 'UT000001', 'TC', 'UNDIVIDED 1/2', 1, 'Y') ; INSERT INTO amhrtdb.owngroup(MANHOMID, OWNGRPID, COPGRPID, GRPSEQNO, STATUS, REGDOCID, TENYTYPE, INTEREST, INTNUMER, TENYSPEC) - VALUES (200000001, 2, 0, 1, '3', 'UT000001', 'TC', 'UNDIVIDED 1/2', 1, 'Y') + VALUES (200000001, 2, 0, 2, '3', 'UT000001', 'TC', 'UNDIVIDED 1/2', 1, 'Y') ; INSERT INTO amhrtdb.owner(MANHOMID, OWNGRPID, OWNERID, OWNSEQNO, VERIFIED, OWNRTYPE, COMPNAME, OWNRFONE, OWNRPOCO, OWNRNAME, OWNRSUFF, OWNRADDR) VALUES (200000001, 1, 1, 1, ' ', 'B', 'CELESTIALHEAVENLYHOMES', '2507701067', 'V8R 3A5', 'CELESTIAL HEAVENLY HOMES', '', diff --git a/mhr_api/test_data/postgres_data_files/test0001.sql b/mhr_api/test_data/postgres_data_files/test0001.sql index 76418287e..677efa90e 100644 --- a/mhr_api/test_data/postgres_data_files/test0001.sql +++ b/mhr_api/test_data/postgres_data_files/test0001.sql @@ -89,12 +89,12 @@ INSERT INTO mhr_notes(id, document_type, registration_id, document_id, status_ty VALUES(200000001, 'REG_101', 200000001, 200000001, 'ACTIVE', 'remarks here', 'N', 200000001, null) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000001, 1, 200000001, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 2, 200000001) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000001, 1, 200000001, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 2, 200000001, 1) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000002, 2, 200000001, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 2, 200000001) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000002, 2, 200000001, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 2, 200000001, 2) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000006, '1234 TEST-0001', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -160,8 +160,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000002, 'REG_101', 200000002, 'UT000002', '90499002', 'attn', NULL, NULL, 'Y', null, null, null, 200000002) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000003, 1, 200000002, 'ACTIVE', 'JOINT', NULL, 'Y', NULL, NULL, 200000002) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000003, 1, 200000002, 'ACTIVE', 'JOINT', NULL, 'Y', NULL, NULL, 200000002, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000010, '1234 TEST-0002', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') diff --git a/mhr_api/test_data/postgres_data_files/test0002.sql b/mhr_api/test_data/postgres_data_files/test0002.sql index e1c46fdb8..c0dcf5a34 100644 --- a/mhr_api/test_data/postgres_data_files/test0002.sql +++ b/mhr_api/test_data/postgres_data_files/test0002.sql @@ -52,8 +52,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000004, 1, 200000003, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000003) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000004, 1, 200000003, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000003, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000015, '1234 TEST-0003', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -121,8 +121,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000004, 'REG_101', 200000004, 'UT000004', '90499004', 'attn', NULL, NULL, 'Y', null, null, null, 200000004) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000005, 1, 200000004, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000004) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000005, 1, 200000004, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000004, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000018, '1234 TEST-0004', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -184,8 +184,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000005, 'REG_101', 200000005, 'UT000005', '90499005', 'attn', NULL, NULL, 'Y', null, null, null, 200000005) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000006, 1, 200000005, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000005) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000006, 1, 200000005, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000005, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000021, '1234 TEST-0005', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -244,8 +244,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000007, 1, 200000006, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000006) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000007, 1, 200000006, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000006, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000024, '1234 TEST-0006', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') diff --git a/mhr_api/test_data/postgres_data_files/test0003.sql b/mhr_api/test_data/postgres_data_files/test0003.sql index 27cadf640..3a2f74251 100644 --- a/mhr_api/test_data/postgres_data_files/test0003.sql +++ b/mhr_api/test_data/postgres_data_files/test0003.sql @@ -47,8 +47,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000008, 1, 200000007, 'PREVIOUS', 'JOINT', NULL, 'Y', NULL, NULL, 200000007) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000008, 1, 200000007, 'PREVIOUS', 'JOINT', NULL, 'Y', NULL, NULL, 200000007, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000027, '1234 TEST-0007', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -66,8 +66,8 @@ INSERT INTO mhr_parties(id, party_type, status_type, registration_id, change_reg mhr_name_compressed_key('TEST ONLY SERAPHIC HOMES'), 190000027, null, NULL, null, 200000008) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000009, 1, 200000007, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000007) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000009, 1, 200000007, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000007, 1) ; INSERT INTO mhr_parties(id, party_type, status_type, registration_id, change_registration_id, first_name, middle_name, last_name, business_name, compressed_name, address_id, email_address, phone_number, phone_extension, @@ -117,8 +117,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000008, 'REG_101', 200000008, 'UT000008', '90499008', 'attn', NULL, NULL, 'Y', null, null, null, 200000008) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000010, 1, 200000008, 'PREVIOUS', 'SOLE', NULL, 'Y', NULL, NULL, 200000008) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000010, 1, 200000008, 'PREVIOUS', 'SOLE', NULL, 'Y', NULL, NULL, 200000008, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000030, '1234 TEST-0008', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -130,8 +130,8 @@ INSERT INTO mhr_parties(id, party_type, status_type, registration_id, change_reg mhr_name_compressed_key('ZAXOD GAYLEX'), 190000030, null, NULL, null, 200000010) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000011, 1, 200000008, 'EXEMPT', 'SOLE', NULL, 'Y', NULL, NULL, 200000008) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000011, 1, 200000008, 'EXEMPT', 'SOLE', NULL, 'Y', NULL, NULL, 200000008, 1) ; INSERT INTO mhr_parties(id, party_type, status_type, registration_id, change_registration_id, first_name, middle_name, last_name, business_name, compressed_name, address_id, email_address, phone_number, phone_extension, @@ -140,8 +140,8 @@ INSERT INTO mhr_parties(id, party_type, status_type, registration_id, change_reg mhr_name_compressed_key('ZAXOD GAYLEX'), 190000030, null, NULL, null, 200000011) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000012, 1, 200000008, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000008) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000012, 1, 200000008, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000008, 1) ; INSERT INTO mhr_parties(id, party_type, status_type, registration_id, change_registration_id, first_name, middle_name, last_name, business_name, compressed_name, address_id, email_address, phone_number, phone_extension, @@ -206,8 +206,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000009, 'REG_101', 200000009, 'UT000009', '90499009', 'attn', NULL, NULL, 'Y', null, null, null, 200000009) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000013, 1, 200000009, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000009) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000013, 1, 200000009, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000009, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000033, '1234 TEST-0009', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -260,8 +260,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000010, 'REG_101', 200000010, 'UT000010', '90499010', 'attn', NULL, NULL, 'Y', null, null, null, 200000010) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000014, 1, 200000010, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000010) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000014, 1, 200000010, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000010, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000036, '1234 TEST-0010', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -376,8 +376,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000013, 'REG_101', 200000013, 'UT000013', '90499013', 'attn', NULL, NULL, 'Y', null, null, null, 200000013) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000015, 1, 200000013, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000013) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000015, 1, 200000013, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000013, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000041, '1234 TEST-0011', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') diff --git a/mhr_api/test_data/postgres_data_files/test0004.sql b/mhr_api/test_data/postgres_data_files/test0004.sql index 902b408dd..881d4e234 100644 --- a/mhr_api/test_data/postgres_data_files/test0004.sql +++ b/mhr_api/test_data/postgres_data_files/test0004.sql @@ -44,8 +44,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000016, 'REG_101', 200000016, 'UT000016', '90499016', 'attn', NULL, NULL, 'Y', null, null, null, 200000016) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000016, 1, 200000016, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000016) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000016, 1, 200000016, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000016, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000046, '1234 TEST-0012', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -103,8 +103,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000017, 'REG_101', 200000017, 'UT000017', '90499017', 'attn', NULL, NULL, 'Y', null, null, null, 200000017) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000017, 1, 200000017, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000017) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000017, 1, 200000017, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000017, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000049, '1234 TEST-0013', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -157,8 +157,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000018, 'REG_101', 200000018, 'UT000018', '90499018', 'attn', NULL, NULL, 'Y', null, null, null, 200000018) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000018, 1, 200000018, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000018) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000018, 1, 200000018, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000018, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000052, '1234 TEST-0014', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') diff --git a/mhr_api/test_data/postgres_data_files/test0005.sql b/mhr_api/test_data/postgres_data_files/test0005.sql index d9e5fe393..0d60dfba2 100644 --- a/mhr_api/test_data/postgres_data_files/test0005.sql +++ b/mhr_api/test_data/postgres_data_files/test0005.sql @@ -46,8 +46,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000019, 'REG_101', 200000019, 'UT000019', '90499019', 'attn', NULL, NULL, 'Y', null, null, null, 200000019) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000019, 1, 200000019, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000019) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000019, 1, 200000019, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000019, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000055, '1234 TEST-0015', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -129,8 +129,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000021, 'REG_101', 200000021, 'UT000021', '90499021', 'attn', NULL, NULL, 'Y', null, null, null, 200000021) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000020, 1, 200000021, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000021) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000020, 1, 200000021, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000021, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000059, '1234 TEST-0016', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -241,8 +241,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000024, 'REG_101', 200000024, 'UT000024', '90499024', 'attn', NULL, NULL, 'Y', null, null, null, 200000024) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000021, 1, 200000024, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000024) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000021, 1, 200000024, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000024, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000064, '1234 TEST-0017', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') diff --git a/mhr_api/test_data/postgres_data_files/test0006.sql b/mhr_api/test_data/postgres_data_files/test0006.sql index 7d4c1fb78..16460025b 100644 --- a/mhr_api/test_data/postgres_data_files/test0006.sql +++ b/mhr_api/test_data/postgres_data_files/test0006.sql @@ -49,8 +49,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000026, 'REG_101', 200000026, 'UT000026', '90499026', 'attn', NULL, NULL, 'Y', null, null, null, 200000026) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000022, 1, 200000026, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000026) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000022, 1, 200000026, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000026, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000068, '1234 TEST-0018', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -80,8 +80,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000027, 'AFFE', 200000027, 'UT000027', '90499027', 'attn', 1000, '$1000.00', 'Y', now() at time zone 'UTC', null, null, 200000027) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000023, 1, 200000027, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000027) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000023, 1, 200000027, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000027, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000070, '1234 TEST-0018', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -144,8 +144,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000028, 'REG_101', 200000028, 'UT000028', '90499028', 'attn', NULL, NULL, 'Y', null, null, null, 200000028) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000024, 1, 200000028, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000028) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000024, 1, 200000028, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000028, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000073, '1234 TEST-0019', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -226,8 +226,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000030, 'REG_101', 200000030, 'UT000030', '90499030', 'attn', NULL, NULL, 'Y', null, null, null, 200000030) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000025, 1, 200000030, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000030) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000025, 1, 200000030, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000030, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000077, '1234 TEST-0020', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -279,8 +279,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000031, 'REG_101', 200000031, 'UT000031', '90499031', 'attn', NULL, NULL, 'Y', null, null, null, 200000031) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000026, 1, 200000031, 'ACTIVE', 'JOINT', NULL, 'Y', NULL, NULL, 200000031) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000026, 1, 200000031, 'ACTIVE', 'JOINT', NULL, 'Y', NULL, NULL, 200000031, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000080, '1234 TEST-0021', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -338,8 +338,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000032, 'REG_101', 200000032, 'UT000032', '90499032', 'attn', NULL, NULL, 'Y', null, null, null, 200000032) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000027, 1, 200000032, 'ACTIVE', 'JOINT', NULL, 'Y', NULL, NULL, 200000032) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000027, 1, 200000032, 'ACTIVE', 'JOINT', NULL, 'Y', NULL, NULL, 200000032, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000083, '1234 TEST-0022', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -397,8 +397,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000033, 'REG_101', 200000033, 'UT000033', '90499033', 'attn', NULL, NULL, 'Y', null, null, null, 200000033) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000028, 1, 200000033, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000033) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000028, 1, 200000033, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000033, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000086, '1234 TEST-0023', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -451,8 +451,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000034, 'REG_101', 200000034, 'UT000034', '90499034', 'attn', NULL, NULL, 'Y', null, null, null, 200000034) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000029, 1, 200000034, 'ACTIVE', 'JOINT', NULL, 'Y', NULL, NULL, 200000034) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000029, 1, 200000034, 'ACTIVE', 'JOINT', NULL, 'Y', NULL, NULL, 200000034, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000089, '1234 TEST-0024', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -512,12 +512,12 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000035, 'REG_101', 200000035, 'UT000035', '90499035', 'attn', NULL, NULL, 'Y', null, null, null, 200000035) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000030, 1, 200000035, 'ACTIVE', 'NA', 'UNDIVIDED', 'Y', 1, 2, 200000035) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000030, 1, 200000035, 'ACTIVE', 'NA', 'UNDIVIDED', 'Y', 1, 2, 200000035, 1) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000031, 2, 200000035, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 2, 200000035) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000031, 2, 200000035, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 2, 200000035, 2) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000092, '1234 TEST-0025', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -580,16 +580,16 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000036, 'REG_101', 200000036, 'UT000036', '90499036', 'attn', NULL, NULL, 'Y', null, null, null, 200000036) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000032, 1, 200000036, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 3, 200000036) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000032, 1, 200000036, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 3, 200000036, 1) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000033, 2, 200000036, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 3, 200000036) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000033, 2, 200000036, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 3, 200000036, 2) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000034, 3, 200000036, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 3, 200000036) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000034, 3, 200000036, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 3, 200000036, 3) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000096, '1234 TEST-0026', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') diff --git a/mhr_api/test_data/postgres_data_files/test0007.sql b/mhr_api/test_data/postgres_data_files/test0007.sql index 1463814b1..a37b13b7c 100644 --- a/mhr_api/test_data/postgres_data_files/test0007.sql +++ b/mhr_api/test_data/postgres_data_files/test0007.sql @@ -47,8 +47,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000037, 'REG_101', 200000037, 'UT000037', '90499037', 'attn', NULL, NULL, 'Y', null, null, null, 200000037) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000035, 1, 200000037, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000037) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000035, 1, 200000037, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000037, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000101, '1234 TEST-0027', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -147,8 +147,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000039, 'REG_101', 200000039, 'UT000039', '90499039', 'attn', NULL, NULL, 'Y', null, null, null, 200000039) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000036, 1, 200000039, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000039) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000036, 1, 200000039, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000039, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000107, '1234 TEST-0028', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -201,8 +201,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000040, 'REG_101', 200000040, 'UT000040', '90499040', 'attn', NULL, NULL, 'Y', null, null, null, 200000040) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000037, 1, 200000040, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000040) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000037, 1, 200000040, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000040, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000110, '1234 TEST-0029', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -281,12 +281,12 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000042, 'REG_101', 200000042, 'UT000042', '90499042', 'attn', NULL, NULL, 'Y', null, null, null, 200000042) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000038, 1, 200000042, 'ACTIVE', 'NA', 'UNDIVIDED', 'Y', 1, 2, 200000042) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000038, 1, 200000042, 'ACTIVE', 'NA', 'UNDIVIDED', 'Y', 1, 2, 200000042, 1) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000039, 2, 200000042, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 2, 200000042) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000039, 2, 200000042, 'ACTIVE', 'COMMON', 'UNDIVIDED', 'Y', 1, 2, 200000042, 2) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000114, '1234 TEST-0030', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -349,8 +349,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000043, 'REG_101', 200000043, 'UT000043', '90499043', 'attn', NULL, NULL, 'Y', null, null, null, 200000043) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000040, 1, 200000043, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000043) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000040, 1, 200000043, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000043, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000118, '1234 TEST-0031', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') @@ -449,8 +449,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000045, 'REG_101', 200000045, 'UT000045', '90499045', 'attn', NULL, NULL, 'Y', null, null, null, 200000045) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000041, 1, 200000045, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000045) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000041, 1, 200000045, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000045, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000124, '1234 TEST-0032', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') diff --git a/mhr_api/test_data/postgres_data_files/test0008.sql b/mhr_api/test_data/postgres_data_files/test0008.sql index 18be4d859..39b11e432 100644 --- a/mhr_api/test_data/postgres_data_files/test0008.sql +++ b/mhr_api/test_data/postgres_data_files/test0008.sql @@ -40,8 +40,8 @@ INSERT INTO mhr_documents(id, document_type, registration_id, document_id, docum VALUES(200000047, 'REG_101', 200000047, 'UT000047', '90499047', 'attn', NULL, NULL, 'Y', null, null, null, 200000047) ; INSERT INTO mhr_owner_groups(id, sequence_number, registration_id, status_type, tenancy_type, interest, - tenancy_specified, interest_numerator, interest_denominator, change_registration_id) - VALUES(200000042, 1, 200000047, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000047) + tenancy_specified, interest_numerator, interest_denominator, change_registration_id, group_sequence_number) + VALUES(200000042, 1, 200000047, 'ACTIVE', 'SOLE', NULL, 'Y', NULL, NULL, 200000047, 1) ; INSERT INTO addresses(id, street, street_additional, city, region, postal_code, country) VALUES(190000130, '1234 TEST-0033', NULL, 'CITY', 'BC', 'V8R 3A5', 'CA') diff --git a/mhr_api/tests/unit/models/db2/test_owngroup.py b/mhr_api/tests/unit/models/db2/test_owngroup.py index 371106b6f..50544166f 100644 --- a/mhr_api/tests/unit/models/db2/test_owngroup.py +++ b/mhr_api/tests/unit/models/db2/test_owngroup.py @@ -210,6 +210,7 @@ def test_owngroup_json(session, tenancy_type, legacy_tenancy_type): test_json = { 'groupId': owngroup.group_id, + 'groupSequenceNumber': owngroup.sequence_number, 'type': tenancy_type, 'status': 'PREVIOUS', 'interest': 'UNDIVIDED', @@ -241,6 +242,7 @@ def test_owngroup_reg_json(session, tenancy_type, legacy_tenancy_type): test_json = { 'groupId': owngroup.group_id, + 'groupSequenceNumber': owngroup.sequence_number, 'type': tenancy_type, 'status': 'ACTIVE', 'interest': 'UNDIVIDED', diff --git a/mhr_api/tests/unit/models/test_mhr_owner_group.py b/mhr_api/tests/unit/models/test_mhr_owner_group.py index 6c6c999fb..d0d5b373f 100644 --- a/mhr_api/tests/unit/models/test_mhr_owner_group.py +++ b/mhr_api/tests/unit/models/test_mhr_owner_group.py @@ -37,7 +37,8 @@ interest='UNDIVIDED', interest_numerator=1, interest_denominator=2, - tenancy_specified='Y') + tenancy_specified='Y', + group_sequence_number=1) @pytest.mark.parametrize('id, has_results', TEST_ID_DATA) @@ -56,6 +57,7 @@ def test_find_by_id(session, id, has_results): assert group.interest == 'UNDIVIDED' assert group.interest_numerator == 1 assert group.interest_denominator == 2 + assert group.group_sequence_number == 1 else: assert not group @@ -77,6 +79,7 @@ def test_find_by_registration_id(session, id, has_results): assert group.interest == 'UNDIVIDED' assert group.interest_numerator == 1 assert group.interest_denominator == 2 + assert group.group_sequence_number == 1 else: assert not groups @@ -97,6 +100,7 @@ def test_find_by_change_registration_id(session, id, has_results): assert group.interest == 'UNDIVIDED' assert group.interest_numerator == 1 assert group.interest_denominator == 2 + assert group.group_sequence_number == 1 else: assert not groups @@ -106,6 +110,7 @@ def test_group_json(session): group: MhrOwnerGroup = TEST_GROUP group_json = { 'groupId': group.group_id, + 'groupSequenceNumber': group.group_sequence_number, 'type': group.tenancy_type, 'status': group.status_type, 'tenancySpecified': True, diff --git a/mhr_api/tests/unit/models/test_mhr_registration.py b/mhr_api/tests/unit/models/test_mhr_registration.py index 855eb90dd..a0f1a48bd 100755 --- a/mhr_api/tests/unit/models/test_mhr_registration.py +++ b/mhr_api/tests/unit/models/test_mhr_registration.py @@ -1006,6 +1006,8 @@ def test_create_transfer_from_json(session, mhr_num, user_group, doc_id_prefix, sub_party = registration.parties[0] assert sub_party.registration_id == registration.id assert sub_party.party_type == MhrPartyTypes.SUBMITTING + for group in registration.owner_groups: + assert group.group_sequence_number if model_utils.is_legacy(): assert registration.manuhome @@ -1052,6 +1054,7 @@ def test_create_transfer_death_from_json(session, mhr_num, user_group, account_i assert registration.draft.account_id == registration.account_id assert registration.parties for group in registration.owner_groups: + assert group.group_sequence_number if group.modified: for owner in group.owners: if reg_type == MhrRegistrationTypes.TRAND: @@ -1394,6 +1397,7 @@ def test_create_new_groups(session, type, group_count, owner_count, denominator, assert group.change_registration_id == 1000 assert group.tenancy_type == type assert group.status_type == MhrOwnerStatusTypes.ACTIVE + assert group.group_sequence_number assert group.owners own_count += len(group.owners) if denominator: diff --git a/mhr_api/tests/unit/models/test_registration_utils.py b/mhr_api/tests/unit/models/test_registration_utils.py index e807200e5..acffbd7da 100644 --- a/mhr_api/tests/unit/models/test_registration_utils.py +++ b/mhr_api/tests/unit/models/test_registration_utils.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Test Suite to ensure the model utility functions are working as expected.""" +import copy from datetime import timedelta as _timedelta import pytest @@ -19,9 +20,52 @@ from flask import current_app from mhr_api.models import utils as model_utils, queries, registration_utils as reg_utils +from mhr_api.models import registration_json_utils as reg_json_utils from mhr_api.models.registration_utils import AccountRegistrationParams +GROUP_1 = { + 'groupId': 12, + 'groupSequenceNumber': 1, + 'type': 'NA', + 'status': 'ACTIVE', + 'tenancySpecified': True, + 'interest': 'UNDIVIDED', + 'interestNumerator': 1, + 'interestDenominator': 3, + 'owners': [] +} +GROUP_2 = { + 'groupId': 13, + 'groupSequenceNumber': 2, + 'type': 'NA', + 'status': 'ACTIVE', + 'tenancySpecified': True, + 'interest': 'UNDIVIDED', + 'interestNumerator': 1, + 'interestDenominator': 3, + 'owners': [] +} +GROUP_3 = { + 'groupId': 14, + 'groupSequenceNumber': 3, + 'type': 'NA', + 'status': 'ACTIVE', + 'tenancySpecified': True, + 'interest': 'UNDIVIDED', + 'interestNumerator': 1, + 'interestDenominator': 3, + 'owners': [] +} +# testdata pattern is ({group1}, {group2}, {group3}) +TEST_COMMON_GROUP_SORT = [ + (GROUP_1, GROUP_2, GROUP_3), + (GROUP_3, GROUP_1, GROUP_2), + (GROUP_2, GROUP_1, GROUP_3), + (GROUP_2, GROUP_3, GROUP_1), + (GROUP_3, GROUP_2, GROUP_1), + (GROUP_1, GROUP_3, GROUP_2) +] # testdata pattern is ({start_ts}, {end_ts}) TEST_DATA_MANUFACTURER_MHREG = [ ('2023-05-25T07:01:00+00:00', '2023-05-26T07:01:00+00:00'), @@ -105,6 +149,23 @@ ] +@pytest.mark.parametrize('group1,group2,group3', TEST_COMMON_GROUP_SORT) +def test_common_group_sort(session, group1, group2, group3): + """Assert that sorting tenants in common owner groups works as expected.""" + groups = [] + groups.append(copy.deepcopy(group1)) + groups.append(copy.deepcopy(group2)) + groups.append(copy.deepcopy(group3)) + sorted_groups = reg_json_utils.sort_owner_groups(groups, True) + assert len(sorted_groups) == 3 + assert 'groupSequenceNumber' not in sorted_groups[0] + assert 'groupSequenceNumber' not in sorted_groups[1] + assert 'groupSequenceNumber' not in sorted_groups[2] + assert sorted_groups[0].get('groupId') == 12 + assert sorted_groups[1].get('groupId') == 13 + assert sorted_groups[2].get('groupId') == 14 + + @pytest.mark.parametrize('start_ts,end_ts', TEST_DATA_MANUFACTURER_MHREG) def test_get_batch_manufacturer_reg_report_data(session, start_ts, end_ts): """Assert that fetching manufacturer MHREG data by optional timestamp range works as expected.""" diff --git a/ppr-api/src/ppr_api/models/registration.py b/ppr-api/src/ppr_api/models/registration.py index 940e8ce6e..585afd46f 100644 --- a/ppr-api/src/ppr_api/models/registration.py +++ b/ppr-api/src/ppr_api/models/registration.py @@ -528,10 +528,10 @@ def find_summary_by_reg_num(cls, account_id: str, registration_num: str, account result['statusType'] = model_utils.STATE_EXPIRED # Another account already added. - if result['existsCount'] > 0 and result['accountId'] != account_id: + if result['existsCount'] > 0 and result['accountId'] not in (account_id, account_id + '_R'): result['inUserList'] = True # User account previously removed (can be added back). - elif result['existsCount'] > 0 and result['accountId'] == account_id: + elif result['existsCount'] > 0 and result['accountId'] in (account_id, account_id + '_R'): result['inUserList'] = False # User account added by default. elif result['accountId'] == account_id: