[IMP] expression: fix [(o2m,not in,...)] domains, re-enable tests, cleanup
bzr revid: odo@openerp.com-20110922005431-gnym5pormtjkfu8q
This commit is contained in:
parent
c856d70bf5
commit
9497814729
|
@ -186,21 +186,23 @@
|
|||
partner_ids = self.search(cr, uid, [])
|
||||
partner_ids.sort()
|
||||
max_partner_id = max(partner_ids)
|
||||
|
||||
# Grab test sample data without using a normal
|
||||
# search domain, because we want to test these later,
|
||||
# so we can't rely on them!
|
||||
partners = self.browse(cr, uid, partner_ids)
|
||||
with_parent = []
|
||||
without_parent = []
|
||||
for x in partners:
|
||||
if x.parent_id and x.parent_id.id in partner_ids:
|
||||
with_parent.append(x.id)
|
||||
with_parent.sort()
|
||||
for x in partners:
|
||||
if not x.parent_id:
|
||||
without_parent.append(x.id)
|
||||
without_parent.sort()
|
||||
with_website = []
|
||||
for x in partners:
|
||||
if x.parent_id:
|
||||
with_parent.append(x.id)
|
||||
else:
|
||||
without_parent.append(x.id)
|
||||
if x.website:
|
||||
with_website.append(x.id)
|
||||
with_parent.sort()
|
||||
without_parent.sort()
|
||||
with_website.sort()
|
||||
|
||||
# We treat null values differently than in SQL. For instance in SQL:
|
||||
|
@ -400,13 +402,9 @@
|
|||
res_11.sort()
|
||||
res_12.sort()
|
||||
res_13.sort()
|
||||
|
||||
print ">>> 11:", res_11
|
||||
#assert res_10 == res_11
|
||||
assert res_10 == res_11
|
||||
assert res_10 == res_12
|
||||
print ">>> 12:", res_12
|
||||
assert res_10 == res_13
|
||||
print ">>> 13:", res_13
|
||||
|
||||
# child_of x returns x and its children (direct or not).
|
||||
company = self.browse(cr, uid, ref('ymltest_company3'))
|
||||
|
@ -416,13 +414,13 @@
|
|||
res_1.sort()
|
||||
res_2 = self.search(cr, uid, [('id', 'child_of', ref('ymltest_company3'))])
|
||||
res_2.sort()
|
||||
#res_3 = self.search(cr, uid, [('id', 'child_of', [company.name])]) # TODO
|
||||
#res_3.sort()
|
||||
res_3 = self.search(cr, uid, [('id', 'child_of', [company.name])])
|
||||
res_3.sort()
|
||||
res_4 = self.search(cr, uid, [('id', 'child_of', company.name)])
|
||||
res_4.sort()
|
||||
assert res_1 == expected
|
||||
assert res_2 == expected
|
||||
#assert res_3 == expected
|
||||
assert res_3 == expected
|
||||
assert res_4 == expected
|
||||
-
|
||||
Verify that normalize_domain() works.
|
||||
|
|
|
@ -391,14 +391,18 @@ class expression(object):
|
|||
return [(left, 'in', recursive_children(ids, left_model, parent or left_model._parent_name))]
|
||||
|
||||
def to_ids(value, field_obj):
|
||||
""" Normalize a single id, or a string, or a list of ids to a list of ids.
|
||||
"""
|
||||
"""Normalize a single id or name, or a list of those, into a list of ids"""
|
||||
names = []
|
||||
if isinstance(value, basestring):
|
||||
return [x[0] for x in field_obj.name_search(cr, uid, value, [], 'ilike', context=context, limit=None)]
|
||||
names = [value]
|
||||
if value and isinstance(value, (tuple, list)) and isinstance(value[0], basestring):
|
||||
names = value
|
||||
if names:
|
||||
return flatten([[x[0] for x in field_obj.name_search(cr, uid, n, [], 'ilike', context=context, limit=None)] \
|
||||
for n in names])
|
||||
elif isinstance(value, (int, long)):
|
||||
return [value]
|
||||
else:
|
||||
return list(value)
|
||||
return list(value)
|
||||
|
||||
i = -1
|
||||
while i + 1<len(self.__exp):
|
||||
|
@ -505,9 +509,10 @@ class expression(object):
|
|||
call_null = False
|
||||
self.__exp[i] = FALSE_LEAF
|
||||
else:
|
||||
call_null = False
|
||||
o2m_op = 'not in' if operator in NEGATIVE_TERM_OPERATORS else 'in'
|
||||
self.__exp[i] = ('id', o2m_op, select_from_where(cr, field._fields_id, field_obj._table, 'id', ids2, operator))
|
||||
ids2 = select_from_where(cr, field._fields_id, field_obj._table, 'id', ids2, operator)
|
||||
if ids2:
|
||||
call_null = False
|
||||
self.__exp[i] = ('id', 'in', ids2)
|
||||
|
||||
if call_null:
|
||||
o2m_op = 'in' if operator in NEGATIVE_TERM_OPERATORS else 'not in'
|
||||
|
|
Loading…
Reference in New Issue