[IMP] lunch: avoid a call to ir.model.data

Not needed to do it via a specific call, can be included in the
controller data
This commit is contained in:
Martin Trigaux
2021-08-10 13:49:04 +02:00
parent 8e4cec6b07
commit 293d3765fa
5 changed files with 15 additions and 45 deletions
+1
View File
@@ -94,6 +94,7 @@ class LunchController(http.Controller):
'userimage': '/web/image?model=res.users&id=%s&field=avatar_128' % user.id,
'wallet': request.env['lunch.cashmove'].get_wallet_balance(user, False),
'is_manager': is_manager,
'group_portal_id': request.env.ref('base.group_portal').id,
'locations': request.env['lunch.location'].search_read([], ['name']),
'currency': {'symbol': currency.symbol, 'position': currency.position},
})
+7 -17
View File
@@ -34,13 +34,12 @@ var LunchWidget = Widget.extend({
this._super.apply(this, arguments);
this.is_manager = params.is_manager || false;
this.group_portal_id = params.group_portal_id || false;
this.userimage = params.userimage || '';
this.username = params.username || '';
this.lunchUserField = null;
this.group_portal_id = undefined;
this.locations = params.locations || [];
this.userLocation = params.user_location[1] || '';
@@ -57,23 +56,14 @@ var LunchWidget = 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 Promise.all([superDef, def]);
if (this.is_manager) {
this.lunchUserField = this._createMany2One('users', 'res.users', this.username,
() => [['groups_id', 'not in', [this.group_portal_id]]]
);
}
return superDef;
},
renderElement: function () {
this._super.apply(this, arguments);
@@ -37,12 +37,6 @@ QUnit.module('LunchKanbanView Mobile', {
fields: {},
records: [],
},
'ir.model.data': {
fields: {},
xmlid_to_res_id() {
return Promise.resolve(PORTAL_GROUP_ID);
},
},
'lunch.location': {
fields: {
name: {string: 'Name', type: 'char'},
@@ -37,12 +37,6 @@ QUnit.module('LunchKanbanView', {
fields: {},
records: [],
},
'ir.model.data': {
fields: {},
xmlid_to_res_id() {
return Promise.resolve(PORTAL_GROUP_ID);
},
},
'lunch.location': {
fields: {
name: {string: 'Name', type: 'char'},
@@ -68,6 +62,7 @@ QUnit.module('LunchKanbanView', {
username: "Marc Demo",
wallet: 36.5,
is_manager: false,
group_portal_id: PORTAL_GROUP_ID,
currency: {
symbol: "\u20ac",
position: "after"
@@ -78,6 +73,7 @@ QUnit.module('LunchKanbanView', {
username: "Mitchell Admin",
wallet: 47.6,
is_manager: true,
group_portal_id: PORTAL_GROUP_ID,
currency: {
symbol: "\u20ac",
position: "after"
@@ -212,7 +208,7 @@ QUnit.module('LunchKanbanView', {
});
QUnit.test('search panel domain location', async function (assert) {
assert.expect(20);
assert.expect(18);
let expectedLocation = 1;
let locationId = this.data['lunch.location'].records[0].id;
const regularInfos = _.extend({}, this.regularInfos);
@@ -266,7 +262,6 @@ QUnit.module('LunchKanbanView', {
'/web/dataset/call_kw/product/search_panel_select_multi_range',
'/web/dataset/search_read',
'/lunch/infos',
'/web/dataset/call_kw/ir.model.data/xmlid_to_res_id',
// Click m2o
'/web/dataset/call_kw/lunch.location/name_search',
// Click new location
@@ -275,14 +270,13 @@ QUnit.module('LunchKanbanView', {
'/web/dataset/call_kw/product/search_panel_select_multi_range',
'/web/dataset/search_read',
'/lunch/infos',
'/web/dataset/call_kw/ir.model.data/xmlid_to_res_id',
]);
kanban.destroy();
});
QUnit.test('search panel domain location false: fetch products in all locations', async function (assert) {
assert.expect(10);
assert.expect(9);
const regularInfos = _.extend({}, this.regularInfos);
const kanban = await createLunchView({
@@ -324,7 +318,6 @@ QUnit.module('LunchKanbanView', {
'/web/dataset/call_kw/product/search_panel_select_multi_range',
'/web/dataset/search_read',
'/lunch/infos',
'/web/dataset/call_kw/ir.model.data/xmlid_to_res_id',
])
kanban.destroy();
+3 -11
View File
@@ -37,12 +37,6 @@ QUnit.module('LunchListView', {
fields: {},
records: [],
},
'ir.model.data': {
fields: {},
xmlid_to_res_id() {
return Promise.resolve(PORTAL_GROUP_ID);
},
},
'lunch.location': {
fields: {
name: {string: 'Name', type: 'char'},
@@ -68,6 +62,7 @@ QUnit.module('LunchListView', {
username: "Marc Demo",
wallet: 36.5,
is_manager: false,
group_portal_id: PORTAL_GROUP_ID,
currency: {
symbol: "\u20ac",
position: "after"
@@ -120,7 +115,7 @@ QUnit.module('LunchListView', {
QUnit.module('LunchWidget', function () {
QUnit.test('search panel domain location', async function (assert) {
assert.expect(20);
assert.expect(18);
let expectedLocation = 1;
let locationId = this.data['lunch.location'].records[0].id;
const regularInfos = _.extend({}, this.regularInfos);
@@ -170,7 +165,6 @@ QUnit.module('LunchListView', {
'/web/dataset/call_kw/product/search_panel_select_multi_range',
'/web/dataset/search_read',
'/lunch/infos',
'/web/dataset/call_kw/ir.model.data/xmlid_to_res_id',
// Click m2o
'/web/dataset/call_kw/lunch.location/name_search',
// Click new location
@@ -179,14 +173,13 @@ QUnit.module('LunchListView', {
'/web/dataset/call_kw/product/search_panel_select_multi_range',
'/web/dataset/search_read',
'/lunch/infos',
'/web/dataset/call_kw/ir.model.data/xmlid_to_res_id',
]);
list.destroy();
});
QUnit.test('search panel domain location false: fetch products in all locations', async function (assert) {
assert.expect(10);
assert.expect(9);
const regularInfos = _.extend({}, this.regularInfos);
const list = await createLunchView({
@@ -224,7 +217,6 @@ QUnit.module('LunchListView', {
'/web/dataset/call_kw/product/search_panel_select_multi_range',
'/web/dataset/search_read',
'/lunch/infos',
'/web/dataset/call_kw/ir.model.data/xmlid_to_res_id',
])
list.destroy();