Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

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

By
Anil R. Kesariya
on 4/15/15, 1:15 AM 983 views

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.

0
Mohammad M Omar
On 4/22/15, 3:03 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/15/15, 1:15 AM
Seen: 983 times
Last updated: 4/22/15, 3:03 AM