Help

3

Can I store field function with the type one2many?

Avatar
Yug Faa

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

Avatar
Discard
4 Answers
2
Avatar
Nicolas Bessi
Best Answer

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.

Avatar
Discard
1
Avatar
Thibaut DIRLIK
Best Answer

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.

Avatar
Discard
0
Avatar
Yug Faa
Best Answer

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',
        fnct_search=_users_search)

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

I know that the function _users_search must return this syntax :

[('id','in',res)]

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

1 Comment
Avatar
Discard
Avatar
Camptocamp SA
-

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

0
Avatar
Nhomar Hernandez
Best Answer

Hello.

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.

Regards.

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

Avatar
Discard