-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HOTFIX] 207915: mass withdraw households and individuals from sudan (#…
…4041) * mass withdraw households and individuals from sudan * rename file
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+5.52 MB
backend/hct_mis_api/one_time_scripts/files/mass_withdraw_sudan_hhs.xlsx
Binary file not shown.
26 changes: 26 additions & 0 deletions
26
backend/hct_mis_api/one_time_scripts/mass_withdraw_sudan_hhs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
80 changes: 80 additions & 0 deletions
80
backend/hct_mis_api/one_time_scripts/tests/test_mass_withdraw_sudan_hhs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |