搜索域:odoo 中的多个条件

Search domain : multiple condition in odoo

如何转换此表达式:((A & B) | ( C & D)) | (( E & F) | (G & H)) 在 OpenERP 域语法

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']
]);

我需要你的帮助,我工作了很多天,但我找不到解决方案:(

您通过括号使过滤器复杂化:

(
    (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']
     ] 

如果它不适合你,请告诉我。

我发现这个答案对复杂的领域很有帮助。

根据那个答案,你可以使用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')]