diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index bcc6e65401..41ac19b71d 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -491,21 +491,23 @@ class ModelSQL(ModelStorage): history_limit = cursor.limit_clause('', 1) history_args = [context['_datetime']] if len(fields_pre) : - fields_pre2 = ['"' + x + '"' for x in fields_pre \ - if x != '_timestamp'] + fields_pre2 = ['"%s"."%s" AS "%s"' % (self._table, x, x) + for x in fields_pre if x != '_timestamp'] if '_timestamp' in fields_pre: if not self.table_query(context): fields_pre2 += ['CAST(EXTRACT(EPOCH FROM ' - '(COALESCE(write_date, create_date))) AS ' + \ - FIELDS['numeric'].sql_type(self.create_date)[1] + \ - ') AS _timestamp'] + '(COALESCE("%s".write_date, "%s".create_date))) AS %s' + ') AS _timestamp' % + (self._table, self._table, + FIELDS['numeric'].sql_type(self.create_date)[1])] for i in range(0, len(ids), in_max): sub_ids = ids[i:i + in_max] red_sql, red_ids = reduce_ids('id', sub_ids) if domain1: cursor.execute('SELECT ' + \ - ','.join(fields_pre2 + ['id']) + \ + ','.join(fields_pre2 + + ['"%s".id AS id' % self._table]) + \ ' FROM ' + table_query + '\"' + self._table +'\" ' \ 'WHERE ' + red_sql + \ history_clause + \ @@ -514,7 +516,8 @@ class ModelSQL(ModelStorage): table_args + red_ids + history_args + domain2) else: cursor.execute('SELECT ' + \ - ','.join(fields_pre2 + ['id']) + \ + ','.join(fields_pre2 + + ['"%s".id AS id' % self._table]) + \ ' FROM ' + table_query + '\"' + self._table + '\" '\ 'WHERE ' + red_sql + \ history_clause + history_order + history_limit,