From fa429545fe947fd138e2ab2ea1a820dfb31e84f4 Mon Sep 17 00:00:00 2001 From: Tyler Zale Date: Tue, 9 Jul 2024 11:33:29 -0700 Subject: [PATCH] changes to auto approval logic around address check --- strr-api/src/strr_api/common/utils.py | 1 - .../src/strr_api/services/approval_service.py | 126 +++++++++--------- .../registration_use_sbc_account_ltsa.json | 5 +- 3 files changed, 66 insertions(+), 66 deletions(-) diff --git a/strr-api/src/strr_api/common/utils.py b/strr-api/src/strr_api/common/utils.py index 4df89aa7..491ef431 100644 --- a/strr-api/src/strr_api/common/utils.py +++ b/strr-api/src/strr_api/common/utils.py @@ -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 diff --git a/strr-api/src/strr_api/services/approval_service.py b/strr-api/src/strr_api/services/approval_service.py index a19d32bf..c1fe76dc 100644 --- a/strr-api/src/strr_api/services/approval_service.py +++ b/strr-api/src/strr_api/services/approval_service.py @@ -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 @@ -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 @@ -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) diff --git a/strr-api/tests/mocks/json/registration_use_sbc_account_ltsa.json b/strr-api/tests/mocks/json/registration_use_sbc_account_ltsa.json index 1d1c3046..90d87d1c 100644 --- a/strr-api/tests/mocks/json/registration_use_sbc_account_ltsa.json +++ b/strr-api/tests/mocks/json/registration_use_sbc_account_ltsa.json @@ -10,7 +10,6 @@ }, "dateOfBirth": "1986-10-23", "socialInsuranceNumber": "666666666", - "businessNumber": "123456789", "details": { "phoneNumber": "604-999-9999", "emailAddress": "test@test.test" @@ -25,6 +24,7 @@ }, "unitDetails": { "parcelIdentifier": "018-850-570", + "businessLicense": "7777777", "propertyType": "PRIMARY", "ownershipType": "OWN" }, @@ -38,8 +38,7 @@ "listingDetails": [ ], "principalResidence": { - "isPrincipalResidence": false, - "nonPrincipalOption": "OTHER", + "isPrincipalResidence": true, "agreedToRentalAct": true, "agreedToSubmit": true }