提交 6d65fdd8 authored 作者: 刘擎阳's avatar 刘擎阳

1.优化时区计算

上级 d7256abe
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import datetime import datetime
import re import re
import pytz
from odoo import fields, models, exceptions, api, tools from odoo import fields, models, exceptions, api, tools
import logging import logging
from .redis_connection import redis_connection from .redis_connection import redis_connection
...@@ -624,4 +625,13 @@ class CommonCommon(models.Model): ...@@ -624,4 +625,13 @@ class CommonCommon(models.Model):
timezone_data['Etc/UTC'] = 0 timezone_data['Etc/UTC'] = 0
timezone_data['Etc/Universal'] = 0 timezone_data['Etc/Universal'] = 0
timezone_data['Etc/Zulu'] = 0 timezone_data['Etc/Zulu'] = 0
return '+%s' % timezone_data[name] if timezone_data[name] > 0 else str(timezone_data[name]) return '+%s' % timezone_data[name] if timezone_data[name] > 0 else str(timezone_data[name])
\ No newline at end of file
def get_time_zone(self, tz):
london_tz = pytz.timezone(tz)
# 获取当前时间
london_time = datetime.datetime.now(london_tz)
# 获取时区偏移(单位是小时)
timezone_offset = london_time.utcoffset().total_seconds() / 3600
offset_str = f"{int(timezone_offset):+d}"
return offset_str
...@@ -124,7 +124,8 @@ class OrderStateChangeRule(models.Model): ...@@ -124,7 +124,8 @@ class OrderStateChangeRule(models.Model):
# 调整时区 # 调整时区
users_obj = self.env['res.users'].search([('name', '=', '邮件接收')], limit=1) users_obj = self.env['res.users'].search([('name', '=', '邮件接收')], limit=1)
tz = users_obj.tz or 'UTC' tz = users_obj.tz or 'UTC'
timezone_offset = self.env['common.common'].sudo().init_timezone_data(tz) timezone_offset = self.env['common.common'].sudo().get_time_zone(tz)
# print(timezone_offset)
utc_time = local_time - timedelta(hours=int(timezone_offset)) utc_time = local_time - timedelta(hours=int(timezone_offset))
sql = "select id from cc_bl where UPPER(REPLACE(REPLACE(REPLACE(bl_no, ' ', ''), '-', ''), '/', '')) = '{0}' order by create_date desc limit 1".format(order_no.replace(' ', '').replace('-', '').replace('/', '')) sql = "select id from cc_bl where UPPER(REPLACE(REPLACE(REPLACE(bl_no, ' ', ''), '-', ''), '/', '')) = '{0}' order by create_date desc limit 1".format(order_no.replace(' ', '').replace('-', '').replace('/', ''))
self._cr.execute(sql) self._cr.execute(sql)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论