Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
hh_ccs
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
贺阳
hh_ccs
Commits
fcc37794
提交
fcc37794
authored
4月 15, 2026
作者:
刘擎阳
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.优化
上级
50774994
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
56 行增加
和
34 行删除
+56
-34
main.py
ccs_connect_tiktok/controllers/main.py
+3
-1
cc_bill_loading.py
ccs_connect_tiktok/models/cc_bill_loading.py
+52
-32
cc_bl_view.xml
ccs_connect_tiktok/views/cc_bl_view.xml
+1
-1
没有找到文件。
ccs_connect_tiktok/controllers/main.py
浏览文件 @
fcc37794
...
...
@@ -30,6 +30,7 @@ class CmcIntegrationController(http.Controller):
tracking_number
=
data
.
get
(
'tracking_no'
)
event_type
=
data
.
get
(
'event'
)
event_time_str
=
data
.
get
(
'event_time'
)
event_time_local
=
data
.
get
(
'event_time_local'
)
if
not
tracking_number
or
not
event_type
:
return
self
.
_json_response
({
'status'
:
'error'
,
'message'
:
'Missing parameters'
})
...
...
@@ -49,7 +50,8 @@ class CmcIntegrationController(http.Controller):
'flight_dynamic_ids'
:
[(
0
,
0
,
{
'type'
:
dynamic_type
,
'event_time_utc'
:
event_time
,
'timezone'
:
'UTC'
,
'event_time_local'
:
event_time_local
,
# 'timezone': 'UTC',
'status'
:
'valid'
,
})]
})
...
...
ccs_connect_tiktok/models/cc_bill_loading.py
浏览文件 @
fcc37794
...
...
@@ -1516,15 +1516,15 @@ class FreightFlightDynamic(models.Model):
],
string
=
"类型"
,
required
=
True
)
# Odoo 的 Datetime 字段在数据库层面默认就是以 0时区 (UTC) 存储的
event_time_utc
=
fields
.
Datetime
(
string
=
"发生时间
(UTC)
"
,
default
=
fields
.
Datetime
.
now
,
required
=
True
)
event_time_utc
=
fields
.
Datetime
(
string
=
"发生时间"
,
default
=
fields
.
Datetime
.
now
,
required
=
True
)
# 时区选择和计算本地时间
@api.model
def
_tz_get
(
self
):
return
[(
x
,
x
)
for
x
in
pytz
.
all_timezones
]
timezone
=
fields
.
Selection
(
_tz_get
,
string
=
'发生地时区'
,
default
=
'UTC'
,
required
=
True
)
event_time_local
=
fields
.
Char
(
string
=
"发生地时间
(含时区)"
,
compute
=
'_compute_local_time'
,
store
=
True
)
#
timezone = fields.Selection(_tz_get, string='发生地时区', default='UTC', required=True)
event_time_local
=
fields
.
Char
(
string
=
"发生地时间
"
)
# 记录人,默认当前用户
user_id
=
fields
.
Many2one
(
'res.users'
,
string
=
"记录人"
,
default
=
lambda
self
:
self
.
env
.
user
,
readonly
=
True
)
...
...
@@ -1535,42 +1535,62 @@ class FreightFlightDynamic(models.Model):
(
'invalid'
,
'无效'
)
],
string
=
"状态"
,
default
=
'valid'
,
readonly
=
True
)
@api.depends
(
'event_time_utc'
,
'timezone'
)
def
_compute_local_time
(
self
):
"""根据 UTC 时间和选择的时区,计算并拼接出当地时间字符串"""
for
record
in
self
:
if
record
.
event_time_utc
and
record
.
timezone
:
tz
=
pytz
.
timezone
(
record
.
timezone
)
utc_dt
=
pytz
.
utc
.
localize
(
record
.
event_time_utc
)
local_dt
=
utc_dt
.
astimezone
(
tz
)
# 格式化为:2023-10-25 14:30:00 (Asia/Shanghai)
record
.
event_time_local
=
f
"{local_dt.strftime('
%
Y-
%
m-
%
d
%
H:
%
M:
%
S')} ({record.timezone})"
else
:
record
.
event_time_local
=
False
# @api.depends('event_time_utc', 'timezone')
# def _compute_local_time(self):
# """根据 UTC 时间和选择的时区,计算并拼接出当地时间字符串"""
# for record in self:
# if record.event_time_utc and record.timezone:
# tz = pytz.timezone(record.timezone)
# utc_dt = pytz.utc.localize(record.event_time_utc)
# local_dt = utc_dt.astimezone(tz)
# # 格式化为:2023-10-25 14:30:00 (Asia/Shanghai)
# record.event_time_local = f"{local_dt.strftime('%Y-%m-%d %H:%M:%S')} ({record.timezone})"
# else:
# record.event_time_local = False
# @api.model
# def create(self, vals):
# """
# 拦截创建方法:
# 新增时,查找该提单下同类型的【有效】记录,将其置为【无效】。
# 确保只有最新的一条是【有效】的。
# """
# bill_id = vals.get('bill_id')
# dyn_type = vals.get('type')
#
# if bill_id and dyn_type:
# # 寻找同类型且状态为有效的老记录
# existing_valid_records = self.search([
# ('bill_id', '=', bill_id),
# ('type', '=', dyn_type),
# ('status', '=', 'valid')
# ])
# if existing_valid_records:
# existing_valid_records.write({'status': 'invalid'})
#
# # 强制将新创建的记录设为有效
# vals['status'] = 'valid'
# return super(FreightFlightDynamic, self).create(vals)
@api.model
def
create
(
self
,
vals
):
"""
拦截创建方法:
新增时,查找该提单下同类型的【有效】记录,将其置为【无效】。
确保只有最新的一条是【有效】的。
"""
bill_id
=
vals
.
get
(
'bill_id'
)
dyn_type
=
vals
.
get
(
'type'
)
if
bill_id
and
dyn_type
:
# 寻找同类型且状态为有效的老记录
vals
[
'status'
]
=
'valid'
record
=
super
(
FreightFlightDynamic
,
self
)
.
create
(
vals
)
if
record
.
bill_id
and
record
.
type
:
existing_valid_records
=
self
.
search
([
(
'bill_id'
,
'='
,
bill_id
),
(
'type'
,
'='
,
dyn_type
),
(
'status'
,
'='
,
'valid'
)
(
'bill_id'
,
'='
,
record
.
bill_id
.
id
),
(
'type'
,
'='
,
record
.
type
),
(
'status'
,
'='
,
'valid'
),
(
'id'
,
'!='
,
record
.
id
)
# 核心注意点:必须排除刚刚创建的这条新记录自己
])
if
existing_valid_records
:
existing_valid_records
.
write
({
'status'
:
'invalid'
})
# 强制将新创建的记录设为有效
vals
[
'status'
]
=
'valid'
return
super
(
FreightFlightDynamic
,
self
)
.
create
(
vals
)
if
record
.
event_time_utc
:
if
record
.
type
==
'departure'
:
record
.
bill_id
.
write
({
'actual_departure_time'
:
record
.
event_time_utc
})
elif
record
.
type
==
'arrival'
:
record
.
bill_id
.
write
({
'actual_arrival_time'
:
record
.
event_time_utc
})
return
record
def
unlink
(
self
):
"""拦截删除方法:只能新增,不能删除"""
...
...
ccs_connect_tiktok/views/cc_bl_view.xml
浏览文件 @
fcc37794
...
...
@@ -76,7 +76,7 @@
<tree
string=
"动态记录"
editable=
"top"
delete=
"0"
default_order=
"create_date desc"
>
<field
name=
"type"
/>
<field
name=
"event_time_utc"
/>
<field
name=
"timezone"
/
>
<!-- <field name="timezone"/>--
>
<field
name=
"event_time_local"
/>
<field
name=
"user_id"
/>
<field
name=
"create_date"
string=
"创建时间"
readonly=
"1"
/>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论