Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
2335 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

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

Penulis

thanks a bunch... it works fine now.

Post Terkait Replies Tampilan Aktivitas
3
Agu 25
2608
1
Mei 25
2640
1
Apr 25
3631
1
Apr 25
4490
1
Apr 25
1961