Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
hh_ccs
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
贺阳
hh_ccs
Commits
7916e40b
提交
7916e40b
authored
4月 17, 2025
作者:
贺阳
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
关务提单和小包状态的操作时间,时区改为操作者时区
上级
cf56f000
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
117 行增加
和
7 行删除
+117
-7
common_common.py
ccs_base/models/common_common.py
+109
-3
cc_bill_loading.py
ccs_connect_tiktok/models/cc_bill_loading.py
+8
-4
没有找到文件。
ccs_base/models/common_common.py
浏览文件 @
7916e40b
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
datetime
import
datetime
import
re
import
pytz
from
odoo
import
fields
,
models
,
exceptions
,
api
,
tools
import
logging
import
logging
import
pytz
from
odoo
import
models
from
.redis_connection
import
redis_connection
from
.redis_connection
import
redis_connection
__author__
=
'zd'
__author__
=
'zd'
r
=
redis_connection
()
r
=
redis_connection
()
_logger
=
logging
.
getLogger
(
__name__
)
_logger
=
logging
.
getLogger
(
__name__
)
...
@@ -14,6 +16,110 @@ class CommonCommon(models.Model):
...
@@ -14,6 +16,110 @@ class CommonCommon(models.Model):
_name
=
'common.common'
_name
=
'common.common'
_description
=
u'公用基础类'
_description
=
u'公用基础类'
def
get_local_time
(
self
,
local_time
=
None
):
"""获取Odoo时区的时间
Args:
local_time: 本地时间,如果不提供则使用当前时间
Returns:
datetime: Odoo时区的时间
"""
if
not
local_time
:
local_time
=
datetime
.
datetime
.
now
()
try
:
# 获取Odoo配置的时区
user_tz
=
self
.
env
.
user
.
tz
or
'UTC'
timezone_offset
=
self
.
env
[
'common.common'
]
.
sudo
()
.
get_time_zone
(
user_tz
)
local_time
=
local_time
+
datetime
.
timedelta
(
hours
=
int
(
timezone_offset
))
return
local_time
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
),
timezone_offset
except
Exception
as
e
:
# 如果出现任何错误,返回UTC时间
logging
.
warning
(
f
"获取Odoo时区失败,使用UTC时间: {str(e)}"
)
return
local_time
.
astimezone
(
pytz
.
UTC
),
'+0'
def
get_timezone_offset
(
self
):
"""
Get UTC offset from Odoo's timezone configuration
Returns format like: UTC+8, UTC-5, etc.
"""
try
:
tz
=
self
.
env
.
user
.
tz
or
'UTC'
if
self
.
env
.
user
.
name
==
'OdooBot'
:
tz
=
'Asia/Shanghai'
user_tz
=
int
(
self
.
init_timezone_data
(
tz
))
return
user_tz
except
Exception
as
e
:
_logger
.
error
(
"Timezone offset calculation error:
%
s"
,
str
(
e
))
return
"UTC+0"
# Default t
def
get_local_rfc3339_time
(
self
,
local_time
=
None
):
"""获取Odoo本地时区的RFC3339格式时间
Args:
local_time: 本地时间,如果不提供则使用当前时间
Returns:
str: RFC3339格式的时间字符串
"""
if
not
local_time
:
local_time
=
datetime
.
datetime
.
now
()
# 获取Odoo配置的时区
user_tz
=
self
.
env
.
user
.
tz
or
'UTC'
local_tz
=
pytz
.
timezone
(
user_tz
)
# 确保时间是本地时区
if
local_time
.
tzinfo
is
None
:
local_time
=
local_tz
.
localize
(
local_time
)
# 转换为RFC3339格式
rfc3339_time
=
local_time
.
isoformat
(
timespec
=
'seconds'
)
logging
.
info
(
'rfc3339_time:
%
s'
%
rfc3339_time
)
return
rfc3339_time
def
get_rfc339_time
(
self
,
utc_time
=
None
):
if
not
utc_time
:
# 获取当前时间的UTC时间
utc_time
=
datetime
.
datetime
.
utcnow
()
# 创建+8时区的对象
target_timezone
=
pytz
.
timezone
(
'Asia/Shanghai'
)
# 将UTC时间转换为目标时区时间
local_time
=
utc_time
.
replace
(
tzinfo
=
pytz
.
utc
)
.
astimezone
(
target_timezone
)
# 格式化为RFC 3339格式
rfc3339_time
=
local_time
.
isoformat
(
timespec
=
'seconds'
)
return
rfc3339_time
# 定义一个方法,将时间的时区转为UTC时间
def
get_utc_rfc339_time
(
self
,
local_time
=
None
):
"""获取Odoo本地时区的RFC3339格式时间
Args:
local_time: 本地时间,如果不提供则使用当前时间
Returns:
str: RFC3339格式的时间字符串
"""
if
not
local_time
:
# 获取当前时间的UTC时间
local_time
=
datetime
.
datetime
.
now
()
# 将本地时间转换为UTC时间
utc_time
=
local_time
.
astimezone
(
pytz
.
utc
)
# 格式化为RFC 3339格式
# rfc3339_time = utc_time.isoformat(timespec='seconds')
logging
.
info
(
'utc_time:
%
s'
%
utc_time
)
if
not
local_time
:
# 获取当前时间的UTC时间
local_time
=
datetime
.
datetime
.
now
()
# 将本地时间转换为UTC时间
utc_time
=
local_time
.
astimezone
(
pytz
.
utc
)
# 格式化为RFC 3339格式
rfc3339_time
=
utc_time
.
isoformat
(
timespec
=
'seconds'
)
return
rfc3339_time
# 定义一个方法,将时间的时区转为UTC时间
def
get_utc_time
(
self
,
local_time
=
None
):
if
not
local_time
:
# 获取当前时间的UTC时间
local_time
=
datetime
.
datetime
.
now
()
# 将本地时间转换为UTC时间
utc_time
=
local_time
.
astimezone
(
pytz
.
utc
)
# 格式化为RFC 3339格式
# rfc3339_time = utc_time.isoformat(timespec='seconds')
return
utc_time
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
def
get_format_time
(
self
,
parse_time
):
def
get_format_time
(
self
,
parse_time
):
"""
"""
把时间加上8小时
把时间加上8小时
...
...
ccs_connect_tiktok/models/cc_bill_loading.py
浏览文件 @
7916e40b
...
@@ -183,13 +183,16 @@ class CcShipPackage(models.Model):
...
@@ -183,13 +183,16 @@ class CcShipPackage(models.Model):
def
get_callback_track_data
(
self
):
def
get_callback_track_data
(
self
):
"""小包上传数据."""
"""小包上传数据."""
# 获取该提单下的所有同步状态为未同步的小包
# 获取该提单下的所有同步状态为未同步的小包
operate_time
,
timezone
=
self
.
env
[
'common.common'
]
.
get_local_time
(
self
.
process_time
)
push_data
=
{
push_data
=
{
"provider_order_id"
:
self
.
logistic_order_no
,
"provider_order_id"
:
self
.
logistic_order_no
,
"track_list"
:
[
"track_list"
:
[
{
{
"shipping_method_code"
:
self
.
state
.
tk_code
,
"shipping_method_code"
:
self
.
state
.
tk_code
,
"operate_time"
:
get_utc_time
(
self
.
process_time
),
"operate_time"
:
operate_time
,
"time_zone"
:
"UTC+0"
,
"time_zone"
:
timezone
,
# "operate_time": get_utc_time(self.process_time),
# "time_zone": "UTC+0",
"action_code"
:
self
.
state
.
tk_code
,
"action_code"
:
self
.
state
.
tk_code
,
"operation_desc"
:
self
.
state
.
desc
,
"operation_desc"
:
self
.
state
.
desc
,
"reason_code"
:
self
.
node_exception_reason_id
.
name
or
""
# 异常原因
"reason_code"
:
self
.
node_exception_reason_id
.
name
or
""
# 异常原因
...
@@ -458,8 +461,9 @@ class CcBl(models.Model):
...
@@ -458,8 +461,9 @@ class CcBl(models.Model):
"customs_waybill_id"
:
self
.
customs_bl_no
or
''
,
# 关务提单号取海关装货单号
"customs_waybill_id"
:
self
.
customs_bl_no
or
''
,
# 关务提单号取海关装货单号
"track_detail"
:
"track_detail"
:
{
{
"operate_time"
:
get_utc_rfc339_time
(
self
.
process_time
),
# "2025-03-19T09:28:00+00:00",
"operate_time"
:
self
.
env
[
'common.common'
]
.
get_local_rfc3339_time
(
self
.
process_time
),
# "#get_utc_time(self.process_time), # 事件发⽣时间,RFC3339格式(实操时间)
# "2025-03-19T09:28:00+00:00",
# get_utc_rfc339_time(self.process_time), # "2025-03-19T09:28:00+00:00", "#get_utc_time(self.process_time), # 事件发⽣时间,RFC3339格式(实操时间)
"waybill_status_code"
:
self
.
customs_clearance_status
.
tk_code
,
# 提单关务状态编码
"waybill_status_code"
:
self
.
customs_clearance_status
.
tk_code
,
# 提单关务状态编码
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论