@@ -19,8 +19,6 @@ class G2PFetchSocialRegistryBeneficiary(models.Model):
19
19
_name = "g2p.fetch.social.registry.beneficiary"
20
20
_description = "Fetch Social Registry Beneficiary"
21
21
22
- MAX_REGISTRANT_IN_FETCH = 150
23
-
24
22
data_source_id = fields .Many2one ("spp.data.source" , required = True )
25
23
26
24
name = fields .Char ("Search Criteria Name" , required = True )
@@ -73,11 +71,13 @@ def get_social_registry_auth_url(self, paths):
73
71
url = self .data_source_id .url
74
72
auth_path = paths .get (constants .DATA_SOURCE_AUTH_PATH_NAME )
75
73
76
- return f"{ url } { auth_path } "
74
+ if auth_path .lstrip ().startswith ("/" ):
75
+ return f"{ url } { auth_path } "
77
76
78
- def get_auth_token (self , auth_url ):
77
+ else :
78
+ return auth_path
79
79
80
- headers = self . get_headers_for_request ()
80
+ def get_auth_token ( self , auth_url ):
81
81
82
82
grant_type = (
83
83
self .env ["ir.config_parameter" ]
@@ -94,20 +94,29 @@ def get_auth_token(self, auth_url):
94
94
.sudo ()
95
95
.get_param ("social_registry_client_secret" )
96
96
)
97
- db_name = (
98
- self .env ["ir.config_parameter" ].sudo ().get_param ("social_registry_db_name" )
97
+ username = (
98
+ self .env ["ir.config_parameter" ]
99
+ .sudo ()
100
+ .get_param ("social_registry_user_name" )
101
+ )
102
+ password = (
103
+ self .env ["ir.config_parameter" ]
104
+ .sudo ()
105
+ .get_param ("social_registry_user_password" )
99
106
)
100
107
101
108
data = {
102
109
"grant_type" : grant_type ,
103
110
"client_id" : client_id ,
104
111
"client_secret" : client_secret ,
105
- "db_name" : db_name ,
112
+ "username" : username ,
113
+ "password" : password ,
106
114
}
115
+
107
116
response = requests .post (
108
117
auth_url ,
109
- headers = headers ,
110
- data = json . dumps ( data ) ,
118
+ headers = { "Content-Type" : "application/x-www-form-urlencoded" } ,
119
+ data = data ,
111
120
timeout = constants .REQUEST_TIMEOUT ,
112
121
)
113
122
@@ -355,10 +364,10 @@ def process_registrants(self, partners):
355
364
def process_registrants_async (self , partners , count ):
356
365
_logger .warning ("Fetching Registrant Asynchronously!" )
357
366
jobs = []
358
- for i in range (0 , count , self . MAX_REGISTRANT_IN_FETCH ):
367
+ for i in range (0 , count , constants . MAX_REGISTRANT ):
359
368
jobs .append (
360
369
self .delayable ().process_registrants (
361
- partners [i : i + self . MAX_REGISTRANT_IN_FETCH ]
370
+ partners [i : i + constants . MAX_REGISTRANT ]
362
371
)
363
372
)
364
373
main_job = group (* jobs )
@@ -425,11 +434,12 @@ def fetch_social_registry_beneficiary(self):
425
434
timeout = constants .REQUEST_TIMEOUT ,
426
435
)
427
436
437
+ sticky = False
438
+
428
439
# Process response
429
440
if response .ok :
430
441
kind = "success"
431
442
message = _ ("Successfully Imported Social Registry Beneficiaries" )
432
- sticky = False
433
443
434
444
search_responses = (
435
445
response .json ().get ("message" , {}).get ("search_response" , [])
@@ -443,7 +453,7 @@ def fetch_social_registry_beneficiary(self):
443
453
total_partners_count = reg_record .get ("totalRegistrantCount" , "" )
444
454
445
455
if total_partners_count :
446
- if total_partners_count < self . MAX_REGISTRANT_IN_FETCH :
456
+ if total_partners_count < constants . MAX_REGISTRANT :
447
457
self .process_registrants (partners )
448
458
449
459
else :
0 commit comments