[FIX] web: accept field name as a groupby descriptor

In some cases, and for historical reasons, the groupby property can be
expressed as a string (for example, 'stage_id') instead of a list of
strings (for example, ['stage_id']).

However, the support was not complete. A crash could happen in some
cases. For example, if there is a group_by: 'stage_id' property in the
context of an action, it works in list view, but adding that view to the
dashboard would result in a crash, without this commit.
This commit is contained in:
Géry Debongnie
2018-11-06 08:53:21 +00:00
parent 764bd645fc
commit baeb1a1938
3 changed files with 37 additions and 1 deletions
@@ -162,6 +162,11 @@ var AbstractView = Class.extend({
this.controllerParams.withControlPanel = params.withControlPanel;
}
var groupBy = params.groupBy;
if (typeof groupBy === 'string') {
groupBy = [groupBy];
}
this.loadParams = {
context: params.context,
count: params.count || ((this.controllerParams.ids !== undefined) &&
@@ -172,7 +177,7 @@ var AbstractView = Class.extend({
comparisonTimeRange: comparisonTimeRange,
comparisonTimeRangeDescription: comparisonTimeRangeDescription,
compare: compare,
groupedBy: params.groupBy,
groupedBy: groupBy,
modelName: params.modelName,
res_id: params.currentId,
res_ids: params.ids,
@@ -3,6 +3,7 @@ odoo.define('web.abstract_view_tests', function (require) {
var AbstractView = require('web.AbstractView');
var ajax = require('web.ajax');
var ListView = require('web.ListView');
var testUtils = require('web.test_utils');
var createAsyncView = testUtils.createAsyncView;
@@ -14,6 +15,16 @@ QUnit.module('Views', {
fields: {},
record: [],
},
foo: {
fields: {
foo: {string: "Foo", type: "char"},
bar: {string: "Bar", type: "boolean"},
},
records: [
{id: 1, bar: true, foo: "yop"},
{id: 2, bar: true, foo: "blip"},
]
},
};
},
}, function () {
@@ -100,5 +111,24 @@ QUnit.module('Views', {
"should load 'c' when 'a' and 'b' are loaded");
defs.c.resolve();
});
QUnit.test('groupBy attribute can be a string, instead of a list of strings', function (assert) {
assert.expect(2);
var list = testUtils.createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree><field name="foo"/><field name="bar"/></tree>',
groupBy: 'bar',
mockRPC: function (route, args) {
assert.strictEqual(args.method, 'read_group');
assert.deepEqual(args.kwargs.groupby, ['bar']);
return this._super.apply(this, arguments);
},
});
list.destroy();
});
});
});
@@ -307,6 +307,7 @@ QUnit.module('Views', {
assert.strictEqual(list.$('th:contains(Bar)').length, 1, "should contain Bar");
assert.strictEqual(list.$('tr.o_group_header').length, 2, "should have 2 .o_group_header");
assert.strictEqual(list.$('th.o_group_name').length, 2, "should have 2 .o_group_name");
list.destroy();
});
QUnit.test('basic grouped list rendering 1 col without selector', function (assert) {