diff --git a/addons/lunch/controllers/main.py b/addons/lunch/controllers/main.py index 690c37ce14d..9be1d8aa6b3 100644 --- a/addons/lunch/controllers/main.py +++ b/addons/lunch/controllers/main.py @@ -75,7 +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 - return user.last_lunch_location_id.id + 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) + + if not user_location or not has_multi_company_access: + return request.env['lunch.location'].search([], limit=1).id + return user_location.id def _make_infos(self, user, **kwargs): res = dict(kwargs) @@ -93,9 +98,11 @@ class LunchController(http.Controller): 'currency': {'symbol': currency.symbol, 'position': currency.position}, }) - if not user.last_lunch_location_id: - user.last_lunch_location_id = request.env['lunch.location'].search([], limit=1) 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) + + if not user_location or not has_multi_company_access: + user.last_lunch_location_id = user_location = request.env['lunch.location'].search([], limit=1) alert_domain = expression.AND([ [('available_today', '=', True)], diff --git a/addons/lunch/models/lunch_location.py b/addons/lunch/models/lunch_location.py index af2a8509de6..5bb47de3a10 100644 --- a/addons/lunch/models/lunch_location.py +++ b/addons/lunch/models/lunch_location.py @@ -10,3 +10,4 @@ class LunchLocation(models.Model): name = fields.Char('Location Name', required=True) address = fields.Text('Address') + company_id = fields.Many2one('res.company', default=lambda self: self.env.company) diff --git a/addons/lunch/security/lunch_security.xml b/addons/lunch/security/lunch_security.xml index 6c4e0891c98..ac8d3eee796 100644 --- a/addons/lunch/security/lunch_security.xml +++ b/addons/lunch/security/lunch_security.xml @@ -78,5 +78,12 @@ ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] + + + Lunch location: Multi Company + + + ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] + diff --git a/addons/lunch/views/lunch_location_views.xml b/addons/lunch/views/lunch_location_views.xml index db9cd3af5a5..7eb13fb98cf 100644 --- a/addons/lunch/views/lunch_location_views.xml +++ b/addons/lunch/views/lunch_location_views.xml @@ -21,6 +21,7 @@ + @@ -35,6 +36,7 @@ +