KERNEL,BASE: fix _where_calc and domain get for rule

bzr revid: ced-7a8713933b54f837db2312e605a7afad7dbf91c5
This commit is contained in:
ced 2007-06-07 10:35:05 +00:00
parent 6a67746357
commit 588fbd837f
2 changed files with 18 additions and 10 deletions

View File

@ -110,23 +110,30 @@ class ir_rule(osv.osv):
dom = eval("[('%s', '%s', %s)]"%(rule.field_id.name, rule.operator, rule.operand), {'user': self.pool.get('res.users').browse(cr, 1, uid), 'time':time})
clause.setdefault(rule.rule_group.id, [])
clause[rule.rule_group.id].append(obj._where_calc(cr, uid, dom))
str = ''
query = ''
val = []
for g in clause.values():
if not g:
continue
if len(str):
str += ' AND '
str += '('
if len(query):
query += ' AND '
query += '('
first = True
for c in g:
if not first:
str += ' OR '
query += ' OR '
first = False
str += '('+c[0][0]+')'
query += '('
first2 = True
for clause in c[0]:
if not first2:
query += ' AND '
first2 = False
query += clause
query += ')'
val += c[1]
str += ')'
return str, val
query += ')'
return query, val
domain_get = tools.cache()(domain_get)
def write(self, cr, uid, *args, **argv):

View File

@ -1338,7 +1338,7 @@ class orm(object):
return result
# TODO: ameliorer avec NULL
def _where_calc(self, cr, user, args):
def _where_calc(self, cr, user, args, context={}):
# if the object has a field named 'active', filter out all inactive
# records unless they were explicitely asked for
if 'active' in self._columns:
@ -1381,6 +1381,7 @@ class orm(object):
i+=1
elif field._type=='many2many':
#XXX Fixme
if args[i][1]=='child_of':
if isinstance(args[i][2], basestring):
ids2 = [x[0] for x in self.pool.get(field._obj).name_search(cr, user, args[i][2], [], 'like')]
@ -1516,7 +1517,7 @@ class orm(object):
def search(self, cr, user, args, offset=0, limit=None, order=None, context={}):
# compute the where, order by, limit and offset clauses
(qu1,qu2,tables) = self._where_calc(cr, user, args)
(qu1,qu2,tables) = self._where_calc(cr, user, args, context)
if len(qu1):
qu1 = ' where '+string.join(qu1,' and ')