From 1bf58d282fd90a22a6d9a737d44bbe543e9629f4 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Mon, 13 Aug 2018 20:53:22 +0000 Subject: [PATCH] [IMP] db: set default user tz through country code Given a country code is specified and the country only has one timezone, it is safe to assume that the admin user is operating from that timezone. Set the default timezone to simplify the onboarding in such particular case. If a country has more than one timezone, we can not make safe assumptions and don't provide a default tz. closes odoo/odoo#26365 --- odoo/service/db.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/odoo/service/db.py b/odoo/service/db.py index 13ba7b7e735..df641cb2c50 100644 --- a/odoo/service/db.py +++ b/odoo/service/db.py @@ -10,6 +10,7 @@ import traceback from xml.etree import ElementTree as ET import zipfile +from pytz import country_timezones from functools import wraps from contextlib import closing from decorator import decorator @@ -71,6 +72,9 @@ def _initialize_db(id, db_name, demo, lang, user_password, login='admin', countr if country_code: country = env['res.country'].search([('code', 'ilike', country_code)])[0] env['res.company'].browse(1).write({'country_id': country_code and country.id, 'currency_id': country_code and country.currency_id.id}) + if len(country_timezones.get(country_code, [])) == 1: + users = env['res.users'].search([]) + users.write({'tz': country_timezones[country_code][0]}) if phone: env['res.company'].browse(1).write({'phone': phone}) if '@' in login: