MouTio
MouTio

Reputation: 1289

How can I anidate an AND inside an OR in search function? In Odoo 9

I want to anidate an AND operator inside an OR, in search function of odoo 9.

I have these two conditions:

A = self.env['sale.order'].search(['&', ('state', '=', 'done'), ('id', '>', my_id)])
B = self.env['sale.order'].search([('date_order', '>', my_date)])

These conditions work fine per separate, but I need A OR B

I have tried this:

C = self.env['sale.order'].search(['|', ('date_order', '>', my_date), ('&', ('state', '=', 'done'), ('id', '>', my_id))])

That doesn't work. It gives me this error:

ValueError: "Invalid leaf ('&', ('state', '=', 'done'), ('id', '>', my_id))" while evaluating

What is the correct way to set the condition?

Upvotes: 3

Views: 3503

Answers (1)

Charif DZ
Charif DZ

Reputation: 14751

This should do it always use the operator before the two tuple:

    C = self.env['sale.order'].search(['|', ('date_order', '>', my_date), '&', ('state', '=', 'done'), ('id', '>', my_id)])

EDITS :

this is the same as:

    ('date_order', '>', my_date)  OR (('state', '=', 'done') AND ('id', '>', my_id))

Example :

     A and (B or ( C AND D))

     A and (B or (AND, C, D))

     A and,( or, B, AND, C, D)

     and, A, or, B, AND, C, D 

Upvotes: 3

Related Questions