如何使用域列表过滤OpenERP中的数据 [英] How to filter datas in OpenERP using domain list

查看:127
本文介绍了如何使用域列表过滤OpenERP中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用域过滤器表达式过滤OPenERP中的recods



在记录中我有一个用户列表的字段,所以我想获取用户的记录登录列表

  [(user.id,'in','user_ids')] 

这不工作



返回此错误:

 文件/usr/lib/pymodules/python2.7/openerp/osv/orm.py, line 2356,in search 
return self._search(cr,user,args,offset = offset,limit = limit,order = order,context = context,count = count)
文件/ usr / lib /pymodules/python2.7/openerp/osv/orm.py,第4846行,在_search
self._apply_ir_rules(cr,user,query,'read',context = context)
文件/ usr / lib / pymodules / python2.7 / openerp / osv / orm.py,第4728行在_apply_ir_rules
rule_where_clause,rule_where_clause_params,rule_tables = rule_obj.domain_get(cr,uid,self._name,mode,context =上下文)
文件/ usr / lib /pymodules/python2.7/openerp/addons/base/ir/ir_rule.py,第156行,在domain_get
query = self.pool.get(model_name)._ where_calc(cr,SUPERUSER_ID,dom,active_test = False)
文件/usr/lib/pymodules/python2.7/openerp/osv/orm.py,第4676行,位于_where_calc
e = expression.expression(cr,user,domain,self,上下文)
文件/usr/lib/pymodules/python2.7/openerp/osv/expression.py,第632行,__init__
self.parse(cr,uid,context = context)
文件/usr/lib/pymodules/python2.7/openerp/osv/expression.py,第759行,解析
field_path = left.split('。',1)
AttributeError:'int'对象没有属性'split'

请帮助我。

解决方案

您的域名语法错误。



应该是 [('user_ids','=',user.id)]


  1. 每个元组搜索域需要有3个元素,格式如下:(' field_name','operator',value),其中:


  2. field_name 必须是有效的名称的对象模型的字段,可能使用点符号进行多对一关系,例如street或partner_id.country是有效值。


  3. 操作符必须是一个带有此列表中有效比较运算符的字符串:
    =,!=,>> =,< =,like,ilike,in,not in,child_of,parent_left,parent_right
    大多数这些运算符的语义是显而易见的。
    child_of 运算符将根据该模型的语义查找属于给定记录的子节点或子节点的记录
    (即跟随由
    self._parent_name 命名的关系字段默认为 parent_id


  4. 必须是与 field_name 的值进行比较的有效值,具体取决于其类型。


可以使用3个逻辑运算符组合域标准,可以在元组之间添加:'& ' AND,默认),' | '(逻辑OR),''(逻辑NOT)
这些是前缀& | 运算符的优先级为2,而的优先级只有1。当您第一次将它们结合起来时,请非常小心。



以下是从比利时和德国搜索名为 ABC 的合作伙伴的示例,其语言不是英文::

  [( '姓名', '=', 'ABC'),( 'language.code', '=', 'EN_US'), '!' '|',( 'country_id.code','=','be'),('country_id.code','=','de')] 

默认情况下,省略'&',当然我们可以使用'!='语言,但这个领域真正代表的是:

 (名称是ABCAND(语言不是英语)AND(国家是比利时或德国))


I want to filter recods in OPenERP using domain filter expression

In the recored I have a field of list of users, so i want get the record where the user logged in the list

[(user.id , 'in' , 'user_ids')]

This doesn't work

it return this error :

File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 2356, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4846, in _search
    self._apply_ir_rules(cr, user, query, 'read', context=context)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4728, in _apply_ir_rules
    rule_where_clause, rule_where_clause_params, rule_tables = rule_obj.domain_get(cr, uid, self._name, mode, context=context)
  File "/usr/lib/pymodules/python2.7/openerp/addons/base/ir/ir_rule.py", line 156, in domain_get
    query = self.pool.get(model_name)._where_calc(cr, SUPERUSER_ID, dom, active_test=False)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4676, in _where_calc
    e = expression.expression(cr, user, domain, self, context)
  File "/usr/lib/pymodules/python2.7/openerp/osv/expression.py", line 632, in __init__
    self.parse(cr, uid, context=context)
  File "/usr/lib/pymodules/python2.7/openerp/osv/expression.py", line 759, in parse
    field_path = left.split('.', 1)
AttributeError: 'int' object has no attribute 'split'

Please help me.

解决方案

Your domain syntax is wrong.

It should be [('user_ids', '=' , user.id)]

  1. Each tuple in the search domain needs to have 3 elements, in the form: ('field_name', 'operator', value), where:

  2. field_name must be a valid name of field of the object model, possibly following many-to-one relationships using dot-notation, e.g 'street' or 'partner_id.country' are valid values.

  3. operator must be a string with a valid comparison operator from this list: =, !=, >, >=, <, <=, like, ilike, in, not in, child_of, parent_left, parent_right The semantics of most of these operators are obvious. The child_of operator will look for records who are children or grand-children of a given record, according to the semantics of this model (i.e following the relationship field named by self._parent_name, by default parent_id.

  4. value must be a valid value to compare with the values of field_name, depending on its type.

Domain criteria can be combined using 3 logical operators than can be added between tuples: '&' (logical AND, default), '|' (logical OR), '!' (logical NOT). These are prefix operators and the arity of the '&' and '|' operator is 2, while the arity of the '!' is just 1. Be very careful about this when you combine them the first time.

Here is an example of searching for Partners named ABC from Belgium and Germany whose language is not english ::

[('name','=','ABC'),'!',('language.code','=','en_US'),'|',('country_id.code','=','be'),('country_id.code','=','de')]

The '&' is omitted as it is the default, and of course we could have used '!=' for the language, but what this domain really represents is::

(name is 'ABC' AND (language is NOT english) AND (country is Belgium OR Germany))

这篇关于如何使用域列表过滤OpenERP中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆