gpt4 book ai didi

python - 我不明白普通波兰语表示法(NPN 或 PN)。如何在 Odoo 中构建复杂域?

转载 作者:数据小太阳 更新时间:2023-10-29 02:03:32 27 4
gpt4 key购买 nike

有人可以将以下波兰语表示法翻译成对应的 SQL 表示法吗:

['|', '&', ('is_company','=', True),('parent_id', '=', False),('company_name', '!=', False),('company_name', '!=', '')]

我的猜测是:

is_company = True OR parent_id = False AND company_name <> False AND company_name <> ''

无论我多么努力地理解它,我都无法理解这个符号的概念。请帮忙。

更新

我试图将上述符号扩展为:


((is_company = True AND parent_id = False) OR company_name <> False) AND company_name <> '' AND customer_type_id <> False

最佳答案

我完全同意你的看法,每次我必须使用这种波兰表示法来做一个复杂的领域时,我都必须绞尽脑汁来管理它。

我认为您要查找的域是:

['&amp;', '|', '&amp;', ('is_company', '=', True), ('parent_id', '=', False), ('company_name', '!=', False), '&amp;', ('company_name', '!=', ''), ('customer_type_id', '!=', False)]

我编写了一个方法来获取这些复杂的域,并且它正在运行:

首先我写一封信代替每个条件:

A => is_company = True => ('is_company', '=', True)
B => parent_id = False => ('parent_id', '=', False)
C => company_name <> False => ('company_name', '!=', False)
D => company_name <> '' => ('company_name', '!=', '')
E => customer_type_id <> False => ('customer_type_id', '!=', False)

然后仅使用字母和标准运算符构建您需要的表达式,忘记波兰语表示法和条件:

Step 0. => ((A and B) or C) and D and E

然后,将您应该首先执行的操作分组(到目前为止不要介意缺少的操作符):

Step 1. => ((A and B) or C) and D and E
Step 2. => (AB or C) and D and E
Step 3. => ABC and D and E
Step 4. => ABC and DE

现在我们只有一个运算符,让我们再次开始分解它(并将运算符移动到每对条件的左侧),按照与操作分组相反的顺序(例如,从步骤 3 到 4 你分组 DE,所以现在,从第 4 步到第 3 步,分解 DE 并将其运算符移到其左侧):

Step 4. => and ABC DE
Step 3. => and ABC and D E
Step 2. => and or AB C and D E
Step 1. => and or and A B C and D E

现在更改运算符并添加逗号、引号和括号:

['&amp;', '|', '&amp;', A, B, C, '&amp;', D, E]

最后,用条件替换字母,您就得到了您的域。最好当面解释一下,但也许您能够理解所有内容。

Note: I don't remove the &amp; operators (despite if you don't writethem, Odoo should take them by default) because my experience is thatwith largest domains, if I didn't write the &amp;, the domain didn'twork. I guess this happened when there was a lot of nested conditions,but my advice is to write always them.

关于python - 我不明白普通波兰语表示法(NPN 或 PN)。如何在 Odoo 中构建复杂域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48523138/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com