bzr revid: olt@tinyerp.com-20081007145130-qmmogf0zbxirjv4m
This commit is contained in:
Olivier Laurent 2008-10-07 16:51:30 +02:00
parent f565d96c77
commit 00faaadc2e
2 changed files with 30 additions and 24 deletions

View File

@ -59,8 +59,8 @@ class expression(object):
doms = []
for o in table.browse(cr, uid, ids, context=context):
if doms:
doms.insert(0,'|')
doms += ['&',('parent_left','<',o.parent_right),('parent_left','>=',o.parent_left)]
doms.insert(0, '|')
doms += ['&', ('parent_left', '<', o.parent_right), ('parent_left', '>=', o.parent_left)]
if prefix:
return [(left, 'in', table.search(cr, uid, doms, context=context))]
return doms
@ -69,14 +69,14 @@ class expression(object):
if not ids:
return []
ids2 = table.search(cr, uid, [(parent, 'in', ids)], context=context)
return ids+rg(ids2, table, parent)
return ids + rg(ids2, table, parent)
return [(left, 'in', rg(ids, table, parent))]
self.__main_table = table
i = -1
while i+1<len(self.__exp):
i+=1
while i + 1<len(self.__exp):
i += 1
e = self.__exp[i]
if self._is_operator(e) or e == self.__DUMMY_LEAF:
continue
@ -114,19 +114,19 @@ class expression(object):
self.__exp[i] = self.__DUMMY_LEAF
else:
subexp = field.search(cr, uid, table, left, [self.__exp[i]])
# we assume that the expression is valid
# we assume that the expression is valid
# we create a dummy leaf for forcing the parsing of the resulting expression
self.__exp[i] = '&'
self.__exp.insert(i + 1, self.__DUMMY_LEAF)
for j, se in enumerate(subexp):
self.__exp.insert(i + 2 + j, se)
# else, the value of the field is store in the database, so we search on it
elif field._type == 'one2many':
if isinstance(right, basestring):
ids2 = [x[0] for x in field_obj.name_search(cr, uid, right, [], operator,limit=None)]
ids2 = [x[0] for x in field_obj.name_search(cr, uid, right, [], operator, limit=None)]
else:
ids2 = list(right)
if not ids2:
@ -138,7 +138,7 @@ class expression(object):
#FIXME
if operator == 'child_of':
if isinstance(right, basestring):
ids2 = [x[0] for x in field_obj.name_search(cr, uid, right, [], 'like',limit=None)]
ids2 = [x[0] for x in field_obj.name_search(cr, uid, right, [], 'like', limit=None)]
else:
ids2 = list(right)
@ -146,7 +146,7 @@ class expression(object):
if field_obj == table:
return ids
return self.__execute_recursive_in(cr, field._id1, field._rel, field._id2, ids)
dom = _rec_get(ids2, field_obj, working_table._parent_name)
ids2 = field_obj.search(cr, uid, dom, context=context)
self.__exp[i] = ('id', 'in', _rec_convert(ids2))
@ -159,7 +159,7 @@ class expression(object):
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)]
ids2 = [x[0] for x in field_obj.name_search(cr, uid, right, [], 'like', limit=None)]
else:
ids2 = list(right)
@ -171,7 +171,7 @@ class expression(object):
self.__exp = self.__exp[:i] + dom + self.__exp[i+1:]
else:
if isinstance(right, basestring):
res_ids = field_obj.name_search(cr, uid, right, [], operator,limit=None)
res_ids = field_obj.name_search(cr, uid, right, [], operator, limit=None)
right = map(lambda x: x[0], res_ids)
self.__exp[i] = (left, 'in', right)
else:
@ -204,7 +204,7 @@ class expression(object):
def __leaf_to_sql(self, leaf, table):
if leaf == self.__DUMMY_LEAF:
return ('(1=1)',[])
return ('(1=1)', [])
left, operator, right = leaf
if operator == 'inselect':
@ -288,7 +288,7 @@ class expression(object):
q1 = stack.pop()
q2 = stack.pop()
stack.append('(%s %s %s)' % (q1, ops[e], q2,))
query = ' AND '.join(reversed(stack))
joins = ' AND '.join(map(lambda j: j[0], self.__joins))
if joins:

View File

@ -45,12 +45,14 @@ module_list = []
module_class_list = {}
class_pool = {}
class except_osv(Exception):
def __init__(self, name, value, exc_type='warning'):
self.name = name
self.exc_type = exc_type
self.value = value
self.args = (exc_type,name)
self.args = (exc_type, name)
class osv_pool(netsvc.Service):
@ -71,9 +73,9 @@ class osv_pool(netsvc.Service):
self.exportMethod(self.execute_cr)
def init_set(self, cr, mode):
if mode<>self._init:
if mode <> self._init:
if mode:
self._init_parent={}
self._init_parent = {}
if not mode:
for o in self._init_parent:
self.get(o)._parent_store_compute(cr)
@ -87,7 +89,7 @@ class osv_pool(netsvc.Service):
if not object:
self.abortResponse(1, 'Object Error', 'warning',
'Object %s doesn\'t exist' % str(obj))
return getattr(object,method)(cr, uid, *args, **kw)
return getattr(object, method)(cr, uid, *args, **kw)
except orm.except_orm, inst:
self.abortResponse(1, inst.name, 'warning', inst.value)
except except_osv, inst:
@ -147,7 +149,7 @@ class osv_pool(netsvc.Service):
# adds a new object instance to the object pool.
# if it already existed, the instance is replaced
def add(self, name, obj_inst):
if self.obj_pool.has_key(name):
if name in self.obj_pool:
del self.obj_pool[name]
self.obj_pool[name] = obj_inst
@ -171,6 +173,7 @@ class osv_pool(netsvc.Service):
res.append(klass.createInstance(self, module, cr))
return res
class osv_memory(orm.orm_memory):
#__metaclass__ = inheritor
def __new__(cls):
@ -190,7 +193,7 @@ class osv_memory(orm.orm_memory):
# put objects in the pool var
#
def createInstance(cls, pool, module, cr):
name = hasattr(cls,'_name') and cls._name or cls._inherit
name = hasattr(cls, '_name') and cls._name or cls._inherit
parent_name = hasattr(cls, '_inherit') and cls._inherit
if parent_name:
print 'Inherit not supported in osv_memory object !'
@ -237,7 +240,7 @@ class osv(orm.orm):
else:
new.extend(cls.__dict__.get(s, []))
nattr[s] = new
name = hasattr(cls,'_name') and cls._name or cls._inherit
name = hasattr(cls, '_name') and cls._name or cls._inherit
cls = type(name, (cls, parent_class), nattr)
obj = object.__new__(cls)
obj.__init__(pool, cr)
@ -249,6 +252,7 @@ class osv(orm.orm):
self.pool = pool
orm.orm.__init__(self, cr)
class Cacheable(object):
_cache = UpdateableDict()
@ -270,6 +274,7 @@ class Cacheable(object):
self._cache.clear()
self._items = []
def filter_dict(d, fields):
res = {}
for f in fields + ['id']:
@ -277,6 +282,7 @@ def filter_dict(d, fields):
res[f] = d[f]
return res
class cacheable_osv(osv, Cacheable):
_relevant = ['lang']
@ -286,9 +292,9 @@ class cacheable_osv(osv, Cacheable):
def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
if not fields:
fields=[]
fields = []
if not context:
context={}
context = {}
fields = fields or self._columns.keys()
ctx = [context.get(x, False) for x in self._relevant]
result, tofetch = [], []
@ -330,7 +336,7 @@ class cacheable_osv(osv, Cacheable):
def write(self, cr, user, ids, values, context=None):
if not context:
context={}
context = {}
for id in ids:
self.invalidate((self._name, id))
return super(cacheable_osv, self).write(cr, user, ids, values, context)