Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

expression - How to filter datas in OpenERP using domain list

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...