@@ -203,45 +203,66 @@ def _adjust_main_company_details(self):
203203 }
204204 )
205205
206+ def _find_module (self , module_name ):
207+ return self .env .ref (f"base.module_{ module_name } " , raise_if_not_found = False )
208+
209+ def _add_module_if_found (self , res , module_name ):
210+ if module := self ._find_module (module_name ):
211+ res |= module
212+ return res
213+
214+ def _install_spmis_base_modules (self , res ):
215+ for module_name in [
216+ "spp_base" ,
217+ "spp_programs" ,
218+ "spp_change_request" ,
219+ "spp_change_request_change_info" ,
220+ "spp_event_data" ,
221+ ]:
222+ res = self ._add_module_if_found (res , module_name )
223+ return res
224+
225+ def _install_spmis_demo_modules (self , res ):
226+ if self .sp_mis_demo_management == "yes" :
227+ for module_name in ["spp_base_demo" , "spp_mis_demo" ]:
228+ res = self ._add_module_if_found (res , module_name )
229+ return res
230+
231+ def _install_spmis_feature_modules (self , res ):
232+ module_map = {
233+ "location_assignment" : "spp_area" ,
234+ "service_point_management" : "spp_service_points" ,
235+ "cash_transfer_needed" : "spp_entitlement_cash" ,
236+ "bank_details_needed" : "g2p_bank" ,
237+ "conducting_inkind_transfer" : "spp_entitlement_in_kind" ,
238+ }
239+ for field , module_name in module_map .items ():
240+ if getattr (self , field ) == "yes" :
241+ res = self ._add_module_if_found (res , module_name )
242+ return res
243+
244+ def _install_farmer_modules (self , res ):
245+ res = self ._add_module_if_found (res , "spp_farmer_registry_base" )
246+ if self .location_assignment == "yes" :
247+ res = self ._add_module_if_found (res , "spp_area_gis" )
248+ if self .farmer_demo_management == "yes" :
249+ for module_name in ["spp_base_demo" , "spp_farmer_registry_demo" , "spp_programs" ]:
250+ res = self ._add_module_if_found (res , module_name )
251+ return res
252+
206253 def _install_modules (self ):
207254 self .ensure_one ()
255+ res = self ._find_module ("theme_openspp_muk" ) or self .env ["ir.module.module" ]
208256
209- def find_module (module_name ):
210- return self .env .ref (f"base.module_{ module_name } " , raise_if_not_found = False )
211-
212- res = find_module ("theme_openspp_muk" )
213257 if self .registry_target == "spmis" :
214- res |= find_module ("spp_base" )
215- res |= find_module ("spp_programs" )
216- res |= find_module ("spp_change_request" )
217- res |= find_module ("spp_change_request_change_info" )
218- res |= find_module ("spp_event_data" )
219- if self .sp_mis_demo_management == "yes" :
220- res |= find_module ("spp_base_demo" )
221- res |= find_module ("spp_mis_demo" )
222- if self .location_assignment == "yes" :
223- res |= find_module ("spp_area" )
224- if self .service_point_management == "yes" :
225- res |= find_module ("spp_service_points" )
226- if self .cash_transfer_needed == "yes" :
227- res |= find_module ("spp_entitlement_cash" )
228- if self .bank_details_needed == "yes" :
229- res |= find_module ("g2p_bank" )
230- if self .conducting_inkind_transfer == "yes" :
231- res |= find_module ("spp_entitlement_in_kind" )
232-
233- if self .registry_target == "farmer" :
234- # TODO: needs to change this once the module for farmer registry default UI is created
235- res |= find_module ("spp_farmer_registry_base" )
236- if self .location_assignment == "yes" :
237- res |= find_module ("spp_area_gis" )
238- if self .farmer_demo_management == "yes" :
239- res |= find_module ("spp_base_demo" )
240- res |= find_module ("spp_farmer_registry_demo" )
241- res |= find_module ("spp_programs" )
258+ res = self ._install_spmis_base_modules (res )
259+ res = self ._install_spmis_demo_modules (res )
260+ res = self ._install_spmis_feature_modules (res )
261+ elif self .registry_target == "farmer" :
262+ res = self ._install_farmer_modules (res )
242263
243264 if self .id_management == "yes" :
244- res |= find_module ( "spp_idpass" )
265+ res = self . _add_module_if_found ( res , "spp_idpass" )
245266
246267 return res
247268
0 commit comments