跳至內容
選單
此問題已被標幟
1 回覆
2321 瀏覽次數

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


頭像
捨棄
最佳答案

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

頭像
捨棄
作者

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

作者

thanks a bunch... it works fine now.

相關帖文 回覆 瀏覽次數 活動
3
8月 25
2597
1
5月 25
2633
1
4月 25
3621
1
4月 25
4488
1
4月 25
1954