This question has been flagged
5 Replies
110258 Views

OpenERP 7.0

I have read http://christophe-simonis-at-tiny.blogspot.com/2008/08/new-new-domain-notation.html

I can't work out how to translate the following:

( A OR B ) AND ( C OR D OR E )

I'd appreciate both the answer as well as a method I can use to get the answer myself next time.

The post above gives this example: [ '|' , '|' , ('state', '=', 'open') , ('state', '=', 'closed') , ('state', '=', 'draft') ]

I am assuming this is ( A OR B OR C ).

So my guess is what I need is:

[ '&' , '|' , (A) , (B) , '|' , '|' , (C) , (D) , (E) ]

and my second guess is:

[ '&' , '|' , (A) , (B) , '|' , (C) , '|' , (D) , (E) ]

are these the same?

I'd rather not guess or assume, and rather not test, I'd like to KNOW!

How does the expression get parsed? Does it start from the right?

Ray,

Avatar
Discard

DO NOT do what "Sehrish" suggested, unless you know you have a good reason to do so. It might be easier than figuring out polish notation, but what you're effectively doing is retrieving all records of the given model from the database and then filtering, which is very likely going to be horrible for performance because unless you have maybe 100 records max, you're going to be pulling a lot of data.

Best Answer

If you want a quick way to do it without having to figure out the notation, just use list view and create a filter there.  Then you can copy that over as your domain.  This video explains it well.

https://youtu.be/jfNC0bKDPnE


Avatar
Discard
Best Answer

You can also use Python lambda expression to filtered out the record set. 

self.env['your.model'].search([]).filtered(lambda x:
(x.field1.id == some_id.id and x.field2.id == False and x.field3.id == some_id.id and x.name == name.strip().upper()) or
(x.field1.id == some_id.id and x.field2.id == some_id.id and x.field3.id == some_id.id and x.name == name.strip().upper())
)

Here we have OR operator between 2 main chunks of filters (which have AND operators)

Avatar
Discard