来源
在Odoo设计之初,就考虑到适应全球一体化业务模式,默认数据库是以UTC时间存放的;这也是odoo设计优秀的地方。
但在国内实际程序开发中,会存在时区的差异,主要考虑到Odoo后台,即Postgresql数据表中数据存储是按UTC时区时间存储的,这样会出现数据导出相差8小时,带来一些不便。以下提供两种处理方式:
1. 代码设计中处理
from datetime import *
# 获得当前时区时间
current_time = (datetime.today() + timedelta(hours=8)).strftime("%Y%m%d%H%M%S")
print(current_time)
#输出结果: 20200302180020
# 获得当前时区星期几
wd = (datetime.today() + timedelta(hours=8)).strftime('%w')
wds = -1
if wd == '1':
wds = -3
current_date = (datetime.today() + timedelta(hours=8, days=wds)).strftime("%Y-%m-%d")
print(current_date)
#输出结果: 2020-02-28
# 获得当前时区月份
current_month = current_date[:7]
print(current_month)
#输出结果: 2020-02
# 获得当前时区天
current_today = (datetime.today() + timedelta(hours=8)).strftime("%Y-%m-%d")
print(current_today)
#输出结果: 2020-03-02
# 获得当前时区前一天
current_yesterday = (datetime.today() + timedelta(hours=8, days=-1)).strftime("%Y-%m-%d")
print(current_yesterday)
#输出结果: 2020-03-01
2. 前台用户时区设置处理
设置路径:Odoo前端-设置-用户-【进入用户】-个人设置-语言【Chinese (Simplified) / 简体中文】/ 时区【Asia/Shanghai】。
image
————————————————
版权声明:本文为CSDN博主「南京-似水流」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_38708145/article/details/104605588