fueggit
fueggit

Reputation: 1043

Odoo multiple condition in domain error

I am trying to do condition: A or (B and C)

my code:

<field name="x" attrs="{'readonly': ['|',('state','!=', 'ok'), (('state', '=', 'fine'), ('participate_process', '=', False))]}" >

I got js error from web:

Error: unknown field state,=,to_approve_second domain ["|",["state","!=","ok"],[["state","=","fine"],["participate_process","=",false]]]

Also I was trying another way:

<field name="x" attrs="{'readonly': ['|', '&amp;', ('state','!=', 'ok'), ('state', '=', 'fine'), ('participate_process', '=', False)]}" >

But it doesn't work..

Whats wrong with these multi domains?

Upvotes: 3

Views: 8080

Answers (4)

Mayur Vora
Mayur Vora

Reputation: 942

Hello fueggit,

OpenERP uses Polish Notation for Domain filters.

First you should understand what is polish notation. You can find detailed information in wikipedia about polish notation. http://en.wikipedia.org/wiki/Polish_notation

About your question

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

should converted to the polish notation as

AND OR A B OR OR C D E

And should be solved by the algorithm with following order [] represents operation

AND [OR A B] OR OR C D E         Result of [OR A B] is F

AND F OR [OR C D] E              Result of [OR C D] is G

AND F [OR G E]                   Result of [OR G E] is H

[AND F H]

it starts from LEFT to Right.

"If another operator is found before two operands are found, then the old operator is placed aside until this new operator is resolved. This process iterates until an operator is resolved, which must happen eventually, as there must be one more operand than there are operators in a complete statement." From wikipedia article.

you can also use in operator instead of writing three separate tuples with OR operator like

['&',('field2', 'in', ['A', 'B']),('state', 'in', ['open', 'closed', 'draft'])]

Solution

    <field name="x" attrs="{'readonly': [('participate_process', '=', False),'|',('state','!=', 'ok'),('state', '=', 'fine')]}" >  

OR

<field name="x" attrs="{'readonly': ['&',('participate_process', '=', False),'|',('state','!=', 'ok'),('state', '=', 'fine')]}" >  

I hope my answer is helpful.
If any query so comment please.

Upvotes: 3

You should also write like this,

<field name="x" attrs="{'readonly': [('participate_process', '=', False), '|', ('state', '=', 'fine'), ('state','!=', 'ok')]}" >

it will be converted to like this.

Where participate_process = False and 
(state = 'fine' or state != 'ok')

Upvotes: 1

CZoellner
CZoellner

Reputation: 14768

It should be:

<field name="x" attrs="{'readonly': ['|', ('state', '=', 'ok'), '&amp;', ('state', '=', 'fine'), ('participate_process','=', False)]}" >

Upvotes: 1

fueggit
fueggit

Reputation: 1043

I found the decision:

<field name="x" attrs="{'readonly': [('participate_process', '=', False), ('state', '=', 'fine'), '|', ('state','!=', 'ok')]}" >

Upvotes: 0

Related Questions