[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.
This commit is contained in:
alt-odoo
2021-08-25 06:03:39 +00:00
parent 281e1a57b3
commit 1aaef7614d
+7 -5
View File
@@ -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):
"""