← Back to team overview

openerp-community team mailing list archive

Selection fields in v8

 

Hi,

I have been banging my head against a wall for a while trying to make a
many2one field to work in a wizard, using a function and
selection=_sel_func parameter, but it doesn't work.

Has this been changed?

https://doc.odoo.com/trunk/server/03_module_dev_02/

*Example*

Using relation fields many2one with selection. In fields definitions add:


...,
'my_field': fields.many2one(
        'mymodule.relation.model',
        'Title',
        selection=_sel_func),
...,

And then define the _sel_func like this (but before the fields definitions):

def _sel_func(self, cr, uid, context=None):
    obj = self.pool.get('mymodule.relation.model')
    ids = obj.search(cr, uid, [])
    res = obj.read(cr, uid, ids, ['name', 'id'], context)
    res = [(r['id'], r['name']) for r in res]
    return res


-- 
La experiencia es la más dura maestra;
primero pone la prueba, luego dá la explicación...
-------------------------------------------------------------------------

Follow ups