Skip to content

Commit

Permalink
Merge pull request #4413 from unicef/generic-import-admin-area-fix
Browse files Browse the repository at this point in the history
generic-import-admin-area-fix
  • Loading branch information
domdinicola authored Nov 6, 2024
2 parents cd2f1dd + 723c3c1 commit 3ba6c6f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "2.12.1",
"version": "2.12.3",
"private": true,
"type": "module",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,9 @@ def _create_household_dict(cls, data_dict: Dict, mapping_dict: Dict) -> Dict:
my_dict.update(cls._create_household_dict(data_dict[key], mapping_dict[key]))

# update admin areas values
admin2 = cls.get(data_dict, "admin2_h_c")
admin3 = cls.get(data_dict, "admin3_h_c")
admin4 = cls.get(data_dict, "admin4_h_c")

my_dict["admin2"] = str(Area.objects.get(p_code=admin2).id) if admin2 else None
my_dict["admin3"] = str(Area.objects.get(p_code=admin3).id) if admin3 else None
my_dict["admin4"] = str(Area.objects.get(p_code=admin4).id) if admin4 else None

if admin2 and Area.objects.filter(p_code=admin2).exists():
my_dict["admin1"] = str(Area.objects.get(p_code=admin2).parent.id)

if admin4 and Area.objects.filter(p_code=admin4).exists():
my_dict["admin_area"] = str(Area.objects.get(p_code=admin4).id)
elif admin3 and Area.objects.filter(p_code=admin3).exists():
my_dict["admin_area"] = str(Area.objects.get(p_code=admin3).id)
elif admin2 and Area.objects.filter(p_code=admin2).exists():
my_dict["admin_area"] = str(Area.objects.get(p_code=admin2).id)

for key in ["admin1", "admin2", "admin3", "admin4"]:
if key in my_dict and Area.objects.filter(p_code=my_dict[key]).exists():
my_dict[key] = str(Area.objects.get(p_code=my_dict[key]).id)
return my_dict

@staticmethod
Expand Down Expand Up @@ -231,6 +216,7 @@ def create_individuals(
program=household.program,
first_registration_date=record.timestamp,
last_registration_date=record.timestamp,
detail_id=record.source_id,
)

record_data_dict = record.get_data()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ def test_import_data_to_datahub(
self.assertEqual(PendingIndividualRoleInHousehold.objects.filter(role=ROLE_PRIMARY).count(), 1)
self.assertEqual(PendingIndividualRoleInHousehold.objects.filter(role=ROLE_ALTERNATE).count(), 1)

self.assertEqual(pending_household.admin_area.p_code, self.household[0][admin_area_field])

def test_import_data_to_datahub_household_individual(self) -> None:
records = [
Record(
Expand Down

0 comments on commit 3ba6c6f

Please sign in to comment.