Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
15791 Vues

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"/>

Avatar
Ignorer

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

Meilleure réponse

Hi,

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

Avatar
Ignorer
Publications associées Réponses Vues Activité
1
juil. 19
6034
1
août 23
1417
1
juin 24
858
2
nov. 22
2950
1
avr. 22
2972