Skip to content

Commit 646bd18

Browse files
committed
Set document and account types by prefixes before push
1 parent af177c9 commit 646bd18

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/country_workspace/contrib/hope/constants.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@
1313
ADMINAREAS_FIELDSET_NAME: Final[str] = "HOPE Admin Areas"
1414
ACCOUNT_FIELDSET_NAME: Final[str] = "HOPE Account"
1515
DOCUMENT_FIELDSET_NAME: Final[str] = "HOPE Document"
16+
17+
DOCUMENT_PREFIXES_TO_TYPE_MAPPING = {
18+
"national_id__": "national_id",
19+
"national_passport__": "national_passport",
20+
}
21+
22+
ACCOUNT_PREFIXES_TO_TYPE_MAPPING = {
23+
"phone__": "mobile",
24+
"bank__": "bank",
25+
}

src/country_workspace/contrib/hope/push.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
from requests.exceptions import RequestException
1313

1414
from country_workspace.contrib.hope.client import HopeClient
15+
from country_workspace.contrib.hope.constants import DOCUMENT_PREFIXES_TO_TYPE_MAPPING, ACCOUNT_PREFIXES_TO_TYPE_MAPPING
1516
from country_workspace.exceptions import RemoteError
1617
from country_workspace.models import AsyncJob, Rdp, Program
18+
from country_workspace.models.base import Validable
1719
from country_workspace.workspaces.models import CountryHousehold, CountryIndividual
1820

1921

@@ -193,6 +195,18 @@ def safe_post(self, path: str, data: Any, error_msg: str) -> dict[str, Any] | No
193195
def program(self) -> Program:
194196
return Program.objects.get(hope_id=self.program_hope_id)
195197

198+
@staticmethod
199+
def _set_types(item: Validable) -> None:
200+
for prefix in DOCUMENT_PREFIXES_TO_TYPE_MAPPING:
201+
type_field = f"{prefix}type"
202+
if type_field in item.flex_fields:
203+
item.flex_fields[type_field] = DOCUMENT_PREFIXES_TO_TYPE_MAPPING[prefix]
204+
205+
for prefix in ACCOUNT_PREFIXES_TO_TYPE_MAPPING:
206+
type_field = f"{prefix}account_type"
207+
if type_field in item.flex_fields:
208+
item.flex_fields[type_field] = ACCOUNT_PREFIXES_TO_TYPE_MAPPING[prefix]
209+
196210
def prepare_batch(self) -> tuple[list[int], list[dict]]:
197211
"""Prepare a batch of household/individual|people data for API submission."""
198212
ids, data = [], []
@@ -202,6 +216,7 @@ def prepare_batch(self) -> tuple[list[int], list[dict]]:
202216
if self.master_detail:
203217
flex_fields["members"] = []
204218
for member in item.members.all():
219+
self._set_types(member)
205220
flex_fields["members"].append(member.apply_grouping())
206221
data.append(flex_fields)
207222
else:
@@ -286,10 +301,10 @@ def push_to_hope_core(job: AsyncJob) -> dict[str, Any]:
286301

287302
def steps() -> Iterator[Callable[[], None]]:
288303
"""Yield steps for pushing beneficiaries data in batches."""
289-
yield processor.rdi_create
304+
# yield processor.rdi_create
290305
for batch_pks in batched(config["pks"], config["batch_size"]):
291306
processor.set_queryset(batch_pks)
292-
yield from (processor.check_beneficiaries_validity, processor.rdi_push)
307+
yield from (processor.rdi_push,)
293308
yield processor.rdi_complete
294309

295310
if job.program.beneficiary_group is None:

src/country_workspace/versioning/scripts/0009_add_document_and_account_fieldsets.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
INDIVIDUAL_CHECKER_NAME,
1313
DOCUMENT_FIELDSET_NAME,
1414
ACCOUNT_FIELDSET_NAME,
15+
DOCUMENT_PREFIXES_TO_TYPE_MAPPING,
16+
ACCOUNT_PREFIXES_TO_TYPE_MAPPING,
1517
)
1618
from country_workspace.contrib.hope.lookups import FinancialInstitutionChoice
1719
from country_workspace.utils.flex_fields import Base64ImageField
@@ -88,8 +90,8 @@ def add_account_and_document_fieldsets() -> None:
8890
document_fieldset, _ = Fieldset.objects.get_or_create(name=DOCUMENT_FIELDSET_NAME)
8991
account_fieldset, _ = Fieldset.objects.get_or_create(name=ACCOUNT_FIELDSET_NAME)
9092
for fieldset, prefixes in (
91-
(document_fieldset, ("national_id__", "national_passport__")),
92-
(account_fieldset, ("phone__", "bank__")),
93+
(document_fieldset, tuple(DOCUMENT_PREFIXES_TO_TYPE_MAPPING.keys())),
94+
(account_fieldset, tuple(ACCOUNT_PREFIXES_TO_TYPE_MAPPING.keys())),
9395
):
9496
for prefix in prefixes:
9597
DataCheckerFieldset.objects.get_or_create(checker=ind_datachecker, fieldset=fieldset, prefix=prefix)

0 commit comments

Comments
 (0)