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

推荐订阅源

大猫的无限游戏
大猫的无限游戏
Webroot Blog
Webroot Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Threat Research - Cisco Blogs
V2EX - 技术
V2EX - 技术
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
Recorded Future
Recorded Future
S
Schneier on Security
I
InfoQ
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The GitHub Blog
The GitHub Blog
S
Security @ Cisco Blogs
O
OpenAI News
W
WeLiveSecurity
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
人人都是产品经理
人人都是产品经理
Cloudbric
Cloudbric
The Last Watchdog
The Last Watchdog
The Hacker News
The Hacker News
Google Online Security Blog
Google Online Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
NISL@THU
NISL@THU
T
Tailwind CSS Blog
V
Visual Studio Blog
PCI Perspectives
PCI Perspectives
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
D
DataBreaches.Net
B
Blog RSS Feed
N
News and Events Feed by Topic
N
News and Events Feed by Topic
H
Heimdal Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
腾讯CDC
Latest news
Latest news
V
Vulnerabilities – Threatpost
Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
V
V2EX
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Register - Security
The Register - Security
Help Net Security
Help Net Security

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

管理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');