From 5ded695423d5599382dd565baa59c15dc4794130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Wed, 16 May 2018 11:55:15 +0200 Subject: [PATCH] [FIX] website_shift: Error when regular has no tz Issue when no timezone set to a regular worker. It try to use the user timezone but has it doesn't exists runs into an error. To solve this, it first takes the timezone of the user, if it is empty, it takes the timezone of the context, and if also empty it uses UTC. --- beesdoo_website_shift/__openerp__.py | 2 +- beesdoo_website_shift/controllers/main.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/beesdoo_website_shift/__openerp__.py b/beesdoo_website_shift/__openerp__.py index b1a3d09..8f8dfe3 100644 --- a/beesdoo_website_shift/__openerp__.py +++ b/beesdoo_website_shift/__openerp__.py @@ -16,7 +16,7 @@ 'author': 'Rémy Taymans', 'license': 'AGPL-3', - 'version': '9.0.2.0', + 'version': '9.0.2.1', 'website': "https://github.com/beescoop/Obeesdoo", 'category': 'Cooperative management', diff --git a/beesdoo_website_shift/controllers/main.py b/beesdoo_website_shift/controllers/main.py index 76fc93c..ab011c7 100644 --- a/beesdoo_website_shift/controllers/main.py +++ b/beesdoo_website_shift/controllers/main.py @@ -45,8 +45,13 @@ class WebsiteShiftController(http.Controller): # Ensure that the datetime given is without a timezone assert datetime.tzinfo is None # Get current user and user timezone + # Take user tz, if empty use context tz, if empty use UTC cur_user = request.env['res.users'].browse(request.uid) - user_tz = timezone(cur_user.tz) + user_tz = utc + if cur_user.tz: + user_tz = timezone(cur_user.tz) + elif request.env.context['tz']: + user_tz = timezone(request.env.context['tz']) # Convert to UTC dt_utc = utc.localize(datetime, is_dst=False) # Convert to user TZ