Help

3

How to update the Selection attribute values based on onchange or using functional field?

Avatar
Anil R. Kesariya (Jupical)

Hello Everybody,

By using onchange method we can return domain, warning and value.

for Eg : domain : return {'domain': {'x_field':[('id', 'in', ids)]}} 

Is there any way in odoo we can update the selection either using on change or functional field.

I have tried to with both way but couldn't works,

Here is sample code which i have applied for functional field.

First try:

     @api.model

     def get_sel_val(self):

         sel= []

         if self.x_ids:

             for data in self.x_ids:

                 sel.append((data.name, data.name))

                 return sel

        else:

                return []

    return []

-------------------------------------

Second try :

     @api.depends('x_ids')

     @api.model

     def _get_sel_val(self):

     sel = []

     if self.x_ids:

         for data in self.x_ids:

             sel.append((data.name, data.name))

         self.cust_sel = sel

     else:

         self.cust_sel = []

return True

-------------------------------

Third try :

     @api.depends('x_ids')

     @api.multi

     def _get_sel_val(self):

         for rec in self:

             sel = []

             if rec.x_ids:

                 for data in rec.x_ids:

                      sel.append((data.name, data.name))

                 rec.cust_sel = sel

             else:

                 rec.cust_sel = []

         return True


This is my selection field :

cust_sel = fields.Selection(selection=get_sel_val, string= "Systems")

Note : Main objective is update the selection field information based on many2many field.

Is there any way to apply this using odoo 8 using api coding standard?

Thanks in advance

Regards,

Anil.

Avatar
Discard
1 Answer
0
Avatar
Mohammad M Omar
Best Answer

as i know the selection field you cannot update its value on on_change,

you can put it as many2one field after that you can update its value from domain or on_change

Avatar
Discard