diff --git a/bin/osv/expression.py b/bin/osv/expression.py index 60512fe0143..495d38b9d08 100644 --- a/bin/osv/expression.py +++ b/bin/osv/expression.py @@ -88,7 +88,6 @@ class expression(object): exp = exp[0] self.__exp = exp - self.__iexp = exp self.__operator = '&' self.__children = [] @@ -317,7 +316,6 @@ class expression(object): query = '(%s AND (%s))' % (joins, query) if isinstance(params, basestring): params = [params] - #print 'SQL:', repr(self.__iexp), '->', query return (query, params) else: diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 9173ecf07d3..832f468c951 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -2188,9 +2188,6 @@ class orm(orm_template): # records unless they were explicitely asked for if 'active' in self._columns and (active_test and context.get('active_test', True)): args = [('&', ('active', '=', 1), tuple(args))] - #active_found = reduce( lambda x, y: x or y == 'active', args, False ) - #if not active_found: - # args.append(('active', '=', 1)) if args: import expression @@ -2202,239 +2199,6 @@ class orm(orm_template): else: qu1, qu2, tables = [], [], ['"%s"' % self._table] - print "expression: %r\n%r\n%r\n%r" % (args, qu1, qu2, tables) - """ - tables=['"'+self._table+'"'] - joins=[] - for i, argument in zip(range(len(args)), args): - table=self - assert argument[1] in ('like','!=','ilike','=like', 'not like', 'not ilike', 'not in','inselect','child_of','in','=','<>','<','>','>=','<='), _('Error ! Bad clause operand "%s".') % (argument[1],) - if argument[1] == 'inselect': - raise except_orm(_('ValidateError'), - _("The clause 'inselect' can not be used outside the orm!")) - if argument[0] in self._inherit_fields: - table=self.pool.get(self._inherit_fields[argument[0]][0]) - if ('"'+table._table+'"' not in tables): - tables.append('"'+table._table+'"') - joins.append(('id', 'join', '%s.%s' % (self._table, self._inherits[table._name]), table)) - fargs = argument[0].split('.', 1) - field = table._columns.get(fargs[0],False) - if not field: - if argument[0] == 'id' and argument[1] == 'child_of': - ids2 = argument[2] - def _rec_get(ids, table, parent): - if not ids: - return [] - ids2 = table.search(cr, user, [(parent, 'in', ids)], context=context) - return ids + _rec_get(ids2, table, parent) - args[i] = (argument[0], 'in', ids2 + _rec_get(ids2, table, table._parent_name), table) - continue - if len(fargs) > 1: - if field._type == 'many2one': - args[i] = (fargs[0], 'in', self.pool.get(field._obj).search(cr, user, [(fargs[1], argument[1], argument[2])], context=context)) - continue - if field._properties: # = fields function - arg = [args.pop(i)] - j = i - while j table._name: - args[i] = (argument[0],'in',ids2+_rec_get(ids2, self.pool.get(field._obj), table._parent_name), table) - else: - args[i] = ('id','in',ids2+_rec_get(ids2, table, argument[0]), table) - else: - if isinstance(argument[2], basestring): - res_ids = self.pool.get(field._obj).name_search(cr, user, argument[2], [], argument[1]) - args[i] = (argument[0],'in',map(lambda x: x[0], res_ids), table) - else: - args[i] += (table,) - else: - if field.translate: - if argument[1] in ('like', 'ilike', 'not like', 'not ilike'): - args[i] = (argument[0], argument[1], '%%%s%%' % argument[2]) - query1 = '(SELECT res_id FROM ir_translation ' \ - 'WHERE name = %s AND lang = %s ' \ - 'AND type = %s ' \ - 'AND VALUE ' + argument[1] + ' %s)' - query2 = [table._name + ',' + argument[0], - context.get('lang', False) or 'en_US', - 'model', - argument[2]] - query1 += ' UNION ' - query1 += '(SELECT id FROM "' + table._table + '" ' \ - 'WHERE "' + argument[0] + '" ' + argument[1] + ' %s)' - query2 += [argument[2]] - args[i] = ('id', 'inselect', (query1, query2), table) - else: - args[i] += (table,) - args.extend(joins) - - qu1, qu2 = [], [] - for x in args: - table=self - if len(x) > 3: - table=x[3] - if x[1] == 'inselect': - qu1.append('(%s.%s in (%s))' % (table._table, x[0], x[2][0])) - qu2 += x[2][1] - elif x[1]=='not in': - if len(x[2])>0: - todel = [] - for xitem in range(len(x[2])): - if x[2][xitem]==False and isinstance(x[2][xitem],bool): - todel.append(xitem) - for xitem in todel[::-1]: - del x[2][xitem] - if x[0]=='id': - qu1.append('(%s.id not in (%s))' % (table._table, ','.join(['%d'] * len(x[2])),)) - else: - qu1.append('(%s.%s not in (%s))' % (table._table, x[0], ','.join([table._columns[x[0]]._symbol_set[0]]*len(x[2])))) - if todel: - qu1[-1] = '('+qu1[-1]+' or '+x[0]+' is null)' - qu2+=x[2] - else: - qu1.append(' (1=0)') - elif x[1] != 'in': -#FIXME: this replace all (..., '=', False) values with 'is null' and this is -# not what we want for real boolean fields. The problem is, we can't change it -# easily because we use False everywhere instead of None -# NOTE FAB: we can't use None because it is not accepted by XML-RPC, that's why -# boolean (0-1), None -> False -# Ged> boolean fields are not always = 0 or 1 - if (x[2] is False) and (x[1]=='='): - qu1.append(x[0]+' is null') - elif (x[2] is False) and (x[1]=='<>' or x[1]=='!='): - qu1.append(x[0]+' is not null') - else: - if x[0]=='id': - if x[1]=='join': - qu1.append('(%s.%s = %s)' % (table._table, x[0], x[2])) - else: - qu1.append('(%s.%s %s %%s)' % (table._table, x[0], x[1])) - qu2.append(x[2]) - else: - add_null = False - if x[1] in ('like', 'ilike', 'not like', 'not ilike'): - if isinstance(x[2], str): - str_utf8 = x[2] - elif isinstance(x[2], unicode): - str_utf8 = x[2].encode('utf-8') - else: - str_utf8 = str(x[2]) - qu2.append('%%%s%%' % str_utf8) - if not str_utf8: - add_null = True - else: - if x[0] in table._columns: - qu2.append(table._columns[x[0]]._symbol_set[1](x[2])) - if x[1]=='=like': - x1 = 'like' - else: - x1 = x[1] - if x[0] in table._columns: - if x[1] in ('like', 'ilike', 'not like', 'not ilike'): - - qu1.append('(%s.%s %s %s)' % (table._table, - x[0], x1, '%s')) - else: - qu1.append('(%s.%s %s %s)' % (table._table, - x[0], x1, - table._columns[x[0]]._symbol_set[0])) - else: - qu1.append('(%s.%s %s \'%s\')' % (table._table, x[0], x1, x[2])) - - if add_null: - qu1[-1] = '('+qu1[-1]+' or '+x[0]+' is null)' - elif x[1]=='in': - if len(x[2])>0: - todel = [] - for xitem in range(len(x[2])): - if x[2][xitem]==False and isinstance(x[2][xitem],bool): - todel.append(xitem) - for xitem in todel[::-1]: - del x[2][xitem] - #TODO fix max_stack_depth - if x[0]=='id': - qu1.append('(%s.id in (%s))' % (table._table, ','.join(['%d'] * len(x[2])),)) - else: - qu1.append('(%s.%s in (%s))' % (table._table, x[0], ','.join([table._columns[x[0]]._symbol_set[0]]*len(x[2])))) - if todel: - qu1[-1] = '('+qu1[-1]+' or '+x[0]+' is null)' - qu2+=x[2] - else: - qu1.append(' (1=0)') -""" return (qu1,qu2,tables) def _check_qorder(self, word):