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

[HOTFIX] 207915: mass withdraw households and individuals from sudan #4041

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Binary file not shown.
26 changes: 26 additions & 0 deletions backend/hct_mis_api/one_time_scripts/mass_withdraw_sudan_hhs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pathlib import Path

import openpyxl

from hct_mis_api.apps.grievance.models import GrievanceTicket
from hct_mis_api.apps.household.models import Household
from hct_mis_api.apps.household.services.household_withdraw import HouseholdWithdraw


def mass_withdraw_sudan_hhs() -> None:
# get the file path to mass_withdraw_sudan_hhs.xlsx
file_path = Path(__file__).resolve().parent / "files" / "mass_withdraw_sudan_hhs.xlsx"
workbook = openpyxl.load_workbook(file_path)
sheet = workbook.active
for row in sheet.iter_rows(min_row=2, values_only=True):
unicef_id = row[0]
if not unicef_id:
break
household = Household.objects.filter(unicef_id=unicef_id, withdrawn=False, program__isnull=False).first()
tag = row[1]
if household:
tickets = GrievanceTicket.objects.belong_household(household)
tickets = filter(lambda t: t.ticket.status != GrievanceTicket.STATUS_CLOSED, tickets)
service = HouseholdWithdraw(household)
service.withdraw(tag=tag)
service.change_tickets_status(tickets)
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from django.test import TestCase

from hct_mis_api.apps.core.fixtures import create_afghanistan
from hct_mis_api.apps.grievance.fixtures import GrievanceTicketFactory
from hct_mis_api.apps.grievance.models import (
GrievanceTicket,
TicketComplaintDetails,
TicketIndividualDataUpdateDetails,
)
from hct_mis_api.apps.household.fixtures import (
DocumentFactory,
create_household_and_individuals,
)
from hct_mis_api.apps.household.models import Document
from hct_mis_api.apps.program.fixtures import ProgramFactory
from hct_mis_api.one_time_scripts.mass_withdraw_sudan_hhs import mass_withdraw_sudan_hhs


class TestMassWithdrawSudanHhs(TestCase):
@classmethod
def setUpTestData(cls) -> None:
business_area = create_afghanistan()
cls.program = ProgramFactory(business_area=business_area)
cls.household, cls.individuals = create_household_and_individuals(
household_data={
"business_area": business_area,
"program": cls.program,
"unicef_id": "HH-20-0192.6628",
},
individuals_data=[{}],
)
cls.document = DocumentFactory(
individual=cls.individuals[0],
program=cls.program,
)

cls.grievance_ticket = GrievanceTicketFactory(status=GrievanceTicket.STATUS_IN_PROGRESS)
cls.ticket_complaint_details = TicketComplaintDetails.objects.create(
ticket=cls.grievance_ticket,
household=cls.household,
)
cls.grievance_ticket2 = GrievanceTicketFactory(status=GrievanceTicket.STATUS_IN_PROGRESS)
cls.ticket_individual_data_update = TicketIndividualDataUpdateDetails.objects.create(
ticket=cls.grievance_ticket2,
individual=cls.individuals[0],
)

def test_mass_withdraw_sudan_hhs(self) -> None:
mass_withdraw_sudan_hhs()

self.household.refresh_from_db()
self.individuals[0].refresh_from_db()
self.document.refresh_from_db()
self.grievance_ticket.refresh_from_db()
self.grievance_ticket2.refresh_from_db()

self.assertEqual(
self.household.withdrawn,
True,
)
self.assertEqual(
self.household.user_fields["withdrawn_tag"],
"Received Full entitlements",
)
self.assertEqual(
self.individuals[0].withdrawn,
True,
)
self.assertEqual(
self.document.status,
Document.STATUS_INVALID,
)
self.assertEqual(
self.grievance_ticket.status,
GrievanceTicket.STATUS_CLOSED,
)
self.assertEqual(
self.grievance_ticket2.status,
GrievanceTicket.STATUS_CLOSED,
)
Loading