[FIX] board: use correct context in sub board views

Before commit 60f143c8e7, the dashboard
parameters did not use the parameters from the action, so some important
information could be lost.

However, in this same commit, the action context overrides the context
from the user defined views, which means that some information is lost.
For example, customized group bys are ignored.

This commit fixes the issue with some careful context manipulation.
Some special care was done to remove the groupby from the action context
if it is not empty, because that same logic is used in views.
This commit is contained in:
Géry Debongnie
2018-11-06 09:17:05 +00:00
parent baeb1a1938
commit 6e9c1d92d7
2 changed files with 46 additions and 4 deletions
+8 -4
View File
@@ -247,10 +247,14 @@ var BoardRenderer = FormRenderer.extend({
// the action does not exist anymore
return $.when();
}
var evalContext = new Context(params.context).eval();
if (evalContext.group_by && evalContext.group_by.length === 0) {
delete evalContext.group_by;
}
// tz and lang are saved in the custom view
// override the language to take the current one
var rawContext = new Context(params.context, action.context, {lang: session.user_context.lang});
var context = pyUtils.eval('context', rawContext);
// override the https://github.com/odoo/odoo/pull/28408language to take the current one
var rawContext = new Context(action.context, evalContext, {lang: session.user_context.lang});
var context = pyUtils.eval('context', rawContext, evalContext);
var domain = params.domain || pyUtils.eval('domain', action.domain || '[]', action.context);
var viewType = params.viewType || action.views[0][1];
var view = _.find(action.views, function (descr) {
@@ -332,7 +336,7 @@ var BoardRenderer = FormRenderer.extend({
self.defs.push(self._createController({
$node: $html.find('.oe_action[data-id=' + action.id + '] .oe_content'),
actionID: _.str.toNumber(action.name),
context: new Context(action.context),
context: action.context,
domain: Domain.prototype.stringToArray(action.domain, {}),
viewType: action.view_mode,
}));
@@ -24,6 +24,7 @@ QUnit.module('Dashboard', {
fields: {
display_name: {string: "Displayed name", type: "char", searchable: true},
foo: {string: "Foo", type: "char", default: "My little Foo Value", searchable: true},
bar: {string: "Bar", type: "boolean"},
},
records: [{
id: 1,
@@ -787,4 +788,41 @@ QUnit.test("Views should be loaded in the user's language", function (assert) {
form.destroy();
});
QUnit.test("Dashboard should use correct groupby", function (assert) {
assert.expect(1);
var form = createView({
View: BoardView,
model: 'board',
data: this.data,
arch: '<form string="My Dashboard">' +
'<board style="2-1">' +
'<column>' +
'<action context="{\'group_by\': [\'bar\']}" string="ABC" name="51"></action>' +
'</column>' +
'</board>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'read_group') {
assert.deepEqual(args.kwargs.groupby, ['bar'],
'user defined groupby should have precedence on action groupby');
}
if (route === '/web/action/load') {
return $.when({
res_model: 'partner',
context: {
group_by: 'some_field',
},
views: [[4, 'list']],
});
}
return this._super.apply(this, arguments);
},
archs: {
'partner,4,list':
'<list string="Partner"><field name="foo"/></list>',
},
});
form.destroy();
});
});