1212from requests .exceptions import RequestException
1313
1414from 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
1516from country_workspace .exceptions import RemoteError
1617from country_workspace .models import AsyncJob , Rdp , Program
18+ from country_workspace .models .base import Validable
1719from 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 :
0 commit comments