[FIX] board: translate custom views according to current user

Have a user in English, put a sale report as "favorite" (pinned to dashboard app)
Change the user's language

Before this commit, the pinned view was in English (because it was recorded that way)

After this commit, the pinned view is in the user's language.

OPW 1890664

closes odoo/odoo#27574
This commit is contained in:
Lucas Perais (lpe)
2018-10-12 08:36:19 +00:00
parent 44069cc4bd
commit 62cbc5f240
3 changed files with 55 additions and 1 deletions
+4 -1
View File
@@ -10,6 +10,7 @@ var FormController = require('web.FormController');
var FormRenderer = require('web.FormRenderer');
var FormView = require('web.FormView');
var pyUtils = require('web.pyeval'); // do not forwardport this to 12.0
var session = require('web.session');
var viewRegistry = require('web.view_registry');
var _t = core._t;
@@ -253,7 +254,9 @@ FormRenderer.include({
// the action does not exist anymore
return $.when();
}
var rawContext = new Context(params.context, action.context);
// 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);
var domain = params.domain || pyUtils.eval('domain', action.domain || '[]', action.context);
var viewType = params.viewType || action.views[0][1];
@@ -595,4 +595,49 @@ QUnit.test('subviews are aware of attach in or detach from the DOM', function (a
form.destroy();
});
QUnit.test("Views should be loaded in the user's language", function (assert) {
assert.expect(2);
var form = createView({
View: FormView,
model: 'board',
data: this.data,
session: {user_context: {lang: 'fr_FR'}},
arch: '<form string="My Dashboard">' +
'<board style="2-1">' +
'<column>' +
'<action context="{\'lang\': \'en_US\'}" view_mode="list" string="ABC" name="51" domain="[]"></action>' +
'</column>' +
'</board>' +
'</form>',
mockRPC: function (route, args) {
if (route === "/web/dataset/search_read") {
assert.deepEqual(args.context, {lang: 'fr_FR'},
'The data should be loaded with the correct context');
}
if (route === '/web/action/load') {
return $.when({
res_model: 'partner',
views: [[4, 'list']],
});
}
return this._super.apply(this, arguments);
},
archs: {
'partner,4,list':
'<list string="Partner"><field name="foo"/></list>',
},
interceptsPropagate: {
load_views: function (ev) {
assert.deepEqual(ev.data.context.eval(), {lang: 'fr_FR'},
'The views should be loaded with the correct context');
}
},
});
form.destroy();
});
});
@@ -171,6 +171,12 @@ function createAsyncView(params) {
});
}
if (params.interceptsPropagate) {
_.each(params.interceptsPropagate, function (cb, name) {
intercept(widget, name, cb, true);
});
}
return view.getController(widget).then(function (view) {
// override the view's 'destroy' so that it calls 'destroy' on the widget
// instead, as the widget is the parent of the view and the mockServer.