read_group 方法中的域
Domain in read_group method
有标准方法
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False)
我在上面调用一个 super 并传递这样的域
[('end_date', '>=', '2019-05-01'), ('end_date', '<=', '2019-05-30'), ('employee', 'in', [49]), ('state', 'in', ['done'])]
而且有效。
但是当我尝试附加
domain.append(('&'))
domain.append(('state', 'in', ['progress']))
我明白了
File "/home/www/workspace/openerp-7.0-20140804-231303/openerp/osv/expression.py", line 201, in normalize_domain
assert expected == 0, 'This domain is syntactically not correct: %s' % (domain)
AssertionError: This domain is syntactically not correct: [('end_date', '>=', '2019-05-01'), ('end_date', '<=', '2019-05-30'), ('employee', 'in', [49]), ('state', 'in', ['done']), '&', ('state', 'in', ['progress'])]
基本上,需要按日期和状态 'done'
过滤所有记录,最重要的是状态 'progress'.
中的所有记录
更新。
如果我使用域
domain = [('end_date', '>=', '2019-05-01'), ('end_date', '<=', '2019-05-30'), ('employee', 'in', [49]),
('state', 'in', ['done'])]
我得到 3 条记录,
如果我使用
domain = [('employee', 'in', [49]), ('state', 'in', ['progress'])]
我得到了 2 条记录的结果,
但如果我像这样组合这些域,我会得到 0 条记录
domain = [('state', 'in', ['progress']),('end_date', '>=', '2019-05-01'), ('end_date', '<=', '2019-05-30'), ('employee', 'in', [49]),
('state', 'in', ['done'])]
我的域应该是什么样子才能获得 5 条记录?
可能的问题是 'progress'
中没有 end_date
的记录
逻辑运算符“&”和“|”有 2 个元数,这意味着 2 个三元组("normal" 具有 3 个条目的域元组)必须跟在它们后面。您只附加一个三元组。在您的情况下,您可以删除 '&' 的 append
,因为不使用任何逻辑运算符,everything/every 三元组将默认与 AND 组合。
逻辑运算符“!”有 arity 1,顺便说一句。
您可以在 the official documentation 中找到足够的信息。
A domain is a list of criteria, each criterion being a triple (either
a list or a tuple) of (field_name, operator, value) where:
field_name (str) a field name of the current model, or a relationship
traversal through a Many2one using dot-notation e.g. 'street' or
'partner_id.country' operator (str) an operator used to compare the
field_name with the value. Valid operators are:
= equals to != not equals to
> greater than
>= greater than or equal to
< less than
<= less than or equal to
=? unset or equals to (returns true if value is either None or False, otherwise behaves like =)
=like matches field_name against the value pattern. An underscore _ in the pattern stands for (matches) any single character; a percent sign % matches any string of zero or more characters.
like matches field_name against the %value% pattern. Similar to =like but wraps value with ‘%’ before matching
not like doesn’t match against the %value% pattern
ilike case insensitive like
not ilike case insensitive not like
=ilike case insensitive =like
in is equal to any of the items from value, value should be a list of items
not in is unequal to all of the items from value
child_of is a child (descendant) of a value record. Takes the semantics of the model into account (i.e following the relationship field named by _parent_name).
Domain criteria can be combined using logical operators in prefix form:
'&' logical AND, default operation to combine criteria following one
another. Arity 2 (uses the next 2 criteria or combinations).
'|' logical OR, arity 2.
'!' logical NOT, arity 1.
编辑:即使这应该是另一个问题,我也会尝试解决您的特殊域问题:
[('employee_id', 'in', [49]),
'|',
('state', 'in', ['progress']),
'&', ('state', 'in', ['done']),
'&', ('end_date', '>=', '2019-05-01'), ('end_date', '<=', '2019-05-30')]
结果应该是(伪):
EMPLOYEE with ID 49 AND
(STATE is progress OR (STATE is done AND END_DATE is between ...))
有标准方法
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False)
我在上面调用一个 super 并传递这样的域
[('end_date', '>=', '2019-05-01'), ('end_date', '<=', '2019-05-30'), ('employee', 'in', [49]), ('state', 'in', ['done'])]
而且有效。
但是当我尝试附加
domain.append(('&'))
domain.append(('state', 'in', ['progress']))
我明白了
File "/home/www/workspace/openerp-7.0-20140804-231303/openerp/osv/expression.py", line 201, in normalize_domain
assert expected == 0, 'This domain is syntactically not correct: %s' % (domain)
AssertionError: This domain is syntactically not correct: [('end_date', '>=', '2019-05-01'), ('end_date', '<=', '2019-05-30'), ('employee', 'in', [49]), ('state', 'in', ['done']), '&', ('state', 'in', ['progress'])]
基本上,需要按日期和状态 'done'
过滤所有记录,最重要的是状态 'progress'.
更新。
如果我使用域
domain = [('end_date', '>=', '2019-05-01'), ('end_date', '<=', '2019-05-30'), ('employee', 'in', [49]),
('state', 'in', ['done'])]
我得到 3 条记录,
如果我使用
domain = [('employee', 'in', [49]), ('state', 'in', ['progress'])]
我得到了 2 条记录的结果,
但如果我像这样组合这些域,我会得到 0 条记录
domain = [('state', 'in', ['progress']),('end_date', '>=', '2019-05-01'), ('end_date', '<=', '2019-05-30'), ('employee', 'in', [49]),
('state', 'in', ['done'])]
我的域应该是什么样子才能获得 5 条记录?
可能的问题是 'progress'
中没有 end_date
逻辑运算符“&”和“|”有 2 个元数,这意味着 2 个三元组("normal" 具有 3 个条目的域元组)必须跟在它们后面。您只附加一个三元组。在您的情况下,您可以删除 '&' 的 append
,因为不使用任何逻辑运算符,everything/every 三元组将默认与 AND 组合。
逻辑运算符“!”有 arity 1,顺便说一句。
您可以在 the official documentation 中找到足够的信息。
A domain is a list of criteria, each criterion being a triple (either a list or a tuple) of (field_name, operator, value) where:
field_name (str) a field name of the current model, or a relationship traversal through a Many2one using dot-notation e.g. 'street' or 'partner_id.country' operator (str) an operator used to compare the field_name with the value. Valid operators are:
= equals to != not equals to
> greater than
>= greater than or equal to
< less than
<= less than or equal to
=? unset or equals to (returns true if value is either None or False, otherwise behaves like =)
=like matches field_name against the value pattern. An underscore _ in the pattern stands for (matches) any single character; a percent sign % matches any string of zero or more characters.
like matches field_name against the %value% pattern. Similar to =like but wraps value with ‘%’ before matching
not like doesn’t match against the %value% pattern
ilike case insensitive like
not ilike case insensitive not like
=ilike case insensitive =like
in is equal to any of the items from value, value should be a list of items
not in is unequal to all of the items from value
child_of is a child (descendant) of a value record. Takes the semantics of the model into account (i.e following the relationship field named by _parent_name).
Domain criteria can be combined using logical operators in prefix form:
'&' logical AND, default operation to combine criteria following one another. Arity 2 (uses the next 2 criteria or combinations).
'|' logical OR, arity 2.
'!' logical NOT, arity 1.
编辑:即使这应该是另一个问题,我也会尝试解决您的特殊域问题:
[('employee_id', 'in', [49]),
'|',
('state', 'in', ['progress']),
'&', ('state', 'in', ['done']),
'&', ('end_date', '>=', '2019-05-01'), ('end_date', '<=', '2019-05-30')]
结果应该是(伪):
EMPLOYEE with ID 49 AND
(STATE is progress OR (STATE is done AND END_DATE is between ...))