Skip to content
Snippets Groups Projects
Commit fc53108c authored by David Monjoie's avatar David Monjoie
Browse files

[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.
parent 4b5398f5
No related branches found
No related tags found
No related merge requests found
# -*- 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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment