[FIX] web: ActionManager: honor action's groupBy

Before this rev., the group_by specified in the action context was
completely overridden by the group_by specified in the search view,
even if it was []. In other words, it was completely ignored.

Moreover, it was only took into account (before being overridden)
at the first load of a view, not at reload.
This commit is contained in:
Aaron Bohy
2018-01-22 20:00:53 +01:00
parent e8fa9428e8
commit cf6697dfbd
2 changed files with 49 additions and 11 deletions
@@ -302,10 +302,6 @@ ActionManager.include({
* @returns {Object}
*/
_generateActionEnv: function (action, options) {
var actionGroupBy = action.context.group_by || [];
if (typeof actionGroupBy === 'string') {
actionGroupBy = [actionGroupBy];
}
var resID = options.resID || action.res_id;
return {
modelName: action.res_model,
@@ -313,7 +309,7 @@ ActionManager.include({
currentId: resID || undefined,
domain: [],
context: action.context || {},
groupBy: actionGroupBy,
groupBy: [],
};
},
/**
@@ -444,10 +440,11 @@ ActionManager.include({
throw new Error(_.str.sprintf(_t("Failed to evaluate search criterions")+": \n%s",
JSON.stringify(results.error)));
}
var groupBy = results.group_by.length ? results.group_by : (action.context.group_by || []);
return {
context: results.context,
domain: results.domain,
groupBy: results.group_by,
groupBy: (typeof groupBy === 'string') ? [groupBy] : groupBy,
};
},
/**
@@ -18,11 +18,11 @@ QUnit.module('ActionManager', {
bar: {string: "Bar", type: "many2one", relation: 'partner'},
},
records: [
{id: 1, display_name: "First record", foo: "yop"},
{id: 2, display_name: "Second record", foo: "blip"},
{id: 3, display_name: "Third record", foo: "gnap"},
{id: 4, display_name: "Fourth record", foo: "plop"},
{id: 5, display_name: "Fifth record", foo: "zoup"},
{id: 1, display_name: "First record", foo: "yop", bar: 2},
{id: 2, display_name: "Second record", foo: "blip", bar: 1},
{id: 3, display_name: "Third record", foo: "gnap", bar: 1},
{id: 4, display_name: "Fourth record", foo: "plop", bar: 2},
{id: 5, display_name: "Fifth record", foo: "zoup", bar: 2},
],
},
pony: {
@@ -2223,6 +2223,47 @@ QUnit.module('ActionManager', {
actionManager.destroy();
});
QUnit.test('honor group_by specified in actions context', function (assert) {
assert.expect(5);
_.findWhere(this.actions, {id: 3}).context = "{'group_by': 'bar'}";
this.archs['partner,false,search'] = '<search>'+
'<group>'+
'<filter name="foo" string="foo" context="{\'group_by\': \'foo\'}"/>' +
'</group>'+
'</search>';
var actionManager = createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
});
actionManager.doAction(3);
assert.strictEqual(actionManager.$('.o_list_view_grouped').length, 1,
"should be grouped");
assert.strictEqual(actionManager.$('.o_group_header').length, 2,
"should be grouped by 'bar' (two groups) at first load");
// groupby 'bar' using the searchview
$('.o_control_panel .o_searchview_more').click(); // open search view sub menus
$('.o_control_panel .o_cp_right button:contains(Group By)').click(); // open groupby dropdown
$('.o_control_panel .o_group_by_menu a:first').click(); // click on 'Foo'
assert.strictEqual(actionManager.$('.o_group_header').length, 5,
"should be grouped by 'foo' (five groups)");
// remove the groupby in the searchview
$('.o_control_panel .o_searchview .o_facet_remove').click();
assert.strictEqual(actionManager.$('.o_list_view_grouped').length, 1,
"should still be grouped");
assert.strictEqual(actionManager.$('.o_group_header').length, 2,
"should be grouped by 'bar' (two groups) at reload");
actionManager.destroy();
});
QUnit.module('Actions in target="new"');
QUnit.test('can execute act_window actions in target="new"', function (assert) {