Odoo multiple condition in domain error

时间:2017-08-04 11:57:27

标签: xml openerp odoo-9 odoo-view

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?

4 个答案:

答案 0 :(得分:2)

你好fueggit,

OpenERP使用波兰表示法进行域名过滤。

首先你应该明白什么是波兰符号。您可以在维基百科中找到有关波兰表示法的详细信息。 http://en.wikipedia.org/wiki/Polish_notation

关于您的问题

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

应转换为光泽表示法

AND OR A B OR OR C D E

并且应该通过以下顺序的算法来解决[]表示操作

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]

LEFT 开始到正确

“如果在找到两个操作数之前找到另一个运算符,则将旧运算符放在一边直到解析这个新运算符。此过程迭代直到运算符被解析,最终必须发生,因为必须有一个操作数比起运营商的完整声明。“来自维基百科文章。

您也可以在运算符中使用,而不是使用OR运算符(如

)编写三个单独的元组
['&',('field2', 'in', ['A', 'B']),('state', 'in', ['open', 'closed', 'draft'])]

解决方案

    <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')]}" >  

我希望我的回答很有帮助 如果有任何疑问请评论。

答案 1 :(得分:1)

应该是:

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

答案 2 :(得分:1)

你也应该这样写,

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

它将被转换为这样。

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

答案 3 :(得分:0)

I found the decision:

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