From 1aaef7614d8b079dc372803266d44f57841874f9 Mon Sep 17 00:00:00 2001 From: alt-odoo Date: Fri, 20 Aug 2021 06:29:48 +0000 Subject: [PATCH] [FIX] lunch: use correct timezone when retrieving today's lines order On the kanban view to order your lunch, we are retrieving today's order lines for the current user. In _get_current_lines, we are using today's date without taking into account the timezone of this user, which can prevent him to see/modify his order of today in case it was ordered very early. --- addons/lunch/controllers/main.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/lunch/controllers/main.py b/addons/lunch/controllers/main.py index 8f6f4ba419e..64350af21ea 100644 --- a/addons/lunch/controllers/main.py +++ b/addons/lunch/controllers/main.py @@ -16,7 +16,7 @@ class LunchController(http.Controller): infos = self._make_infos(user, order=False) - lines = self._get_current_lines(user.id) + lines = self._get_current_lines(user) if lines: lines = [{'id': line.id, 'product': (line.product_id.id, line.product_id.name, float_repr(float_round(line.product_id.price, 2), 2)), @@ -40,7 +40,7 @@ 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 - lines = self._get_current_lines(user.id) + lines = self._get_current_lines(user) lines.action_cancel() lines.unlink() @@ -49,7 +49,7 @@ 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 - lines = self._get_current_lines(user.id) + lines = self._get_current_lines(user) if lines: lines = lines.filtered(lambda line: line.state == 'new') @@ -122,8 +122,10 @@ class LunchController(http.Controller): if (user_id and request.env.uid != user_id and not request.env.user.has_group('lunch.group_lunch_manager')): raise AccessError(_('You are trying to impersonate another user, but this can only be done by a lunch manager')) - def _get_current_lines(self, user_id): - return request.env['lunch.order'].search([('user_id', '=', user_id), ('date', '=', fields.Date.today()), ('state', '!=', 'cancelled')]) + def _get_current_lines(self, user): + return request.env['lunch.order'].search( + [('user_id', '=', user.id), ('date', '=', fields.Date.context_today(user)), ('state', '!=', 'cancelled')] + ) def _get_state(self, lines): """