Skip to content
Snippets Groups Projects
Commit ad8a6afa authored by Pierre Paridans's avatar Pierre Paridans
Browse files

[FIX] lunch: rpc call cannot be performed in Widget.init()

The Widget's init function is synchronous.

The 'then' will execute after the end of the function so
self.group_portal_id will not be set immediately.

Also, RPC's in the init function is really not a good idea, it should be
putted in the willStart.

Original commit: https://github.com/odoo/odoo/commit/855c6dac25fccaf9312543022001ed0b360d6e13



closes odoo/odoo#31508

Signed-off-by: default avatarAdrien Dieudonné (adr) <adr@odoo.com>
parent 0ab333c6
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,6 @@ var LunchKanbanWidget = Widget.extend({
},
init: function (parent, params) {
var self = this;
this._super.apply(this, arguments);
this.is_manager = params.is_manager || false;
......@@ -44,20 +43,6 @@ var LunchKanbanWidget = Widget.extend({
this.group_portal_id = undefined;
self._rpc({
model: 'ir.model.data',
method: 'xmlid_to_res_id',
kwargs: {xmlid: 'base.group_portal'},
}).then(function (id) {
self.group_portal_id = id;
});
if (this.is_manager) {
this.lunchUserField = this._createMany2One('users', 'res.users', this.username, function () {
return [['groups_id', 'not in', [self.group_portal_id]]];
});
}
this.locations = params.locations || [];
this.userLocation = params.user_location[1] || '';
......@@ -73,6 +58,25 @@ var LunchKanbanWidget = Widget.extend({
this.currency = params.currency || session.get_currency(session.company_currency_id);
},
willStart: function () {
var self = this;
var superDef = this._super.apply(this, arguments);
var def = this._rpc({
model: 'ir.model.data',
method: 'xmlid_to_res_id',
kwargs: {xmlid: 'base.group_portal'},
}).then(function (id) {
self.group_portal_id = id;
if (self.is_manager) {
self.lunchUserField = self._createMany2One('users', 'res.users', self.username, function () {
return [['groups_id', 'not in', [self.group_portal_id]]];
});
}
});
return $.when(superDef, def);
},
renderElement: function () {
this._super.apply(this, arguments);
if (this.lunchUserField) {
......
......@@ -2,6 +2,7 @@ odoo.define('lunch.lunchKanbanTests', function (require) {
"use strict";
var LunchKanbanView = require('lunch.LunchKanbanView');
var LunchKanbanWidget = require('lunch.LunchKanbanWidget');
var testUtils = require('web.test_utils');
var createView = testUtils.createView;
......@@ -218,6 +219,41 @@ QUnit.module('Views', {
lunchKanban.destroy();
});
QUnit.module('LunchKanbanWidget');
QUnit.test('Rpc calls should be performed after the init()', function (assert) {
assert.expect(2);
var parent = testUtils.createParent({});
var widget = new LunchKanbanWidget(parent, {
user_location: [1, 'hello'],
});
testUtils.mock.addMockEnvironment(widget, {
data: {},
mockRPC: function (route, args) {
if (route === '/web/dataset/call_kw/ir.model.data/xmlid_to_res_id') {
assert.ok('should perform xmlid_to_res_id RPC call in the willStart()');
assert.deepEqual(args, {
args: [],
kwargs: {
xmlid: "base.group_portal",
},
method: "xmlid_to_res_id",
model: "ir.model.data",
}, 'should have the right parameters for xmlid_to_res_id RPC call');
return $.when();
}
return this._super.apply(this, arguments);
},
});
widget.appendTo($("#qunit-fixture"));
parent.destroy();
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment