Odoo 中文社区

    • 注册
    • 登录
    • 搜索
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    Web界面备份数据库文件名时差问题--侧面了解OpenERP时间机制

    Odoo 开发与实施交流
    6
    8
    6285
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • Y
      youring 最后由 编辑

      导读:
      [检测到链接无效,已移除]
      http://stackoverflow.com/questions/9919706/openerp-strange-date-time-issue
      [quote]There is one golden rule for datetime fields in 6.1 addons code: "ALWAYS work in UTC - compute in UTC - save in UTC" The UTC values will be properly converted to local time when the result is diplayed in a client-side form.[/quote]
      从v6.1开始,OpenERP服务器的时间(新手注:这里指的不是操作系统Windows或Linux服务器设定的时间)从设计上统一规定为UTC,即GMT。
      在web界面,用户只要设置了自己的时区,web端显示的时间会自动转换为本地时间,中国即 UTC + 8小时。

      而在备份数据库时,自动生成的文件名中的时间,显示的仍然是UTC。因为这个时间戳没有通过web客户端转换,而是直接取OpenERP服务器设定的UTC。代码追溯:openerp\addons\web\controllers\main.py

      &nbsp; &nbsp; def backup(self, req, backup_db, backup_pwd, token):<br />&nbsp; &nbsp; &nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; db_dump = base64.b64decode(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; req.session.proxy(&quot;db&quot;).dump(backup_pwd, backup_db))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename = &quot;%(db)s_%(timestamp)s.dump&quot; % {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;db&#039;: backup_db,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;timestamp&#039;: datetime.datetime.utcnow().strftime(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;%Y-%m-%d_%H-%M-%SZ&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
      



      经群里Jeff大神指点,像这种备份操作结果不在web端显示,而是直接取server端的时间生成文件名,就没办法按用户时区生成文件名了!
      不过作为中国用户,可以直接写死+8是不是?

      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;timestamp&#039;: (datetime.datetime.utcnow() + datetime.timedelta(hours = 8)).strftime(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;%Y-%m-%d_%H-%M-%SZ&quot;)
      


      重启Openerp Server生效。
      //完



      1 条回复 最后回复 回复 引用 0
      • mrshelly
        mrshelly 最后由 编辑

        嗯. 感谢分享.....
        因为 备份时, 并不提供用户信息, 所以, 电脑并不知道 是来自哪个时区的用户在备份.
        我个人认为 就使用GMT时间就好了. 备份的人自己知道就OK了....

        1 条回复 最后回复 回复 引用 0
        • 3
          387912318 最后由 编辑

          嗯. 感谢分享

          1 条回复 最后回复 回复 引用 0
          • wjfonhand
            wjfonhand 最后由 编辑

            直接用datetime.datetime.now()就是取的服务器时间了吧,这样比加8更好些。

            可以继续研究一下 auto_backup 模块生成的sql文件是按哪个时区的。

            GoodERP -- Odoo China fork

            1 条回复 最后回复 回复 引用 0
            • Y
              youring 最后由 编辑

              datetime.datetime.now() 和
              datetime.datetime.utcnow() 一个效果

              +8还是必须的吧?

              1 条回复 最后回复 回复 引用 0
              • Z
                zhong_163 最后由 编辑

                autobackup 设置界面再弄个 参数 ,时区差异  ?

                1 条回复 最后回复 回复 引用 0
                • Joshua
                  Joshua 管理员 最后由 编辑

                  可以调用这个 fields.datetime.context_timestamp,在context里面写入tz

                  &nbsp; &nbsp; def context_timestamp(cr, uid, timestamp, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;Returns the given timestamp converted to the client&#039;s timezone.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  This method is *not* meant for use as a _defaults initializer,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  because datetime fields are automatically converted upon<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  display on client side. For _defaults you :meth:`fields.datetime.now`<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  should be used instead.<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  :param datetime timestamp: naive datetime value (expressed in UTC)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to be converted to the client timezone<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  :param dict context: the &#039;tz&#039; key in the context should give the<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name of the User/Client timezone (otherwise<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UTC is used)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  :rtype: datetime<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  :return: timestamp converted to timezone-aware datetime in context<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timezone<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;
                  

                  【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

                  1 条回复 最后回复 回复 引用 0
                  • First post
                    Last post