惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
WordPress大学
WordPress大学
Help Net Security
Help Net Security
Jina AI
Jina AI
Security Latest
Security Latest
Y
Y Combinator Blog
Project Zero
Project Zero
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
Know Your Adversary
Know Your Adversary
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
博客园 - 司徒正美
MyScale Blog
MyScale Blog
Cyberwarzone
Cyberwarzone
D
Docker
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
C
CERT Recently Published Vulnerability Notes
B
Blog
L
LangChain Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
The Hacker News
The Hacker News
C
Check Point Blog
L
Lohrmann on Cybersecurity
V2EX - 技术
V2EX - 技术
S
Securelist
T
Threat Research - Cisco Blogs
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
云风的 BLOG
云风的 BLOG
Latest news
Latest news
人人都是产品经理
人人都是产品经理
L
LINUX DO - 最新话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Register - Security
The Register - Security
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
AWS News Blog
AWS News Blog
C
Cybersecurity and Infrastructure Security Agency CISA
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
小众软件
小众软件
T
Tailwind CSS Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
宝玉的分享
宝玉的分享
O
OpenAI News

博客园 - 伽马科技.攻城师

管理git生成的多个ssh key Docker基础教程(命令详解) Docker基础教程(常用命令篇) Docker基础教程(安装篇) 常用的Jquery插件 自定义webkit浏览器滚动条样式 centos tar压缩与解压缩命令大全 Nginx编译安装(Centos) Nginx的启动脚本(Centos) ffmpeg 音频转换(amr2mp3) 安装php openssl扩展 centos手动编译安装apache、php、mysql 添加自编译的apache为linux系统服务 Jquery datatables 使用方法 HTML5 图片缩放功能 七牛图片上传JSSDK 2015年12月中国航空公司名录 HTML5 开发框架 利用HTML5定位功能,实现在百度地图上定位
openerp7 时区问题
伽马科技.攻城师 · 2014-09-11 · via 博客园 - 伽马科技.攻城师

由于目前openerp 的时区,读取的是UTC 时间,而我国本地时间比UTC 快8小时,这个问题就导致:写入数据库的时候时间相差8小时,以及Openerp日志输出时间格式也相差8小时和 前端显示时间的问题

1、更改openerp日志输出时间,如:
    修改文件:oe_dev/openerp/__init__.py
os.environ['TZ'] = 'UTC'
    修改成:
os.environ['TZ'] = 'Asia/Shanghai'

2、修改数据写入时间差问题
    修改文件:oe_dev/openerp/osv/orm.py
由于OE的数据库model会默认创建create_date,wirte_date,而更改这两处的只有create和write方法,我们只需要对这两处的方法做下处理,(他们默认取的都是utc时间)
    修改文件行:4219
    修改:
upd0.append("write_date=(now() at time zone 'Asia/Shanghai')")

修改文件行:4510
修改:
upd1 += ",%s,(now() at time zone 'Asia/Shanghai'),%s,(now() at time zone 'Asia/Shanghai')"

3、针对时间字段类型(date,datetime...)类型写入数据库时间差问题
    修改文件:oe_dev/openerp/osv/fields.py
在文件头增加:from datetime import datetime,timedelta
在4483文件后增加
    if self._columns[field]._type == 'datetime':
    datetime_type = datetime.strptime(vals[field],'%Y-%m-%d %H:%M:%S') + timedelta(hours=8)
    vals[field] = datetime_type.strftime('%Y-%m-%d %H:%M:%S')
如:
    只是针对datetime,date类型没写(懒得写,反正现在也不用~~~Orz....)
    由于加载datetime和OE的源码加载方式不一样
    OE: import datetime
    修改:from datetime import datetime,timedelta
    需要修改datetime的调用方式,不然会出错,具体错误原因,请猛戳:http://stackoverflow.com/questions/12906402/type-object-datetime-datetime-has-no-attribute-datetime
    修改函数:_store_set_values (大概在4657行)
    修改成:write_date = datetime.fromtimestamp(time.mktime(res_date))  ,少一层调用

4、前端显示问题,虽然数据库里面存的时间是对的,但是前端显示时也会有时间差问题
    修改文件: oe_dev/openerp/addons/web/static/src/js/dates.js
修改第24行:
    var obj = Date.parseExact(res[1] + " UTC", 'yyyy-MM-dd HH:mm:ss zzz');
修改成:
    var obj = Date.parseExact(res[1], 'yyyy-MM-dd HH:mm:ss');