diff --git a/pyproject.toml b/pyproject.toml index 0644a75878..d84337f4c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -141,7 +141,7 @@ distribution = true [project] name = "hope" -version = "2.12.1" +version = "2.12.2" description = "HCT MIS is UNICEF's humanitarian cash transfer platform." authors = [ { name = "Tivix" }, diff --git a/src/hct_mis_api/apps/grievance/services/needs_adjudication_ticket_services.py b/src/hct_mis_api/apps/grievance/services/needs_adjudication_ticket_services.py index de0065c09d..3350faf786 100644 --- a/src/hct_mis_api/apps/grievance/services/needs_adjudication_ticket_services.py +++ b/src/hct_mis_api/apps/grievance/services/needs_adjudication_ticket_services.py @@ -368,7 +368,7 @@ def mark_as_distinct_individual( individual_to_distinct, ) individual_marked_as_distinct.send(sender=Individual, instance=individual_to_distinct) - household = individual_to_distinct.household - household.refresh_from_db() - if household.active_individuals.count() > 0: - household.unwithdraw() + if household := individual_to_distinct.household: + household.refresh_from_db() + if household.active_individuals.count() > 0: + household.unwithdraw() diff --git a/tests/unit/apps/grievance/test_services_utils.py b/tests/unit/apps/grievance/test_services_utils.py index 08198b31f6..6c6a9ad171 100644 --- a/tests/unit/apps/grievance/test_services_utils.py +++ b/tests/unit/apps/grievance/test_services_utils.py @@ -408,6 +408,53 @@ def test_close_needs_adjudication_ticket_service(self) -> None: assert ind_1.duplicate is False assert ind_2.duplicate is True + def test_close_needs_adjudication_ticket_service_individual_without_household(self) -> None: + user = UserFactory() + ba = BusinessAreaFactory(slug="afghanistan") + program = ProgramFactory(business_area=ba) + + grievance = GrievanceTicketFactory( + category=GrievanceTicket.CATEGORY_NEEDS_ADJUDICATION, + business_area=ba, + status=GrievanceTicket.STATUS_FOR_APPROVAL, + description="GrievanceTicket", + issue_type=GrievanceTicket.ISSUE_TYPE_UNIQUE_IDENTIFIERS_SIMILARITY, + ) + grievance.programs.add(program) + ind_data = { + "given_name": "John", + "family_name": "Doe", + "middle_name": "", + "full_name": "John Doe", + } + ind_1 = IndividualFactory(household=None, program=program, **ind_data) + document = DocumentFactory(individual=ind_1, status=Document.STATUS_INVALID) + _, individuals_2 = create_household( + {"size": 1, "business_area": ba, "program": program}, + ind_data, + ) + ind_2 = individuals_2[0] + + ticket_details = TicketNeedsAdjudicationDetailsFactory( + ticket=grievance, + golden_records_individual=ind_1, + is_multiple_duplicates_version=True, + selected_individual=None, + ) + ticket_details.selected_distinct.set([ind_1, ind_2]) + ticket_details.ticket = grievance + ticket_details.save() + + close_needs_adjudication_ticket_service(grievance, user) + + ind_1.refresh_from_db() + ind_2.refresh_from_db() + document.refresh_from_db() + + self.assertEqual(ind_1.duplicate, False) + self.assertEqual(ind_2.duplicate, False) + self.assertEqual(document.status, Document.STATUS_VALID) + def test_close_needs_adjudication_ticket_service_when_just_duplicates(self) -> None: user = UserFactory() ba = BusinessAreaFactory(slug="afghanistan")