diff --git a/backend/hct_mis_api/apps/grievance/services/needs_adjudication_ticket_services.py b/backend/hct_mis_api/apps/grievance/services/needs_adjudication_ticket_services.py index 3c5881b1ee..cccff32fca 100644 --- a/backend/hct_mis_api/apps/grievance/services/needs_adjudication_ticket_services.py +++ b/backend/hct_mis_api/apps/grievance/services/needs_adjudication_ticket_services.py @@ -73,7 +73,6 @@ def close_needs_adjudication_old_ticket(ticket_details: TicketNeedsAdjudicationD def close_needs_adjudication_new_ticket(ticket_details: TicketNeedsAdjudicationDetails, user: AbstractUser) -> None: - # TODO: need to double check all this logic here validate_all_individuals_before_close_needs_adjudication(ticket_details) distinct_individuals = ticket_details.selected_distinct.all() @@ -86,7 +85,7 @@ def close_needs_adjudication_new_ticket(ticket_details: TicketNeedsAdjudicationD if distinct_individuals: for individual_to_distinct in distinct_individuals: - mark_as_distinct_and_reassign_roles(ticket_details, individual_to_distinct, user) + mark_as_distinct_individual(individual_to_distinct, user, ticket_details.ticket.programs.all()) _clear_deduplication_individuals_fields(distinct_individuals) @@ -250,27 +249,6 @@ def mark_as_duplicate_individual_and_reassign_roles( ) -def mark_as_distinct_and_reassign_roles( - ticket_details: TicketNeedsAdjudicationDetails, - individual_to_distinct: Individual, - user: AbstractUser, -) -> None: - # TODO: HAVE to update this logic - if ticket_details.is_multiple_duplicates_version: - household = reassign_roles_on_disable_individual_service( - individual_to_distinct, - ticket_details.role_reassign_data, - user, - ticket_details.ticket.programs.all(), - "new_individual", - ) - else: - household = reassign_roles_on_disable_individual_service( - individual_to_distinct, ticket_details.role_reassign_data, user, ticket_details.ticket.programs.all() - ) - mark_as_distinct_individual(individual_to_distinct, household, user, ticket_details.ticket.programs.all()) - - def mark_as_duplicate_individual( individual_to_remove: Individual, unique_individual: Optional[Individual], @@ -279,7 +257,6 @@ def mark_as_duplicate_individual( program: "Program", ) -> None: old_individual = Individual.objects.get(id=individual_to_remove.id) - # TODO: who is unique_individual is more then 1 was selected.. or none just individual_to_remove.mark_as_duplicate(unique_individual) log_create( Individual.ACTIVITY_LOG_MAPPING, @@ -298,12 +275,10 @@ def mark_as_duplicate_individual( def mark_as_distinct_individual( individual_to_distinct: Individual, - household: Optional[Household], user: AbstractUser, program: "Program", ) -> None: old_individual = Individual.objects.get(id=individual_to_distinct.id) - # TODO: who is unique_individual is more then 1 was selected.. or just None individual_to_distinct.mark_as_distinct() log_create( Individual.ACTIVITY_LOG_MAPPING, @@ -314,7 +289,7 @@ def mark_as_distinct_individual( individual_to_distinct, ) individual_marked_as_distinct.send(sender=Individual, instance=individual_to_distinct) - if household: - household.refresh_from_db() - if household.active_individuals.count() > 0: - household.unwithdraw() + household = individual_to_distinct.household + household.refresh_from_db() + if household.active_individuals.count() > 0: + household.unwithdraw() diff --git a/backend/hct_mis_api/apps/grievance/utils.py b/backend/hct_mis_api/apps/grievance/utils.py index 6763ffb842..25fdd0a533 100644 --- a/backend/hct_mis_api/apps/grievance/utils.py +++ b/backend/hct_mis_api/apps/grievance/utils.py @@ -34,7 +34,7 @@ def get_individual(individual_id: str) -> Individual: def traverse_sibling_tickets(grievance_ticket: GrievanceTicket, selected_individuals: QuerySet[Individual]) -> None: - # TODO: what we have to do here with 'selected_distinct' + # TODO: what we have to do here with 'selected_distinct' ??? rdi = grievance_ticket.registration_data_import if not rdi: return @@ -222,16 +222,19 @@ def validate_all_individuals_before_close_needs_adjudication(ticket_details: Tic duplicates_qs = ticket_details.selected_individuals.all() distinct_qs = ticket_details.selected_distinct.all() - # A user can flag all active individuals as duplicates but won’t be able to resolve (close) the ticket + # A user can flag all active individuals as duplicates but won’t be able to close the ticket if distinct_qs.count() == 0: raise ValidationError("Close ticket is not possible when all Individuals are flagged as duplicates") if not [individual for individual in distinct_qs if not individual.withdrawn] or duplicates_qs.count() == 0: raise ValidationError( - "Close ticket is possible when at least one individual is flagged as distinct or one of the individuals is inactive (withdrawn or duplicate)" + "Close ticket is possible when at least one individual is flagged as distinct or one of the individuals is withdrawn" ) - # all active individuals are flagged # TODO: have to check this requirement?????????? - for individual in ticket_details.possible_duplicates.all(): - if not individual.withdrawn and individual not in duplicates_qs or individual not in distinct_qs: + all_possible_duplicates = list(ticket_details.possible_duplicates.all()) + [ + ticket_details.golden_records_individual + ] + + for individual in all_possible_duplicates: + if not individual.withdrawn or individual not in duplicates_qs or individual not in distinct_qs: raise ValidationError("Close ticket is possible when all active Individuals are flagged") diff --git a/backend/hct_mis_api/apps/household/models.py b/backend/hct_mis_api/apps/household/models.py index 9392a4bd47..cdc6b6aa3a 100644 --- a/backend/hct_mis_api/apps/household/models.py +++ b/backend/hct_mis_api/apps/household/models.py @@ -1164,9 +1164,7 @@ def mark_as_duplicate(self, original_individual: Optional["Individual"] = None) self.duplicate_date = timezone.now() self.save() - def mark_as_distinct(self, original_individual: Optional["Individual"] = None) -> None: - if original_individual is not None: - self.unicef_id = str(original_individual.unicef_id) + def mark_as_distinct(self) -> None: self.documents.update(status=Document.STATUS_VALID) self.duplicate = False self.duplicate_date = timezone.now()