Browse Source

[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.
pull/128/head
Rémy Taymans 7 years ago
parent
commit
5ded695423
  1. 2
      beesdoo_website_shift/__openerp__.py
  2. 7
      beesdoo_website_shift/controllers/main.py

2
beesdoo_website_shift/__openerp__.py

@ -16,7 +16,7 @@
'author': 'Rémy Taymans', 'author': 'Rémy Taymans',
'license': 'AGPL-3', 'license': 'AGPL-3',
'version': '9.0.2.0',
'version': '9.0.2.1',
'website': "https://github.com/beescoop/Obeesdoo", 'website': "https://github.com/beescoop/Obeesdoo",
'category': 'Cooperative management', 'category': 'Cooperative management',

7
beesdoo_website_shift/controllers/main.py

@ -45,8 +45,13 @@ class WebsiteShiftController(http.Controller):
# Ensure that the datetime given is without a timezone # Ensure that the datetime given is without a timezone
assert datetime.tzinfo is None assert datetime.tzinfo is None
# Get current user and user timezone # 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) 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 # Convert to UTC
dt_utc = utc.localize(datetime, is_dst=False) dt_utc = utc.localize(datetime, is_dst=False)
# Convert to user TZ # Convert to user TZ

Loading…
Cancel
Save