Skip to content

Commit

Permalink
Merge pull request bcgov#46 from turb0c0w/tyler/auto_approval_changes
Browse files Browse the repository at this point in the history
changes to auto approval logic around address check
  • Loading branch information
turb0c0w authored Jul 9, 2024
2 parents 6e5bc1c + fa42954 commit a9f5589
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 66 deletions.
1 change: 0 additions & 1 deletion strr-api/src/strr_api/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ def compare_addresses(property_address: Address, sbc_address: SBCMailingAddress)
and property_address.postal_code.lower().replace(" ", "") == sbc_address.postalCode.lower().replace(" ", "")
and property_address.country.lower() == sbc_address.country.lower()
)
print(f"result: {result}")
return result
126 changes: 64 additions & 62 deletions strr-api/src/strr_api/services/approval_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def process_approval(cls, token, registration: models.Registration):
renting = registration.rental_property.ownership_type == OwnershipType.RENT.name
other_service_provider = registration.eligibility.specified_service_provider is not None
pr_exempt = not registration.eligibility.is_principal_residence
bn_provided = registration.rental_property.property_manager.primary_contact.business_number is not None
bl_provided = registration.rental_property.local_business_licence is not None
bcsc_address = AuthService.get_sbc_accounts_mailing_address(token, registration.sbc_account_id)

# Status setting just temporary for visibility
Expand Down Expand Up @@ -146,58 +146,6 @@ def process_approval(cls, token, registration: models.Registration):

if not pr_exempt:
auto_approval.pr_exempt = False
geocode_response = GeoCoderService.get_geocode_by_address(address)
longitude, latitude = cls.extract_longitude_and_latitude(geocode_response)
organization = models.DSSOrganization.lookup_by_geocode(longitude, latitude)
if organization["is_business_licence_required"]:
auto_approval.business_license_required = True
if bn_provided:
auto_approval.business_license_required_provided = True
else:
auto_approval.business_license_required_not_provided = True
registration.status = RegistrationStatus.UNDER_REVIEW
registration.save()
EventRecordsService.save_event_record(
EventRecordType.AUTO_APPROVAL_FULL_REVIEW,
EventRecordType.AUTO_APPROVAL_FULL_REVIEW.value,
True,
registration.user_id,
registration.id,
)
return auto_approval
else:
auto_approval.business_license_not_required_not_provided = True

if pid:
ltsa_data = LtsaService.get_title_details_from_pid(pid)
ltsa_response = LtsaService.build_ltsa_response(registration.id, ltsa_data)
owner_title_match = cls.check_full_name_exists_in_ownership_groups(ltsa_response, owner_name)
else:
owner_title_match = False
if owner_title_match:
auto_approval.title_check = True
registration.status = RegistrationStatus.PROVISIONAL
registration.save()
EventRecordsService.save_event_record(
EventRecordType.AUTO_APPROVAL_PROVISIONAL,
EventRecordType.AUTO_APPROVAL_PROVISIONAL.value,
True,
registration.user_id,
registration.id,
)
else:
auto_approval.title_check = False
registration.status = RegistrationStatus.UNDER_REVIEW
registration.save()
EventRecordsService.save_event_record(
EventRecordType.AUTO_APPROVAL_FULL_REVIEW,
EventRecordType.AUTO_APPROVAL_FULL_REVIEW.value,
True,
registration.user_id,
registration.id,
)
return auto_approval
else:
if not compare_addresses(registration.rental_property.address, bcsc_address):
auto_approval.address_match = False
registration.status = RegistrationStatus.UNDER_REVIEW
Expand All @@ -215,29 +163,83 @@ def process_approval(cls, token, registration: models.Registration):
geocode_response = GeoCoderService.get_geocode_by_address(address)
longitude, latitude = cls.extract_longitude_and_latitude(geocode_response)
organization = models.DSSOrganization.lookup_by_geocode(longitude, latitude)
if organization["is_principal_residence_required"]:
auto_approval.pr_exempt = False
registration.status = RegistrationStatus.UNDER_REVIEW
if organization["is_business_licence_required"]:
auto_approval.business_license_required = True
if bl_provided:
auto_approval.business_license_required_provided = True
else:
auto_approval.business_license_required_not_provided = True
registration.status = RegistrationStatus.UNDER_REVIEW
registration.save()
EventRecordsService.save_event_record(
EventRecordType.AUTO_APPROVAL_FULL_REVIEW,
EventRecordType.AUTO_APPROVAL_FULL_REVIEW.value,
True,
registration.user_id,
registration.id,
)
return auto_approval
else:
auto_approval.business_license_not_required_not_provided = True

if pid:
ltsa_data = LtsaService.get_title_details_from_pid(pid)
ltsa_response = LtsaService.build_ltsa_response(registration.id, ltsa_data)
owner_title_match = cls.check_full_name_exists_in_ownership_groups(
ltsa_response, owner_name
)
else:
owner_title_match = False
if owner_title_match:
auto_approval.title_check = True
registration.status = RegistrationStatus.PROVISIONAL
registration.save()
EventRecordsService.save_event_record(
EventRecordType.AUTO_APPROVAL_FULL_REVIEW,
EventRecordType.AUTO_APPROVAL_FULL_REVIEW.value,
EventRecordType.AUTO_APPROVAL_PROVISIONAL,
EventRecordType.AUTO_APPROVAL_PROVISIONAL.value,
True,
registration.user_id,
registration.id,
)
else:
auto_approval.pr_exempt = True
registration.status = RegistrationStatus.PROVISIONAL
auto_approval.title_check = False
registration.status = RegistrationStatus.UNDER_REVIEW
registration.save()
EventRecordsService.save_event_record(
EventRecordType.AUTO_APPROVAL_APPROVED,
EventRecordType.AUTO_APPROVAL_APPROVED.value,
EventRecordType.AUTO_APPROVAL_FULL_REVIEW,
EventRecordType.AUTO_APPROVAL_FULL_REVIEW.value,
True,
registration.user_id,
registration.id,
)
return auto_approval
else:
geocode_response = GeoCoderService.get_geocode_by_address(address)
longitude, latitude = cls.extract_longitude_and_latitude(geocode_response)
organization = models.DSSOrganization.lookup_by_geocode(longitude, latitude)
if organization["is_principal_residence_required"]:
auto_approval.pr_exempt = False
registration.status = RegistrationStatus.UNDER_REVIEW
registration.save()
EventRecordsService.save_event_record(
EventRecordType.AUTO_APPROVAL_FULL_REVIEW,
EventRecordType.AUTO_APPROVAL_FULL_REVIEW.value,
True,
registration.user_id,
registration.id,
)
else:
auto_approval.pr_exempt = True
registration.status = RegistrationStatus.APPROVED
registration.save()
EventRecordsService.save_event_record(
EventRecordType.AUTO_APPROVAL_APPROVED,
EventRecordType.AUTO_APPROVAL_APPROVED.value,
True,
registration.user_id,
registration.id,
)
return auto_approval
except Exception as default_exception: # noqa: B902; log error
current_app.logger.error("error in approval logoic:" + repr(default_exception))
current_app.logger.error(auto_approval)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
"dateOfBirth": "1986-10-23",
"socialInsuranceNumber": "666666666",
"businessNumber": "123456789",
"details": {
"phoneNumber": "604-999-9999",
"emailAddress": "test@test.test"
Expand All @@ -25,6 +24,7 @@
},
"unitDetails": {
"parcelIdentifier": "018-850-570",
"businessLicense": "7777777",
"propertyType": "PRIMARY",
"ownershipType": "OWN"
},
Expand All @@ -38,8 +38,7 @@
"listingDetails": [
],
"principalResidence": {
"isPrincipalResidence": false,
"nonPrincipalOption": "OTHER",
"isPrincipalResidence": true,
"agreedToRentalAct": true,
"agreedToSubmit": true
}
Expand Down

0 comments on commit a9f5589

Please sign in to comment.