From fbc7b7803692cd4e4c662967720b9dd02018459a Mon Sep 17 00:00:00 2001 From: Kevin Baptiste Date: Thu, 16 Dec 2021 10:02:50 +0000 Subject: [PATCH] [FIX] lunch: show only company locations All lunch locations were showing regardless of the company the user is logged in. Now only the lunch locations of the current company are showing. closes odoo/odoo#81603 Taskid: 2710417 X-original-commit: 3e87770bb8faf2a58ba0b429148f64256537a4da Signed-off-by: Kevin Baptiste --- addons/lunch/controllers/main.py | 5 +++-- addons/lunch/static/src/js/lunch_widget.js | 10 ++++++++-- addons/lunch/static/tests/lunch_kanban_tests.js | 12 ++++++++++-- addons/lunch/static/tests/lunch_list_tests.js | 12 ++++++++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/addons/lunch/controllers/main.py b/addons/lunch/controllers/main.py index bda50e6f5ec..504598408fc 100644 --- a/addons/lunch/controllers/main.py +++ b/addons/lunch/controllers/main.py @@ -75,11 +75,12 @@ class LunchController(http.Controller): self._check_user_impersonification(user_id) user = request.env['res.users'].browse(user_id) if user_id else request.env.user + company_ids = request.env.context.get('allowed_company_ids', request.env.company.ids) user_location = user.last_lunch_location_id - has_multi_company_access = not user_location.company_id or user_location.company_id.id in request._context.get('allowed_company_ids', request.env.company.ids) + has_multi_company_access = not user_location.company_id or user_location.company_id.id in company_ids if not user_location or not has_multi_company_access: - return request.env['lunch.location'].search([], limit=1).id + return request.env['lunch.location'].search([('company_id', 'in', [False] + company_ids)], limit=1).id return user_location.id def _make_infos(self, user, **kwargs): diff --git a/addons/lunch/static/src/js/lunch_widget.js b/addons/lunch/static/src/js/lunch_widget.js index aa5d19d8d03..c58cdb6df3f 100644 --- a/addons/lunch/static/src/js/lunch_widget.js +++ b/addons/lunch/static/src/js/lunch_widget.js @@ -43,7 +43,10 @@ var LunchWidget = Widget.extend({ this.locations = params.locations || []; this.userLocation = params.user_location[1] || ''; - this.lunchLocationField = this._createMany2One('locations', 'lunch.location', this.userLocation); + const company_ids = [false].concat(session.user_context.allowed_company_ids || []); + this.lunchLocationField = this._createMany2One('locations', 'lunch.location', this.userLocation, () => [ + ['company_id', 'in', company_ids] + ]); this.wallet = params.wallet || 0; this.raw_state = params.raw_state || 'new'; @@ -72,7 +75,10 @@ var LunchWidget = Widget.extend({ } else { this.$('.o_lunch_user_field').text(this.username); } - this.lunchLocationField.appendTo(this.$('.o_lunch_location_field')); + + if (this.userLocation) { + this.lunchLocationField.appendTo(this.$('.o_lunch_location_field')); + } }, //-------------------------------------------------------------------------- diff --git a/addons/lunch/static/tests/lunch_kanban_tests.js b/addons/lunch/static/tests/lunch_kanban_tests.js index 093748921e0..65ab01b0320 100644 --- a/addons/lunch/static/tests/lunch_kanban_tests.js +++ b/addons/lunch/static/tests/lunch_kanban_tests.js @@ -40,10 +40,11 @@ QUnit.module('LunchKanbanView', { 'lunch.location': { fields: { name: {string: 'Name', type: 'char'}, + company_id: {string: 'Company', type: 'many2one', relation: 'res.company'}, }, records: [ - {id: 1, name: "Office 1"}, - {id: 2, name: "Office 2"}, + {id: 1, name: "Office 1", company_id: false}, + {id: 2, name: "Office 2", company_id: false}, ], }, 'res.users': { @@ -57,6 +58,13 @@ QUnit.module('LunchKanbanView', { {id: 3, name: "Jean-Luc Portal", groups_id: [PORTAL_GROUP_ID]}, ], }, + 'res.company': { + fields: { + name: {string: 'Name', type: 'char'}, + }, records: [ + {id: 1, name: "Dunder Trade Company"}, + ] + } }; this.regularInfos = { username: "Marc Demo", diff --git a/addons/lunch/static/tests/lunch_list_tests.js b/addons/lunch/static/tests/lunch_list_tests.js index ebff6ffbddb..1acfa75443a 100644 --- a/addons/lunch/static/tests/lunch_list_tests.js +++ b/addons/lunch/static/tests/lunch_list_tests.js @@ -40,10 +40,11 @@ QUnit.module('LunchListView', { 'lunch.location': { fields: { name: {string: 'Name', type: 'char'}, + company_id: {string: 'Company', type: 'many2one', relation: 'res.company'}, }, records: [ - {id: 1, name: "Office 1"}, - {id: 2, name: "Office 2"}, + {id: 1, name: "Office 1", company_id: false}, + {id: 2, name: "Office 2", company_id: false}, ], }, 'res.users': { @@ -57,6 +58,13 @@ QUnit.module('LunchListView', { {id: 3, name: "Jean-Luc Portal", groups_id: [PORTAL_GROUP_ID]}, ], }, + 'res.company': { + fields: { + name: {string: 'Name', type: 'char'}, + }, records: [ + {id: 1, name: "Dunder Trade Company"}, + ] + } }; this.regularInfos = { username: "Marc Demo",