英文:
Search domain : multiple condition in odoo
问题
如何将此表达式转换为OpenERP域语法:((A & B) | (C & D)) | ((E & F) | (G & H))
PostgreSQL查询如下:
SELECT
*
FROM
calendar_event
WHERE
(
(start_datetime <= '2020-01-07 09:00:00' and '2020-01-07 09:00:00' <= stop_datetime) or
(start_datetime <= '2020-01-07 11:00:00' and '2020-01-07 11:00:00' <= stop_datetime)
) or (
('2020-01-07 09:00:00' <= start_datetime and start_datetime <= '2020-01-07 11:00:00') or
('2020-01-07 09:00:00' <= stop_datetime and stop_datetime <= '2020-01-07 11:00:00')
)
我尝试做成这样,但不正确,请问我哪里错了?
inParams1.push([
"|",
"&",
["start_datetime", "<", '2020-01-07 09:00:00'],
['2020-01-07 09:00:00', "<=", "stop_datetime"],
"&",
["start_datetime", "<=", '2020-01-07 11:00:00'],
['2020-01-07 11:00:00', "<=", "stop_datetime"],
"|",
"&",
['2020-01-07 09:00:00', "<=", "start_datetime"],
["start_datetime", "<=",'2020-01-07 11:00:00'],
"&",
['2020-01-07 09:00:00', "<=", "stop_datetime"],
["stop_datetime", "<=",'2020-01-07 11:00:00']
]);
请帮助我,我已经工作了很多天了,但找不到解决方案
英文:
How to convert this expression : ((A & B) | ( C & D)) | (( E & F) | (G & H)) in OpenERP domain syntax
PostgreSQL query is :
SELECT
*
FROM
calendar_event
WHERE
(
(start_datetime <= '2020-01-07 09:00:00' and '2020-01-07 09:00:00' <= stop_datetime) or
(start_datetime <= '2020-01-07 11:00:00' and '2020-01-07 11:00:00' <= stop_datetime)
) or (
('2020-01-07 09:00:00' <= start_datetime and start_datetime <= '2020-01-07 11:00:00') or
('2020-01-07 09:00:00' <= stop_datetime and stop_datetime <= '2020-01-07 11:00:00')
)
I try to make like this but is not correct, where i'm wrong please?
inParams1.push([
"|",
"&",
["start_datetime", "<", '2020-01-07 09:00:00'],
['2020-01-07 09:00:00', "<=", "stop_datetime"],
"&",
["start_datetime", "<=", '2020-01-07 11:00:00'],
['2020-01-07 11:00:00', "<=", "stop_datetime"],
"|",
"&",
['2020-01-07 09:00:00', "<=", " start_datetime"],
["start_datetime", "<=",'2020-01-07 11:00:00'],
"&",
['2020-01-07 09:00:00', "<=", "stop_datetime"],
["stop_datetime", "<=",'2020-01-07 11:00:00']
]);
Please i need your help, i have many days working and i can't find a solution
答案1
得分: 1
根据那个答案,您可以使用odoo.osv.expression
。
from odoo.osv.expression import AND, OR
a, b, c, d, e, f, g, h = ([("field_" + x, "=", "value_" + x)] for x in "ABCDEFGH")
OR([OR([AND([a, b]), AND([c, d])]), OR([AND([e, f]), AND([g, h])])])
这是您提供的代码部分的中文翻译。
英文:
I find this answer very helpful for complicated domain. https://stackoverflow.com/a/57853916/8211573
According to that answer, you can use odoo.osv.expression
.
In [6]: from odoo.osv.expression import AND,OR
In [7]: a,b,c,d,e,f,g,h = ([("field_" + x, "=", "value_" + x)] for x in "ABCDEFGH")
In [8]: OR([OR([AND([a,b]),AND([c,d])]),OR([AND([e,f]),AND([g,h])])])
Out[8]:
['|',
'|',
'&',
('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')]
答案2
得分: 0
你在括号内复杂化了筛选条件:
(
(start_datetime <= '2020-01-07 09:00:00' and '2020-01-07 09:00:00' <= stop_datetime) or
(start_datetime <= '2020-01-07 11:00:00' and '2020-01-07 11:00:00' <= stop_datetime)
) or (
('2020-01-07 09:00:00' <= start_datetime and start_datetime <= '2020-01-07 11:00:00') or
('2020-01-07 09:00:00' <= stop_datetime and stop_datetime <= '2020-01-07 11:00:00')
)
与下面的条件等效:
(start_datetime <= '2020-01-07 09:00:00' and '2020-01-07 09:00:00' <= stop_datetime)
or
(start_datetime <= '2020-01-07 11:00:00' and '2020-01-07 11:00:00' <= stop_datetime)
or
('2020-01-07 09:00:00' <= start_datetime and start_datetime <= '2020-01-07 11:00:00')
or
('2020-01-07 09:00:00' <= stop_datetime and stop_datetime <= '2020-01-07 11:00:00')
所以请尝试使用以下条件:
[
'|',
"&",
["start_datetime", "<", '2020-01-07 09:00:00'],
["stop_datetime", ">=", '2020-01-07 09:00:00'],
'|',
"&",
["start_datetime", "<=", '2020-01-07 11:00:00'],
["stop_datetime", ">=", '2020-01-07 11:00:00'],
'|',
"&",
["start_datetime", ">=", '2020-01-07 09:00:00'],
["start_datetime", "<=", '2020-01-07 11:00:00'],
"&",
["stop_datetime", ">=", '2020-01-07 09:00:00'],
["stop_datetime", "<=", '2020-01-07 11:00:00']
]
如果不起作用,请告诉我。
英文:
You complicated the filter by parentheses:
<!-- language: python -->
(
(start_datetime <= '2020-01-07 09:00:00' and '2020-01-07 09:00:00' <= stop_datetime) or
(start_datetime <= '2020-01-07 11:00:00' and '2020-01-07 11:00:00' <= stop_datetime)
) or (
('2020-01-07 09:00:00' <= start_datetime and start_datetime <= '2020-01-07 11:00:00') or
('2020-01-07 09:00:00' <= stop_datetime and stop_datetime <= '2020-01-07 11:00:00')
)
Is the same as this:
(start_datetime <= '2020-01-07 09:00:00' and '2020-01-07 09:00:00' <= stop_datetime)
or
(start_datetime <= '2020-01-07 11:00:00' and '2020-01-07 11:00:00' <= stop_datetime)
or
('2020-01-07 09:00:00' <= start_datetime and start_datetime <= '2020-01-07 11:00:00')
or
('2020-01-07 09:00:00' <= stop_datetime and stop_datetime <= '2020-01-07 11:00:00')
So just try this:
[ '|'
"&",
["start_datetime", "<", '2020-01-07 09:00:00'],
["stop_datetime", ">=", '2020-01-07 09:00:00'],
'|',
"&",
["start_datetime", "<=", '2020-01-07 11:00:00'],
["stop_datetime", ">=", '2020-01-07 11:00:00'],
'|',
"&",
["start_datetime", ">=", '2020-01-07 09:00:00'],
["start_datetime", "<=",'2020-01-07 11:00:00'],
"&",
["stop_datetime", ">=", '2020-01-07 09:00:00'],
["stop_datetime", "<=",'2020-01-07 11:00:00']
]
let me know if it doesn't work for you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论