Search code examples
xmlodooodoo-9odoo-view

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?


Solution

  • 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.