Using OpenERP domain operators

Asked by Cuong

Hi,

I'm testing with openerp server trunk 6.1rc1, rev 3963.
My code is like this:
===
ids = self.search(cr, uid, ['|', ('from_pty_id', 'in', (1, 2)), '|', ('to_pty_id', 'in', (3, 4)), '|', ('pty_rel_tye_id', 'in', (5, 6))], limit=limit, context=context)
===

I face an assertion as below
===
File "/usr/local/lib/python2.7/dist-packages/openerp-6.1rc1-py2.7.egg/openerp/osv/expression.py", line 184, in normalize
    assert expected == 0
===

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Cuong
Solved:
Last query:
Last reply:

This question was originally filed as bug #916380.

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) said :
#1

(This is a question on how to properly use OpenERP domains operators, so turning it into a question)

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) said :
#2

Hi Cuong,

The domain you are passing to search() is not valid, and the assert fails because of that. You need to remember that OpenERP domains uses prefix operators, so the operator must be *before* its operands.
As OR (|) is a binary operator (it takes 2 operands), it should always be used in this form: ['|', A, B]. Here you seem to be using it also as infix operator between the operands: ['|', A, '|', B, '|', C]. which will *not* work.

Here are 2 proper way to OR 3 operands:
   1. [ '|', '|', A, B, C ] <== ((A OR B) OR C)
   2. [ '|', A, '|', B, C ] <== (A OR (B OR C))

Taking the first way, you code should be:
  ids = self.search(cr, uid, ['|', '|', ('from_pty_id', 'in', (1, 2)), ('to_pty_id', 'in', (3, 4)), ('pty_rel_tye_id', 'in', (5, 6))],
                                limit=limit, context=context)

Hope this helps

Revision history for this message
Cuong (bhcuong2008) said :
#3

Hi Olivier,

Thank you very much for your explanation. I misunderstood in using domain operator. Now I get better.

Thanks,