问题
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