跳至内容
菜单
此问题已终结
4 回复
13954 查看

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

形象
丢弃
最佳答案

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.

形象
丢弃
最佳答案

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.

形象
丢弃
最佳答案

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.

形象
丢弃
编写者 最佳答案

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

形象
丢弃

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

相关帖文 回复 查看 活动
4
9月 24
21274
3
10月 22
21270
0
7月 22
3696
1
12月 16
5024
1
10月 15
3698