openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #07549
[Merge] lp:~openerp-dev/openobject-server/trunk-bug-740799-nch into lp:openobject-server
Naresh(OpenERP) has proposed merging lp:~openerp-dev/openobject-server/trunk-bug-740799-nch into lp:openobject-server.
Requested reviews:
Vo Minh Thu (OpenERP) (vmt-openerp)
Related bugs:
Bug #740799 in OpenERP Server: "[filtering] does not support hierarchy"
https://bugs.launchpad.net/openobject-server/+bug/740799
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-bug-740799-nch/+merge/62606
--
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-bug-740799-nch/+merge/62606
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-server/trunk-bug-740799-nch.
=== modified file 'openerp/addons/base/test/test_osv_expression.yml'
--- openerp/addons/base/test/test_osv_expression.yml 2010-12-29 17:42:23 +0000
+++ openerp/addons/base/test/test_osv_expression.yml 2011-05-27 05:51:03 +0000
@@ -1,4 +1,24 @@
-
+ Testing for hierarchical search in M2M
+-
+ !python {model: res.partner }: |
+ ids = self.search(cr, uid, [('category_id', 'child_of','supplier')])
+ assert len(ids) >= 1, ids
+
+-
+ Test hierarchical search in M2M with child ID1
+-
+ !python {model: res.partner }: |
+ ids = self.search(cr, uid, [('category_id', 'child_of','Components Supplier')])
+ assert len(ids) >= 1, ids
+-
+ Test hierarchical search in M2M with child ID2
+-
+ !python {model: res.partner }: |
+ ids = self.search(cr, uid, [('category_id', 'child_of','Miscellaneous Suppliers')])
+ assert len(ids) >= 1, ids
+
+-
Testing that some domain expressions work
-
!python {model: res.partner.address }: |
@@ -40,7 +60,7 @@
-
!assert {model: res.partner, search: "[('category_id', '=', False)]"}:
- category_id in (False, None, [])
--
+-
Filtering on invalid value across x2many relationship should return an empty set
-
!assert {model: res.partner, search: "[('address.city','=','foo')]", count: 0, string: "Searching for address.city = foo should give empty results"}
=== modified file 'openerp/osv/expression.py'
--- openerp/osv/expression.py 2011-02-07 12:57:23 +0000
+++ openerp/osv/expression.py 2011-05-27 05:51:03 +0000
@@ -105,6 +105,14 @@
return ids + rg(ids2, table, parent)
return [(left, 'in', rg(ids, table, parent or table._parent_name))]
+ def get_child_of_result(value):
+ if isinstance(value, basestring):
+ return [x[0] for x in field_obj.name_search(cr, uid, value, [], 'ilike', context=context, limit=None)]
+ elif isinstance(value, (int, long)):
+ return list([value])
+ else:
+ return list(value)
+
self.__main_table = table
self.__all_tables.add(table)
@@ -181,10 +189,7 @@
elif field._type == 'one2many':
# Applying recursivity on field(one2many)
if operator == 'child_of':
- if isinstance(right, basestring):
- ids2 = [x[0] for x in field_obj.name_search(cr, uid, right, [], 'like', context=context, limit=None)]
- else:
- ids2 = list(right)
+ ids2 = get_child_of_result(right)
if field._obj != working_table._name:
dom = _rec_get(ids2, field_obj, left=left, prefix=field._obj)
else:
@@ -228,11 +233,7 @@
elif field._type == 'many2many':
#FIXME
if operator == 'child_of':
- if isinstance(right, basestring):
- ids2 = [x[0] for x in field_obj.name_search(cr, uid, right, [], 'like', context=context, limit=None)]
- else:
- ids2 = list(right)
-
+ ids2 = get_child_of_result(right)
def _rec_convert(ids):
if field_obj == table:
return ids
@@ -276,13 +277,7 @@
elif field._type == 'many2one':
if operator == 'child_of':
- if isinstance(right, basestring):
- ids2 = [x[0] for x in field_obj.name_search(cr, uid, right, [], 'like', limit=None)]
- elif isinstance(right, (int, long)):
- ids2 = list([right])
- else:
- ids2 = list(right)
-
+ ids2 = get_child_of_result(right)
self.__operator = 'in'
if field._obj != working_table._name:
dom = _rec_get(ids2, field_obj, left=left, prefix=field._obj)
@@ -292,12 +287,12 @@
else:
def _get_expression(field_obj,cr, uid, left, right, operator, context=None):
if context is None:
- context = {}
+ context = {}
c = context.copy()
c['active_test'] = False
#Special treatment to ill-formed domains
operator = ( operator in ['<','>','<=','>='] ) and 'in' or operator
-
+
dict_op = {'not in':'!=','in':'=','=':'in','!=':'not in','<>':'not in'}
if isinstance(right,tuple):
right = list(right)
@@ -319,7 +314,7 @@
elif isinstance(right,(list,tuple)):
m2o_str = True
for ele in right:
- if not isinstance(ele, basestring):
+ if not isinstance(ele, basestring):
m2o_str = False
break
elif right == []:
@@ -335,7 +330,7 @@
new_op = '!='
#Is it ok to put 'left' and not 'id' ?
self.__exp[i] = (left,new_op,False)
-
+
if m2o_str:
self.__exp[i] = _get_expression(field_obj,cr, uid, left, right, operator, context=context)
else: