create complicated domain for my attrs attribute

[亡魂溺海] 提交于 2021-02-10 16:43:47

问题


I want to build below logic for my attrs . Can some help me here ?

 A OR B OR ( C OR ( (D AND E) OR (F AND G AND H) ) ) 

I tried with below logic

['|','|', (A), (B),'|'(C), '|','&', (D), (E),'&', (F),'&' (G),(H)]

回答1:


It can be quite tricky to form such domains. In those cases you can use odoo.osv.expression helpers, which take a list of domains (not a list of leafs). Example:

>>> from odoo.osv.expression import AND, OR                                                                                                                                                                 

>>> a,b,c,d,e,f,g,h = ([("field_" + x, "=", "value_" + x)] for x in "ABCDEFGH")                                                                                                                             

>>> OR([a, b, OR([c, AND([d, e]), AND([f, g, h])])])                                                                                                                                                        
['|', '|', ('field_A', '=', 'value_A'), ('field_B', '=', 'value_B'), '|', '|', ('field_C', '=', 'value_C'), '&', ('field_D', '=', 'value_D'), ('field_E', '=', 'value_E'), '&', '&', ('field_F', '=', 'value_F'), ('field_G', '=', 'value_G'), ('field_H', '=', 'value_H')]

Note: I had to convert your variables into valid domains or the methods wouldn't work.



来源:https://stackoverflow.com/questions/57849297/create-complicated-domain-for-my-attrs-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!