[MERGE] forward port branch saas-15 up to 75853066a1
This commit is contained in:
@@ -163,6 +163,25 @@ class TestORM(TransactionCase):
|
||||
['date:month', 'date:day'], lazy=False)
|
||||
self.assertEqual(len(res), len(partner_ids))
|
||||
|
||||
# combine groupby and orderby
|
||||
months = ['February 2013', 'January 2013', 'December 2012', 'November 2012']
|
||||
res = partners.read_group([('id', 'in', partner_ids)], ['date'],
|
||||
groupby=['date:month'], orderby='date:month DESC')
|
||||
self.assertEqual([item['date:month'] for item in res], months)
|
||||
|
||||
# order by date should reorder by date:month
|
||||
res = partners.read_group([('id', 'in', partner_ids)], ['date'],
|
||||
groupby=['date:month'], orderby='date DESC')
|
||||
self.assertEqual([item['date:month'] for item in res], months)
|
||||
|
||||
# order by date should reorder by date:day
|
||||
days = ['11 Feb 2013', '28 Jan 2013', '14 Jan 2013', '07 Jan 2013',
|
||||
'31 Dec 2012', '17 Dec 2012', '19 Nov 2012']
|
||||
res = partners.read_group([('id', 'in', partner_ids)], ['date'],
|
||||
groupby=['date:month', 'date:day'],
|
||||
orderby='date DESC', lazy=False)
|
||||
self.assertEqual([item['date:day'] for item in res], days)
|
||||
|
||||
def test_write_duplicate(self):
|
||||
p1 = self.env['res.partner'].create({'name': 'W'})
|
||||
(p1 + p1).write({'name': 'X'})
|
||||
|
||||
+12
-5
@@ -1698,31 +1698,38 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
|
||||
"""
|
||||
orderby_terms = []
|
||||
groupby_terms = [gb['qualified_field'] for gb in annotated_groupbys]
|
||||
groupby_fields = [gb['groupby'] for gb in annotated_groupbys]
|
||||
if not orderby:
|
||||
return groupby_terms, orderby_terms
|
||||
|
||||
self._check_qorder(orderby)
|
||||
|
||||
# when a field is grouped as 'foo:bar', both orderby='foo' and
|
||||
# orderby='foo:bar' generate the clause 'ORDER BY "foo:bar"'
|
||||
groupby_fields = {
|
||||
gb[key]: gb['groupby']
|
||||
for gb in annotated_groupbys
|
||||
for key in ('field', 'groupby')
|
||||
}
|
||||
for order_part in orderby.split(','):
|
||||
order_split = order_part.split()
|
||||
order_field = order_split[0]
|
||||
if order_field == 'id' or order_field in groupby_fields:
|
||||
|
||||
if self._fields[order_field.split(':')[0]].type == 'many2one':
|
||||
order_clause = self._generate_order_by(order_part, query).replace('ORDER BY ', '')
|
||||
if order_clause:
|
||||
orderby_terms.append(order_clause)
|
||||
groupby_terms += [order_term.split()[0] for order_term in order_clause.split(',')]
|
||||
else:
|
||||
order = '"%s" %s' % (order_field, '' if len(order_split) == 1 else order_split[1])
|
||||
orderby_terms.append(order)
|
||||
order_split[0] = '"%s"' % groupby_fields.get(order_field, order_field)
|
||||
orderby_terms.append(' '.join(order_split))
|
||||
elif order_field in aggregated_fields:
|
||||
order_split[0] = '"' + order_field + '"'
|
||||
order_split[0] = '"%s"' % order_field
|
||||
orderby_terms.append(' '.join(order_split))
|
||||
else:
|
||||
# Cannot order by a field that will not appear in the results (needs to be grouped or aggregated)
|
||||
_logger.warn('%s: read_group order by `%s` ignored, cannot sort on empty columns (not grouped/aggregated)',
|
||||
self._name, order_part)
|
||||
|
||||
return groupby_terms, orderby_terms
|
||||
|
||||
@api.model
|
||||
|
||||
Reference in New Issue
Block a user