Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2295 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Autor

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

Autor

thanks a bunch... it works fine now.

Publicaciones relacionadas Respuestas Vistas Actividad
3
ago 25
2540
1
may 25
2598
1
abr 25
3570
1
abr 25
4420
1
abr 25
1881