odoo 9 Automatically changing the selection field and radio button field depends on the changed other selection field

I need a help please. So I wanted when I change the Internal Category (field name is categ_id) value to 500 final product,

and then the Routes field changes to : Manufacture checked, Make To Order checked, Buy checked

and also the Value of Tracking field is changes as well to: By Lots checked

How can I do that? Any suggestion ? Or my is it my question are not clear enough ? Sorry for asking , I never done this before so yeah kind a confusing. Here I got the picture the interface and the information about the field as well.

Routes field name Tracking field name

Please anyone kindly to help me. I am so confused.

Upvotes: 0

Views: 798

Answers (1)

thangtn
thangtn

Reputation: 876

You could achieve this by using api onchange in Odoo 9.

@api.onchange('categ_id')
def onchange_categ_id(self):
  for record in self:
    # I prefer to check by id, but here I show how to check by string name in case you want it
    if record.categ_id.name == '500 final product':
      # because route_ids is many2many field, 
      # you need special commands to change the value
      # here I use (6, _, ids) to set value. 
      # But before that, you have to get the ids of the routes you want from model stock.location.route 
      # (you could use search method to get the ids)
      record.route_ids = [(6,0, list_of_id)]
      record.tracking = 'lot'
      ...

You could refer to Odoo Doc to learn more about O2m and M2m commands

Upvotes: 2

Related Questions