[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
This commit is contained in:
David Arnold
2018-10-26 07:21:47 +00:00
committed by Martin Trigaux
parent 653b4289c6
commit 1bf58d282f
+4
View File
@@ -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: