Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
1 Svar
2303 Visninger

i want to update crm.lead field stage_id when mail.activity is updated. 

i am trying to add Automated Action on mail.activity with On Update trigger and Execute Python Code, its not working, please correct where i am wrong.

the Python Code is:

for records in record:

# raise Warning('stage_id update here...')

new_leads = env['crm.lead'].write({

'stage_id':2

})

please help, how it should update current lead's stage_id?



regards


Avatar
Kassér
Bedste svar

Hi,

Inside the mail activity model, you have two fields res_model and res_id which can give you information about the original record to which the activity is linked with.

So using this two fields inside your code, you can achieve the same.

leads_to_write = env['crm.lead'].search([('id', '=', record.res_id)])
leads_to_write({'stage_id': 2})


Also, try changing for records in records to for record in records also using the res_model field in the activity you can ensure the activity is linked with leads.

for record in records:
... if record.res_model == 'crm.lead':
..........leads_to_write = env['crm.lead'].search([('id', '=', record.res_id)])
..........leads_to_write.write({'stage_id': 2})



Thanks

Avatar
Kassér
Forfatter

thank you @Mehjabin but it is throiwng error, the code i copy & paste from your post (2nd code) and run, on updating an Activity it is showing:

ValueError: <class 'TypeError'>: "'crm.lead' object is not callable"

what can be the problem and how it can be resolved?

regards

please try with updated code, made an update in last line

Forfatter

thanks a bunch... it works fine now.

Related Posts Besvarelser Visninger Aktivitet
3
aug. 25
2565
1
maj 25
2611
1
apr. 25
3589
1
apr. 25
4445
1
apr. 25
1909