Odoo Help


Can I store field function with the type one2many?

Yug Faa
on 2/7/13, 8:10 AM 7,641 views

Hi everybody

To resolve the problem of filtring values that are function fields of type one2many

I create this syntax :

'user_ids': fields.function(_get_marche_users, string='Chefs', type='one2many', readonly=True, relation='res.users', multi='marche_users', store=True)

but when I update the my module I get this error :

  File "/usr/lib/pymodules/python2.7/openerp/modules/loading.py", line 167, in load_module_graph
    init_module_models(cr, package.name, models)
  File "/usr/lib/pymodules/python2.7/openerp/modules/module.py", line 374, in init_module_models
    result = obj._auto_init(cr, {'module': module_name})
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 3156, in _auto_init
    cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, get_pg_type(f)[1]))
TypeError: 'NoneType' object has no attribute '__getitem_

A help please


Nicolas Bessi

--Nicolas Bessi--

| 5 7 8
Lausanne, Switzerland
--Nicolas Bessi--
Nicolas Bessi
On 2/7/13, 8:48 AM

As far as I know this feature is not supported. You have to implement fnct_search of you function field, but I never try to do it on a one2many field and can not guarantee it works.

Thibaut DIRLIK
On 2/7/13, 9:39 AM

As said by @nbessi, you have to define fnct_search which will let you do what you want. By definition, you can't store a one2many, it doesn't make any sense.

Yug Faa
On 2/8/13, 7:16 AM

I had edit this syntax to :

'user_ids': fields.function(
        _get_marche_users, string='Chefs',
        type='one2many', readonly=True,
        relation='res.users', multi='marche_users',

the function _get_marche_users get users ids by intelligence and it works.

I know that the function _users_search must return this syntax :


and res is a list

I formulate now the question : res is it the table of ids of users that returned by the function _get_marche_users ? Really I need a full example, I grep the code and I have a big problem in a interresting project I don't found the documentation, just the prototype that's not sufficient, and I can't understand the source code so a help please I will be so grateful for you

A function search needs to return the ids of for the object, not for the relation object.

In your case, you must return ids of the object having Chefs lets say it is a Restaurant

So you have to search first for res.user ids matching a name. Then check if those ids are included in your Restaurant.

And for Restaurant that match this condition, you add it's id in your res list

Camptocamp SA
on 2/28/13, 4:08 PM
Nhomar Hernandez
On 2/7/13, 8:57 AM


Please try this:

The function related, must always return an iterable, if in some case it can return None it will explode,

If you try a Python console:

>>> None[1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object has no attribute '__getitem__'

See, i'm obtaining almost the same error becasue the ORM is not capable to manage a value of a type different to what it is specting, can you try and tell me the result.


BTW: It should be cool if you can share branch wih your module to see all the py file, regards.

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: 2/7/13, 8:10 AM
Seen: 7641 times
Last updated: 3/16/15, 8:10 AM