Odoo Help


How to retrive values in Many2one field as selection field?

Mostafa Mohamed Abdel Monaem
on 4/6/15, 12:12 PM 4,098 views

How to retrieve values on Many2one field using OnChange ?

When i try to do so it gives me an error

'Expected singleton: fci.standard.groups(3, 4, 5, 6)'

I'm trying that when i change the standard field the group field will be updated to select only groups in this standard

Here is my fields

'standard_id': fields.many2one('fci.standard', string='Standard', required=True),

'group_id': fields.many2one('fci.standard.groups', string='Standard Group'),

Here is my function

def on_change_standard(self, cr, uid, ids, standard_id, context=None):

val = {}

if not standard_id:

return {}

student_obj = self.pool.get('fci.standard')

student_data = student_obj.browse(cr, uid, standard_id, context=context)

val.update({'group_id': student_data.groups_ids.id})

return {'value': val}

and here is my xml

<field name="standard_id" on_change="on_change_standard(standard_id)" widget="selection"/>

<field name="group_id" widget="selection"/>

hi, you try to set a list of id in a many2one field which requires just one id, this not possible, you should have same type of field for group_id than groups_ids, if you want that values for group will be always the same in 2 class, use a field function type with type of groups_ids. bye

Cyril Gaspard (GEM)
on 4/6/15, 2:12 PM

Baiju KS

--Baiju KS--
| 5 5 8
Kochi, India
--Baiju KS--
ODOO technical

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju KS
On 4/7/15, 5:44 AM


You can't pass more than one 'id' to a many2one field, that’s why you are getting error.

Its seems like you need domain filter , Please Check this :- (and add a proper filter for this field :   <field name="group_id" widget="selection"/>    )

Simple condition in programming:

if field1 = 10

In OpenERP domain filter, it will be written as:

syntax : Each tuple in the domain has three fields -> (‘field_name’, ‘operator’, value)

field_name : a valid name of field of the object model or in the database table

operator : valid operators are =, !=, >, >=, <, <=, like, ilike, in, not in, child_of, parent_left, parent_right (openerp/osv/expression.py)

value : a valid value to compare with the values of field_name, depending on its type.

ie, domain = [(‘field1′,’=’,10)] # where field1 should be a field in the model and 10 will be the value

or domain = [(‘field1′,’=’,field2)] # where field1 and field2 should be the fields in the model

Condition AND

Simple condition in programming:

if field1 = 5 and field2 = 10

In OpenERP domain filter, it will be written as:

ie, domain = [(‘field1′,’=’,5),(‘field2′,’=’,10)]

or domain = [(‘field1′,’=’,field3),(‘field1′,’=’,field3)]

Note : Note that if you don’t specify any condition at the beginning and condition will be applied.

Condition OR

Simple condition in programming:

if field1 = 5 or field2 = 10

In OpenERP domain filter, it will be written as:

ie, domain = [‘|’, (‘field1′,’=’,5),(‘field2′,’=’,10)]

or domain = [‘|’, (‘field1′,’=’,field3),(‘field1′,’=’,field3)]

Multiple Condition

Simple condition in programming:

if field1 = 5 or (field2 ! = 10 and field3 = 12)

In OpenERP domain filter, it will be written as:

domain = [‘|’,(‘field1′,’=’,5),(‘&’,(‘field2′,’!=’,10),(‘field3′,’=’,’12’))]

Hope this helps........

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 4/6/15, 12:12 PM
Seen: 4098 times
Last updated: 4/8/15, 11:37 AM