[FIX] web: grouped list views: allow sorting groups
Before this rev., sorting groups in list views wasn't supported. It hadn't been implemented in the new views. This rev. activates the feature, so groups can now be sorted on their aggregates again. It also implements a basic (first level only) sorting in mockReadGroup, in the mock server. opw 781288
This commit is contained in:
@@ -3431,6 +3431,7 @@ var BasicModel = AbstractModel.extend({
|
||||
domain: list.domain,
|
||||
context: list.context,
|
||||
groupBy: list.groupedBy,
|
||||
orderBy: list.orderedBy,
|
||||
lazy: true,
|
||||
})
|
||||
.then(function (groups) {
|
||||
|
||||
@@ -707,6 +707,23 @@ var MockServer = Class.extend({
|
||||
|
||||
return res;
|
||||
});
|
||||
|
||||
if (kwargs.orderby) {
|
||||
// only consider first sorting level
|
||||
kwargs.orderby = kwargs.orderby.split(',')[0];
|
||||
var fieldName = kwargs.orderby.split(' ')[0];
|
||||
var order = kwargs.orderby.split(' ')[1];
|
||||
result.sort(function (g1, g2) {
|
||||
if (g1[fieldName] < g2[fieldName]) {
|
||||
return order === 'ASC' ? -1 : 1;
|
||||
}
|
||||
if (g1[fieldName] > g2[fieldName]) {
|
||||
return order === 'ASC' ? 1 : -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -635,6 +635,42 @@ QUnit.module('Views', {
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('groups can be sorted on aggregates', function (assert) {
|
||||
assert.expect(10);
|
||||
|
||||
var list = createView({
|
||||
View: ListView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
groupBy: ['foo'],
|
||||
arch: '<tree editable="bottom"><field name="int_field" sum="Sum"/></tree>',
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === 'read_group') {
|
||||
assert.step(args.kwargs.orderby || 'default order');
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(list.$('tbody .o_list_number').text(), '10517',
|
||||
"initial order should be 10, 5, 17");
|
||||
assert.strictEqual(list.$('tfoot td:nth(2)').text(), '32', "total should be 32");
|
||||
|
||||
list.$('.o_column_sortable').click(); // sort (int_field ASC)
|
||||
assert.strictEqual(list.$('tfoot td:nth(2)').text(), '32', "total should still be 32");
|
||||
assert.strictEqual(list.$('tbody .o_list_number').text(), '51017',
|
||||
"order should be 5, 10, 17");
|
||||
|
||||
list.$('.o_column_sortable').click(); // sort (int_field DESC)
|
||||
assert.strictEqual(list.$('tbody .o_list_number').text(), '17105',
|
||||
"initial order should be 17, 10, 5");
|
||||
assert.strictEqual(list.$('tfoot td:nth(2)').text(), '32', "total should still be 32");
|
||||
|
||||
assert.verifySteps(['default order', 'int_field ASC', 'int_field DESC']);
|
||||
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('properly apply onchange in simple case', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
@@ -1693,7 +1729,7 @@ QUnit.module('Views', {
|
||||
// close first level group
|
||||
nbRPCs = {readGroup: 0, searchRead: 0};
|
||||
envIDs = []; // the group being closed, there is no more record in the environment
|
||||
list.$('.o_group_header:first').click();
|
||||
list.$('.o_group_header:nth(1)').click();
|
||||
assert.strictEqual(nbRPCs.readGroup, 0, "should have done no read_group");
|
||||
assert.strictEqual(nbRPCs.searchRead, 0, "should have done no search_read");
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ QUnit.module('Views', {
|
||||
domain: [["display_name","like","a"], ["display_name","ilike","piou"], ["foo","ilike","piou"]],
|
||||
fields:["display_name","foo","bar"],
|
||||
groupby:["bar"],
|
||||
orderby: '',
|
||||
lazy: true
|
||||
}, "should search with the complete domain (domain + search), and group by 'bar'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user