我不明白普通波兰语表示法(NPN 或 PN)。如何在 Odoo 中构建复杂域?
I don´t understand Normal Polish Notation (NPN or PN). How to build a complex domain in Odoo?
有人可以将以下波兰语表示法翻译成它的 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
我完全同意你的看法,每次我要用这种波兰语表示法做一个复杂的领域时,我都必须绞尽脑汁来管理它。
我认为您要查找的域名是:
['&', '|', '&', ('is_company', '=', True), ('parent_id', '=', False), ('company_name', '!=', False), '&', ('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
现在更改运算符并添加逗号、引号和方括号:
['&', '|', '&', A, B, C, '&', D, E]
最后,用条件替换字母,你就有了你的域名。最好当面解释,但也许你能理解一切。
Note: I don't remove the &
operators (despite if you don't write
them, Odoo should take them by default) because my experience is that
with largest domains, if I didn't write the &
, the domain didn't
work. I guess this happened when there was a lot of nested conditions,
but my advice is to write always them.
有人可以将以下波兰语表示法翻译成它的 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
我完全同意你的看法,每次我要用这种波兰语表示法做一个复杂的领域时,我都必须绞尽脑汁来管理它。
我认为您要查找的域名是:
['&', '|', '&', ('is_company', '=', True), ('parent_id', '=', False), ('company_name', '!=', False), '&', ('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
现在更改运算符并添加逗号、引号和方括号:
['&', '|', '&', A, B, C, '&', D, E]
最后,用条件替换字母,你就有了你的域名。最好当面解释,但也许你能理解一切。
Note: I don't remove the
&
operators (despite if you don't write them, Odoo should take them by default) because my experience is that with largest domains, if I didn't write the&
, the domain didn't work. I guess this happened when there was a lot of nested conditions, but my advice is to write always them.