Skip to content

Commit

Permalink
Merge pull request #4394 from unicef/prevent-errors-on-closing-ticket…
Browse files Browse the repository at this point in the history
…-forindividual-without-hh

[220122] [HOTFIX] Prevent errors when individual has no household
  • Loading branch information
domdinicola authored Oct 31, 2024
2 parents f1d6db8 + 92b1920 commit 987532c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
47 changes: 47 additions & 0 deletions tests/unit/apps/grievance/test_services_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 987532c

Please sign in to comment.