Skip to content

Commit

Permalink
mass withdraw households and individuals from sudan
Browse files Browse the repository at this point in the history
  • Loading branch information
pkujawa committed Jul 12, 2024
1 parent 7561649 commit 11974f0
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
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_withdrawn_sudan_hhs.xlsx
file_path = Path(__file__).resolve().parent / "files" / "mass_withdrawn_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,
)

0 comments on commit 11974f0

Please sign in to comment.