Endpoint push leads
unknown
python
3 years ago
5.0 kB
10
Indexable
@http.route([
'/api/push_leads'
], type='http', auth="none", methods=['POST'], csrf=False)
@check_valid_token
def restapi_push_leads_data(self, **post):
datas = post.get('leads_data',None)
if datas:
datas = eval(datas)
OProspect = request.env['crm.prospect']
total = 0
for data in datas:
try:
if data.get('source') == '' or data.get('source') == None or data.get('source') == False or data.get('source') == ' ':
source = 'WSE Website'
else:
source = data.get('source')
except:
source = 'WSE Website'
# Add parameter to pass by Steven (11-03-2020)
utm_medium = data.get('utm_medium')
utm_campaign = data.get('utm_campaign')
utm_source = data.get('utm_source')
utm_content = data.get('utm_content')
utm_term = data.get('utm_term')
membership_product_name = data.get('membership_product_name')
branch_name = data.get('branch_name')
# Add parameter to pass requested by Ricky (23-04-2020)
department = data.get('department')
corporate_name = data.get('corporate_name')
# Add referral code (11-05-2020) Requested by Kevin
ref_code = data.get('ref_code')
# Add more fields requested by Marketing Team(16-07-2020)
consultation = data.get('consultation')
learning_preference = data.get('learning_preference')
if learning_preference == 'Online':
branch_id = '24'
else:
branch_id = data.get('branch_id')
# branch_name = data.get('branch_id')
# Add course plan and awareness field requested by Jafar - BD Team(05-04-2021)
course_plan = data.get('course_plan')
awareness = data.get('awareness')
# Add gender requested by Marketing (19-10-2021)
gender = data.get('gender')
# Add fbp and fbc requested by Aditiya (01-11-2021)
fbp = data.get('fbp')
fbc = data.get('fbc')
# Add multitouch_attribution requested by Marketing (18-11-2021)
multitouch_attribution = data.get('multitouch_attribution')
# Add conversion_url requested by Marketing (10-02-2022)
conversion_url = data.get('conversion_url')
data.update({'name': data['contact_name'],
'source': source,
'utm_medium': utm_medium,
'utm_campaign': utm_campaign,
'utm_source': utm_source,
'utm_content': utm_content,
'utm_term': utm_term,
'membership_product_name': membership_product_name,
'branch': branch_name,
'department': department,
'corporate_name': corporate_name,
'ref_code': ref_code,
'consultation': consultation,
'learning_preference': learning_preference,
'course_plan': course_plan,
'awareness': awareness,
'gender': gender,
'fbp': fbp,
'fbc': fbc,
'multitouch_attribution': multitouch_attribution,
'conversion_url': conversion_url,
'branch_id': branch_id,})
if data.get('purpose'):
for purpose in PURPOSE_MAPPING:
dpurp = data.get('purpose')
if dpurp in PURPOSE_MAPPING[purpose]:
data.update({'purpose':purpose})
if data.get('job'):
for job in JOB_MAPPING:
djob = data.get('job')
if djob in JOB_MAPPING[job]:
data.update({'job':job})
if data.get('goals'):
for goal in GOALS_MAPPING:
dg = data.get('goals')
if dg in GOALS_MAPPING[goal]:
data.update({'goals':goal})
OProspect.create(data)
total += 1
return valid_response(
200, 'Success Push Data . Total ' + str(total) + ' Record.'
)Editor is loading...