Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Automated Action: Update a record based on the update of another record

形象
odoo
1 备注
形象
丢弃
形象
odoo
-

We tried to do something like this, but it doesn't work

update = env['crm.lead'].search([('sales_order_id','=', record.id)])
if update:
env['crm.lead'].write({'field': 'value'})

Can someone help us?

2 答案
0
形象
odoo
最佳答案

Hi,

Did you keep any relation in the crm.lead model to understand from which record the lead get generated ? or any field in sale.order model store the value of created opportunity ?

If yes, using that field, you can access the opportunity and update the stage when changes done inside the sale order.

If not. first you have to keep the relation, using the studio add a new field and keep the relation in it.

Thanks


8 注释
形象
丢弃
形象
odoo
-

I configured an automated action that creates an opportunity based on a manually created sales order. I added a custom field called "Sales Order" in the opportunity. This custom field is populated by the automated action with the following:

Sales Order (crm.lead) Python expression record.id

So if I understood you question correctly, yes I have a relation between both. But now based on that relation I want to have an automated action that changes the stage of the generated opportunity based on a manually change of status of the related sales order. I tried to code a line but I get an error message:

update = env['crm.lead'].search([(' x_studio_many2one_field_ZvJsh'.id,'=', record.id)])
if update:
env['crm.lead'].set({'stage_id': '14'})

thanks for your help

形象
odoo
-

crm_rec = env['crm.lead'].search([(' x_studio_many2one_field_ZvJsh'.id,'=', record.id)], limit=1)
if crm_rec:
crm_rec['stage_id'] = 4

形象
odoo
-

This is the error message I get an I already got it before, I think its related to the type of my custom field:
ValueError: <class 'AttributeError'>: "'str' object has no attribute 'id'" while evaluating
"# Available variables:\n# - env: Odoo Environment on which the action is triggered\n# - model: Odoo Model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - UserError: Warning Exception to use with raise\n# To return an action, assign: action = {...}\n\ncrm_rec = env['crm.lead'].search([(' x_studio_many2one_field_ZvJsh'.id,'=', record.id)], limit=1)\nif crm_rec:\n crm_rec['stage_id'] = 4"

形象
odoo
-

crm_rec = env['crm.lead'].search([(' x_studio_many2one_field_ZvJsh,'=', record.id)], limit=1)

形象
odoo
-

There is an syntax error in your line but i understood what you changed in that line and this is the error i get now :
ValueError: <class 'ValueError'>: "Invalid field crm.lead. x_studio_many2one_field_ZvJsh in leaf (' x_studio_many2one_field_ZvJsh', '=', 932)" while evaluating

形象
odoo
-

says there is no field named x_studio_many2one_field_ZvJsh in crm.lead model

形象
odoo
-
形象
odoo
-

There is the image that shown the field in the crm.lead model

I do not really understand where the issue is

0
形象
odoo
最佳答案

hi,I succeeded with this mode. you create a automated action that set model sale order , set Trigger: on update ,set  Trigger field: status(sale order) and set domin according change status , also action to do:execute python code than ;

update = env['crm.lead'].search([(' x_studio_many2one_field_ZvJsh.id' ,'=',  record.id)])
if update:
env['crm.lead'].write({'stage_id': 4})

so  x_studio_many2one_field_ZvJsh  is many2one field to created in  opportunity and related sale order 

形象
丢弃