Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
2310 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Auteur

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

Auteur

thanks a bunch... it works fine now.

Publications associées Réponses Vues Activité
3
août 25
2576
1
mai 25
2616
1
avr. 25
3597
1
avr. 25
4464
1
avr. 25
1928