mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
fix 时区问题 and common
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
<!--设置默认时区为中国,注意select 类型要加 ""-->
|
<!--设置默认时区为中国,注意select 类型要加 ""-->
|
||||||
<record id="res_partner_tz_default" model="ir.default">
|
<record id="res_partner_tz_default" model="ir.default">
|
||||||
<field name="field_id" eval="ref('base.field_res_partner__tz')"/>
|
<field name="field_id" eval="ref('base.field_res_partner__tz')"/>
|
||||||
<field name="json_value">"Asia/Shanghai"</field>
|
<field name="json_value">"Etc/GMT-8"</field>
|
||||||
</record>
|
</record>
|
||||||
<!--设置用户email在odoo内提醒-->
|
<!--设置用户email在odoo内提醒-->
|
||||||
<record id="res_user_notify_email_default" model="ir.default">
|
<record id="res_user_notify_email_default" model="ir.default">
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ def post_init_hook(cr, registry):
|
|||||||
rec._compute_complete_name()
|
rec._compute_complete_name()
|
||||||
# 超级用户改时区为中国
|
# 超级用户改时区为中国
|
||||||
ids = env['res.users'].sudo().with_context(lang='zh_CN').browse([1, 2])
|
ids = env['res.users'].sudo().with_context(lang='zh_CN').browse([1, 2])
|
||||||
ids.write({'tz': "Asia/Shanghai"})
|
ids.write({'tz': "Etc/GMT-8"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Warning(e)
|
raise Warning(e)
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,12 @@ class Base(models.AbstractModel):
|
|||||||
"""
|
"""
|
||||||
if not value:
|
if not value:
|
||||||
return value
|
return value
|
||||||
# 默认中国时区
|
if isinstance(value, datetime):
|
||||||
user_tz = pytz.timezone(self.env.user.tz or 'Etc/GMT+8')
|
value = value.strftime(return_format)
|
||||||
dt_local = pytz.utc.localize(value).astimezone(user_tz)
|
dt = datetime.strptime(value, return_format)
|
||||||
return dt_local.strftime(return_format)
|
pytz_timezone = pytz.timezone(self.env.user.tz or 'Etc/GMT-8')
|
||||||
|
dt = dt.replace(tzinfo=pytz.timezone('UTC'))
|
||||||
|
return dt.astimezone(pytz_timezone).strftime(return_format)
|
||||||
|
|
||||||
def _app_dt2utc(self, value, return_format=DEFAULT_SERVER_DATETIME_FORMAT):
|
def _app_dt2utc(self, value, return_format=DEFAULT_SERVER_DATETIME_FORMAT):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user