From fc53108c65822160dd22eefc0d6da5e6ea9d5939 Mon Sep 17 00:00:00 2001 From: David Monjoie <dmo@odoo.com> Date: Wed, 31 Aug 2016 15:54:24 +0200 Subject: [PATCH] [FIX] base: fix tz onchange in user preferences view Since res.users is an inherits of res.partner, the onchange that should be triggered by tz to update tz_offset is not triggered. Considering tz_offset is never used on res_partner and is only used by the timezone_mistmatch widget which compares the offset with the one of the browser timezone, which only makes sense if you are a user, we could have completely moved this field on res.users. That being said, it feels strange to have a tz field defined on partner but having to be a user to compute the actual timezon offset, which doesn't need any additional information. For this reason, we chose to duplicate it until either we decide to truly move it in the next version, or the orm is fixed to correctly trigger the onchanges of the inherits models. This patch could be applied in 9.0 if needed, but considering nobody ever complained about this issue and the "workaround" nature of this fix, we decided to apply it in master only. --- openerp/addons/base/res/res_users.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index e0f8a610b6f9..06c2f97bb1d1 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import pytz +import datetime import logging from collections import defaultdict @@ -206,6 +208,7 @@ class Users(models.Model): share = fields.Boolean(compute='_compute_share', compute_sudo=True, string='Share User', store=True, help="External user with limited access, created only for the purpose of sharing data.") companies_count = fields.Integer(compute='_compute_companies_count', string="Number of Companies", default=_companies_count) + tz_offset = fields.Char(compute='_compute_tz_offset', string='Timezone offset', invisible=True) @api.model def _get_company(self): @@ -257,6 +260,11 @@ class Users(models.Model): for user in self: user.companies_count = companies_count + @api.depends('tz') + def _compute_tz_offset(self): + for user in self: + user.tz_offset = datetime.datetime.now(pytz.timezone(user.tz or 'GMT')).strftime('%z') + @api.onchange('login') def on_change_login(self): if self.login and tools.single_email_re.match(self.login): -- GitLab