[Openerp-community] Selection fields in v8

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Openerp-community] Selection fields in v8

Aristóbulo Meneses
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?


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

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Selection fields in v8

Ovnicraft



On Thu, Jul 24, 2014 at 3:55 PM, Aristóbulo Meneses <[hidden email]> wrote:
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?


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


AFAIK it nevers works on >6.0 you can check column implementation, there is not that feature. 

Regards,

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

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp




--

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp