Sei sulla pagina 1di 2

Your domain syntax is wrong.

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

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

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.

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.

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))
shareimprove this answer
edited Aug 20 '14 at 6:42
answered Jan 31 '13 at 4:39

Sudhir Arya
3,06322237
1
Excellent. Such a detailed explanation is missing from the docs. – Daniel Reis Jan
31 '13 at 8:36
1
Great answer! Can I ask how you figure things out in Odoo while documentation is
poor? What are your go to resources? Thanks – Alexander Suraphel Jul 4 '15 at 14:42
I used to go into ORM files, checking all the classes and methods and the code. –
Sudhir Arya Jul 8 '15 at 6:53
Hi @SudhirArya, I am needing a domaing based on two conditions: 1. either product
should exist in "product_ids" 2. or it should exist in "suggested_product_ids" with
('is_psa','!=',True), where *_ids fields are m2m and 'is_psa' a boolean Field. I
have tried domain below with no luck. Thanks in advance. domain="['|',
('id','in',product_ids[0][2])('is_psa','!=',True),
('id','in','suggested_product_ids[0][2]'))]" – StackUP Aug 1 '15 at 17:48
You should try this: domain="['|',('id', 'in', product_ids[0][2]), ('id', 'in',
'sugge‌
sted_product_ids[0][2]'), ('is_psa', '!=', True))]" – Sudhir Arya Aug 3 '15
at 5:10
show 1 more comment
up vote
0
down vote
In a simple case this is right, BUT if you want to filter current object by its
functional field, you'll be very surprised that code in function of this field will
not execute; instead fnct_search part of this field will be executed, that will
allow you to do various things.

Left part of filter expression is evaluated in context of current object, and right
part — in context of inner context (read current user).

Left part is evaluated after right, so you can add a functional field to a user
model, make some calculations there, and then receive those calculations on the
object's side and take them into account.

Potrebbero piacerti anche