Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[220122] [HOTFIX] Prevent errors when individual has no household #4394

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading