Skip to Content
Menu
This question has been flagged
3 Replies
4531 Views

Hii All,

I have two fields in odoo10, add i want to add onchange function for it. In one field i added three workflows, In first workflow(work1) i added two stages(create, new) similarly for second(work2) and third(work3)  added two stages(draft, escalate) & (assign, pending). i want that when i select work1 from workflow field then related stages show in the stage field. So, anyone can solve this problem. my python code for that is below:

python code:

work_flow_stage = fields.Many2one('stage.workflow', string="Work Flow", change_default=True, default=_work_flow_status)
work_stage = fields.Many2one('partner.state', string="Stage")

@api.onchange('work_flow_stage', 'work_stage')
@api.multi
def _work_flow_status(self):
stage = self.env['stage.workflow'].search([('work_stage', 'in', 'work_flow_stage')], limit=1)
print "stage", stage
return stage
Avatar
Discard
Author Best Answer

Hello @Rakesh,

After using this function following error occurs on terminal.

 raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'work_stage' in leaf "<osv.ExtendedLeaf: ('work_stage', '=', 'work_flow_stage') on stage_workflow (ctx: )>"
Avatar
Discard
Best Answer

work_flow_stage = fields.Many2one('stage.workflow', string="Work Flow", change_default=True, default=_work_flow_status)
work_stage = fields.Many2one('partner.state', string="Stage")

@api.onchange('work_flow_stage', 'work_stage')
 def _work_flow_status(self):
stage = self.env['stage.workflow'].search([('work_stage', '=', 'work_flow_stage')])
print "stage", stage.id
    self.work_stage=stage.id

Avatar
Discard

here I am assigning work_stage with stage.id

Related Posts Replies Views Activity
2
Mar 24
10335
5
Sep 20
5187
2
Jun 20
12110
1
Dec 19
8420
4
Jan 19
7797