~numerigraphe-team/ocb-server/7.0-import-non-local-warning-mat

« back to all changes in this revision

Viewing changes to openerp/addons/base/tests/test_base.py

  • Committer: Martin Trigaux
  • Date: 2014-02-18 10:09:29 UTC
  • mfrom: (5236.1.2 7.0)
  • Revision ID: mat@openerp.com-20140218100929-qeg0rz1fmta2ni9y
[MERGE] [FIX] orm: read_group doesn't take referenced fields or aggregated fields in account when sorting (opw 598942)

Sorting was done using a search on ids that where found in a custom SQL field,
only 1 record among aggregated records with same groupby value was used
when using search for ordering, resulting data ordered on
max(aggregated_data).field_value instead of sum(aggregated_data.field_value).

Show diffs side-by-side

added added

removed removed

Lines of Context:
289
289
          {'name': 'Alice', 'login': 'alice', 'color': 1, 'function': 'Friend'},
290
290
          {'name': 'Bob', 'login': 'bob', 'color': 2, 'function': 'Friend'},
291
291
          {'name': 'Eve', 'login': 'eve', 'color': 3, 'function': 'Eavesdropper'},
 
292
          {'name': 'Nab', 'login': 'nab', 'color': 2, 'function': '5$ Wrench'},
292
293
        ]:
293
294
          self.res_users.create(cr, uid, user_data)
294
295
 
298
299
          self.assertIn('color', group_data, "Aggregated data for the column 'color' is not present in read_group return values")
299
300
          self.assertEqual(group_data['color'], 3, "Incorrect sum for aggregated data for the column 'color'")
300
301
 
 
302
        groups_data = self.res_users.read_group(cr, uid, domain=[('login', 'in', ('alice', 'bob', 'eve'))], fields=['name', 'color'], groupby='name', orderby='name DESC, color asc')
 
303
        self.assertEqual(len(groups_data), 3, "Incorrect number of results when grouping on a field")
 
304
        self.assertEqual([user['name'] for user in groups_data], ['Eve', 'Bob', 'Alice'], 'Incorrect ordering of the list')
 
305
 
 
306
        groups_data = self.res_users.read_group(cr, uid, domain=[('login', 'in', ('alice', 'bob', 'eve', 'nab'))], fields=['function', 'color'], groupby='function', orderby='color ASC')
 
307
        self.assertEqual(len(groups_data), 3, "Incorrect number of results when grouping on a field")
 
308
        self.assertEqual(groups_data, sorted(groups_data, key=lambda x: x['color']), 'Incorrect ordering of the list')
 
309
 
301
310
class test_partner_recursion(common.TransactionCase):
302
311
 
303
312
    def setUp(self):