Please review this at http://codereview.appspot.com/1785041/show

Affected files:
  M trytond/model/modelsql.py


Index: trytond/model/modelsql.py
===================================================================
--- a/trytond/model/modelsql.py
+++ b/trytond/model/modelsql.py
@@ -491,21 +491,23 @@
             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 @@
                             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,



-- 
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/

Attachment: pgpAN8aGU0dpC.pgp
Description: PGP signature

Reply via email to