搜索域:Odoo中的多个条件

huangapple go评论77阅读模式
英文:

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

请帮助我,我已经工作了很多天了,但找不到解决方案 搜索域:Odoo中的多个条件

英文:

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 &lt;= &#39;2020-01-07 09:00:00&#39; and &#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime) or
    (start_datetime &lt;= &#39;2020-01-07 11:00:00&#39; and &#39;2020-01-07 11:00:00&#39; &lt;= stop_datetime)
  ) or (
    (&#39;2020-01-07 09:00:00&#39; &lt;= start_datetime and start_datetime &lt;= &#39;2020-01-07 11:00:00&#39;) or
    (&#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime and stop_datetime &lt;= &#39;2020-01-07 11:00:00&#39;)
  )

I try to make like this but is not correct, where i'm wrong please?

   inParams1.push([
         &quot;|&quot;,
         &quot;&amp;&quot;,
         [&quot;start_datetime&quot;, &quot;&lt;&quot;,  &#39;2020-01-07 09:00:00&#39;],
         [&#39;2020-01-07 09:00:00&#39;, &quot;&lt;=&quot;, &quot;stop_datetime&quot;],
         &quot;&amp;&quot;,
         [&quot;start_datetime&quot;, &quot;&lt;=&quot;, &#39;2020-01-07 11:00:00&#39;],
         [&#39;2020-01-07 11:00:00&#39;, &quot;&lt;=&quot;, &quot;stop_datetime&quot;],

         &quot;|&quot;,
         &quot;&amp;&quot;,
         [&#39;2020-01-07 09:00:00&#39;, &quot;&lt;=&quot;, &quot; start_datetime&quot;],
         [&quot;start_datetime&quot;, &quot;&lt;=&quot;,&#39;2020-01-07 11:00:00&#39;],
         &quot;&amp;&quot;,
         [&#39;2020-01-07 09:00:00&#39;, &quot;&lt;=&quot;,  &quot;stop_datetime&quot;],
     [&quot;stop_datetime&quot;, &quot;&lt;=&quot;,&#39;2020-01-07 11:00:00&#39;]
]);

Please i need your help, i have many days working and i can't find a solution 搜索域:Odoo中的多个条件

答案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 = ([(&quot;field_&quot; + x, &quot;=&quot;, &quot;value_&quot; + x)] for x in &quot;ABCDEFGH&quot;)                                                                                                

In [8]: OR([OR([AND([a,b]),AND([c,d])]),OR([AND([e,f]),AND([g,h])])])                                                                                                              
Out[8]: 
[&#39;|&#39;,
 &#39;|&#39;,
 &#39;&amp;&#39;,
 (&#39;field_A&#39;, &#39;=&#39;, &#39;value_A&#39;),
 (&#39;field_B&#39;, &#39;=&#39;, &#39;value_B&#39;),
 &#39;&amp;&#39;,
 (&#39;field_C&#39;, &#39;=&#39;, &#39;value_C&#39;),
 (&#39;field_D&#39;, &#39;=&#39;, &#39;value_D&#39;),
 &#39;|&#39;,
 &#39;&amp;&#39;,
 (&#39;field_E&#39;, &#39;=&#39;, &#39;value_E&#39;),
 (&#39;field_F&#39;, &#39;=&#39;, &#39;value_F&#39;),
 &#39;&amp;&#39;,
 (&#39;field_G&#39;, &#39;=&#39;, &#39;value_G&#39;),
 (&#39;field_H&#39;, &#39;=&#39;, &#39;value_H&#39;)]

答案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 &lt;= &#39;2020-01-07 09:00:00&#39; and &#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime) or
    (start_datetime &lt;= &#39;2020-01-07 11:00:00&#39; and &#39;2020-01-07 11:00:00&#39; &lt;= stop_datetime)
  ) or (
    (&#39;2020-01-07 09:00:00&#39; &lt;= start_datetime and start_datetime &lt;= &#39;2020-01-07 11:00:00&#39;) or
    (&#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime and stop_datetime &lt;= &#39;2020-01-07 11:00:00&#39;)
  )

Is the same as this:

    (start_datetime &lt;= &#39;2020-01-07 09:00:00&#39; and &#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime)
     or
    (start_datetime &lt;= &#39;2020-01-07 11:00:00&#39; and &#39;2020-01-07 11:00:00&#39; &lt;= stop_datetime)
    or 
    (&#39;2020-01-07 09:00:00&#39; &lt;= start_datetime and start_datetime &lt;= &#39;2020-01-07 11:00:00&#39;) 
    or
    (&#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime and stop_datetime &lt;= &#39;2020-01-07 11:00:00&#39;)

So just try this:

    [    &#39;|&#39;
         &quot;&amp;&quot;,
         [&quot;start_datetime&quot;, &quot;&lt;&quot;,  &#39;2020-01-07 09:00:00&#39;],
         [&quot;stop_datetime&quot;, &quot;&gt;=&quot;, &#39;2020-01-07 09:00:00&#39;],
         &#39;|&#39;,
         &quot;&amp;&quot;,
         [&quot;start_datetime&quot;, &quot;&lt;=&quot;, &#39;2020-01-07 11:00:00&#39;],
         [&quot;stop_datetime&quot;, &quot;&gt;=&quot;, &#39;2020-01-07 11:00:00&#39;],
         &#39;|&#39;,
         &quot;&amp;&quot;,
         [&quot;start_datetime&quot;, &quot;&gt;=&quot;, &#39;2020-01-07 09:00:00&#39;],
         [&quot;start_datetime&quot;, &quot;&lt;=&quot;,&#39;2020-01-07 11:00:00&#39;],
         &quot;&amp;&quot;,
         [&quot;stop_datetime&quot;, &quot;&gt;=&quot;,  &#39;2020-01-07 09:00:00&#39;],
         [&quot;stop_datetime&quot;, &quot;&lt;=&quot;,&#39;2020-01-07 11:00:00&#39;]
     ] 

let me know if it doesn't work for you.

huangapple
  • 本文由 发表于 2020年1月6日 20:21:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612047.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定