搜索域:Odoo中的多个条件

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

Search domain : multiple condition in odoo

问题

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

PostgreSQL查询如下:

  1. SELECT
  2. *
  3. FROM
  4. calendar_event
  5. WHERE
  6. (
  7. (start_datetime <= '2020-01-07 09:00:00' and '2020-01-07 09:00:00' <= stop_datetime) or
  8. (start_datetime <= '2020-01-07 11:00:00' and '2020-01-07 11:00:00' <= stop_datetime)
  9. ) or (
  10. ('2020-01-07 09:00:00' <= start_datetime and start_datetime <= '2020-01-07 11:00:00') or
  11. ('2020-01-07 09:00:00' <= stop_datetime and stop_datetime <= '2020-01-07 11:00:00')
  12. )

我尝试做成这样,但不正确,请问我哪里错了?

  1. inParams1.push([
  2. "|",
  3. "&",
  4. ["start_datetime", "<", '2020-01-07 09:00:00'],
  5. ['2020-01-07 09:00:00', "<=", "stop_datetime"],
  6. "&",
  7. ["start_datetime", "<=", '2020-01-07 11:00:00'],
  8. ['2020-01-07 11:00:00', "<=", "stop_datetime"],
  9. "|",
  10. "&",
  11. ['2020-01-07 09:00:00', "<=", "start_datetime"],
  12. ["start_datetime", "<=",'2020-01-07 11:00:00'],
  13. "&",
  14. ['2020-01-07 09:00:00', "<=", "stop_datetime"],
  15. ["stop_datetime", "<=",'2020-01-07 11:00:00']
  16. ]);

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

英文:

How to convert this expression : ((A & B) | ( C & D)) | (( E & F) | (G & H)) in OpenERP domain syntax

PostgreSQL query is :

  1. SELECT
  2. *
  3. FROM
  4. calendar_event
  5. WHERE
  6. (
  7. (start_datetime &lt;= &#39;2020-01-07 09:00:00&#39; and &#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime) or
  8. (start_datetime &lt;= &#39;2020-01-07 11:00:00&#39; and &#39;2020-01-07 11:00:00&#39; &lt;= stop_datetime)
  9. ) or (
  10. (&#39;2020-01-07 09:00:00&#39; &lt;= start_datetime and start_datetime &lt;= &#39;2020-01-07 11:00:00&#39;) or
  11. (&#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime and stop_datetime &lt;= &#39;2020-01-07 11:00:00&#39;)
  12. )

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

  1. inParams1.push([
  2. &quot;|&quot;,
  3. &quot;&amp;&quot;,
  4. [&quot;start_datetime&quot;, &quot;&lt;&quot;, &#39;2020-01-07 09:00:00&#39;],
  5. [&#39;2020-01-07 09:00:00&#39;, &quot;&lt;=&quot;, &quot;stop_datetime&quot;],
  6. &quot;&amp;&quot;,
  7. [&quot;start_datetime&quot;, &quot;&lt;=&quot;, &#39;2020-01-07 11:00:00&#39;],
  8. [&#39;2020-01-07 11:00:00&#39;, &quot;&lt;=&quot;, &quot;stop_datetime&quot;],
  9. &quot;|&quot;,
  10. &quot;&amp;&quot;,
  11. [&#39;2020-01-07 09:00:00&#39;, &quot;&lt;=&quot;, &quot; start_datetime&quot;],
  12. [&quot;start_datetime&quot;, &quot;&lt;=&quot;,&#39;2020-01-07 11:00:00&#39;],
  13. &quot;&amp;&quot;,
  14. [&#39;2020-01-07 09:00:00&#39;, &quot;&lt;=&quot;, &quot;stop_datetime&quot;],
  15. [&quot;stop_datetime&quot;, &quot;&lt;=&quot;,&#39;2020-01-07 11:00:00&#39;]
  16. ]);

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

答案1

得分: 1

根据那个答案,您可以使用odoo.osv.expression

  1. from odoo.osv.expression import AND, OR
  2. a, b, c, d, e, f, g, h = ([("field_" + x, "=", "value_" + x)] for x in "ABCDEFGH")
  3. 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.

  1. In [6]: from odoo.osv.expression import AND,OR
  2. 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;)
  3. In [8]: OR([OR([AND([a,b]),AND([c,d])]),OR([AND([e,f]),AND([g,h])])])
  4. Out[8]:
  5. [&#39;|&#39;,
  6. &#39;|&#39;,
  7. &#39;&amp;&#39;,
  8. (&#39;field_A&#39;, &#39;=&#39;, &#39;value_A&#39;),
  9. (&#39;field_B&#39;, &#39;=&#39;, &#39;value_B&#39;),
  10. &#39;&amp;&#39;,
  11. (&#39;field_C&#39;, &#39;=&#39;, &#39;value_C&#39;),
  12. (&#39;field_D&#39;, &#39;=&#39;, &#39;value_D&#39;),
  13. &#39;|&#39;,
  14. &#39;&amp;&#39;,
  15. (&#39;field_E&#39;, &#39;=&#39;, &#39;value_E&#39;),
  16. (&#39;field_F&#39;, &#39;=&#39;, &#39;value_F&#39;),
  17. &#39;&amp;&#39;,
  18. (&#39;field_G&#39;, &#39;=&#39;, &#39;value_G&#39;),
  19. (&#39;field_H&#39;, &#39;=&#39;, &#39;value_H&#39;)]

答案2

得分: 0

你在括号内复杂化了筛选条件:

  1. (
  2. (start_datetime <= '2020-01-07 09:00:00' and '2020-01-07 09:00:00' <= stop_datetime) or
  3. (start_datetime <= '2020-01-07 11:00:00' and '2020-01-07 11:00:00' <= stop_datetime)
  4. ) or (
  5. ('2020-01-07 09:00:00' <= start_datetime and start_datetime <= '2020-01-07 11:00:00') or
  6. ('2020-01-07 09:00:00' <= stop_datetime and stop_datetime <= '2020-01-07 11:00:00')
  7. )

与下面的条件等效:

  1. (start_datetime <= '2020-01-07 09:00:00' and '2020-01-07 09:00:00' <= stop_datetime)
  2. or
  3. (start_datetime <= '2020-01-07 11:00:00' and '2020-01-07 11:00:00' <= stop_datetime)
  4. or
  5. ('2020-01-07 09:00:00' <= start_datetime and start_datetime <= '2020-01-07 11:00:00')
  6. or
  7. ('2020-01-07 09:00:00' <= stop_datetime and stop_datetime <= '2020-01-07 11:00:00')

所以请尝试使用以下条件:

  1. [
  2. '|',
  3. "&",
  4. ["start_datetime", "<", '2020-01-07 09:00:00'],
  5. ["stop_datetime", ">=", '2020-01-07 09:00:00'],
  6. '|',
  7. "&",
  8. ["start_datetime", "<=", '2020-01-07 11:00:00'],
  9. ["stop_datetime", ">=", '2020-01-07 11:00:00'],
  10. '|',
  11. "&",
  12. ["start_datetime", ">=", '2020-01-07 09:00:00'],
  13. ["start_datetime", "<=", '2020-01-07 11:00:00'],
  14. "&",
  15. ["stop_datetime", ">=", '2020-01-07 09:00:00'],
  16. ["stop_datetime", "<=", '2020-01-07 11:00:00']
  17. ]

如果不起作用,请告诉我。

英文:

You complicated the filter by parentheses:

<!-- language: python -->

  1. (
  2. (start_datetime &lt;= &#39;2020-01-07 09:00:00&#39; and &#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime) or
  3. (start_datetime &lt;= &#39;2020-01-07 11:00:00&#39; and &#39;2020-01-07 11:00:00&#39; &lt;= stop_datetime)
  4. ) or (
  5. (&#39;2020-01-07 09:00:00&#39; &lt;= start_datetime and start_datetime &lt;= &#39;2020-01-07 11:00:00&#39;) or
  6. (&#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime and stop_datetime &lt;= &#39;2020-01-07 11:00:00&#39;)
  7. )

Is the same as this:

  1. (start_datetime &lt;= &#39;2020-01-07 09:00:00&#39; and &#39;2020-01-07 09:00:00&#39; &lt;= stop_datetime)
  2. or
  3. (start_datetime &lt;= &#39;2020-01-07 11:00:00&#39; and &#39;2020-01-07 11:00:00&#39; &lt;= stop_datetime)
  4. or
  5. (&#39;2020-01-07 09:00:00&#39; &lt;= start_datetime and start_datetime &lt;= &#39;2020-01-07 11:00:00&#39;)
  6. or
  7. (&#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:

  1. [ &#39;|&#39;
  2. &quot;&amp;&quot;,
  3. [&quot;start_datetime&quot;, &quot;&lt;&quot;, &#39;2020-01-07 09:00:00&#39;],
  4. [&quot;stop_datetime&quot;, &quot;&gt;=&quot;, &#39;2020-01-07 09:00:00&#39;],
  5. &#39;|&#39;,
  6. &quot;&amp;&quot;,
  7. [&quot;start_datetime&quot;, &quot;&lt;=&quot;, &#39;2020-01-07 11:00:00&#39;],
  8. [&quot;stop_datetime&quot;, &quot;&gt;=&quot;, &#39;2020-01-07 11:00:00&#39;],
  9. &#39;|&#39;,
  10. &quot;&amp;&quot;,
  11. [&quot;start_datetime&quot;, &quot;&gt;=&quot;, &#39;2020-01-07 09:00:00&#39;],
  12. [&quot;start_datetime&quot;, &quot;&lt;=&quot;,&#39;2020-01-07 11:00:00&#39;],
  13. &quot;&amp;&quot;,
  14. [&quot;stop_datetime&quot;, &quot;&gt;=&quot;, &#39;2020-01-07 09:00:00&#39;],
  15. [&quot;stop_datetime&quot;, &quot;&lt;=&quot;,&#39;2020-01-07 11:00:00&#39;]
  16. ]

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:

确定