diff --git a/odoo/osv/expression.py b/odoo/osv/expression.py index 35c66c7f923..927c7fa739c 100644 --- a/odoo/osv/expression.py +++ b/odoo/osv/expression.py @@ -441,14 +441,14 @@ def select_from_where(cr, select_field, from_table, where_field, where_ids, wher res = [] if where_ids: if where_operator in ['<', '>', '>=', '<=']: - cr.execute('SELECT "%s" FROM "%s" WHERE "%s" %s %%s' % \ + cr.execute('SELECT DISTINCT "%s" FROM "%s" WHERE "%s" %s %%s' % \ (select_field, from_table, where_field, where_operator), (where_ids[0],)) # TODO shouldn't this be min/max(where_ids) ? res = [r[0] for r in cr.fetchall()] else: # TODO where_operator is supposed to be 'in'? It is called with child_of... for i in range(0, len(where_ids), cr.IN_MAX): subids = where_ids[i:i + cr.IN_MAX] - cr.execute('SELECT "%s" FROM "%s" WHERE "%s" IN %%s' % \ + cr.execute('SELECT DISTINCT "%s" FROM "%s" WHERE "%s" IN %%s' % \ (select_field, from_table, where_field), (tuple(subids),)) res.extend([r[0] for r in cr.fetchall()]) return res