diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index ab65a0565d..df354e3129 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -1981,14 +1981,10 @@ class ModelSQL(ModelStorage): 'WHERE id IN (' + ','.join(['%s' for x in child_ids]) + ')', child_ids) - if parent_id is False: - cursor.execute('SELECT id FROM "' + self._table + '" WHERE "' +\ - field_name + '" IS NULL') - else: - cursor.execute('SELECT id FROM "' + self._table + '" WHERE "' +\ - field_name + '" = %s', (parent_id,)) - brother_ids = [x[0] for x in cursor.fetchall()] - + # Use root user to by-pass rules + brother_ids = self.search(cursor, 0, [ + (field_name, '=', parent_id), + ]) if brother_ids[-1] != object_id: next_id = brother_ids[brother_ids.index(object_id) + 1] cursor.execute('SELECT "' + left + '", "' + right + '" ' \