Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
hh_ccs
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
贺阳
hh_ccs
Commits
6c370518
提交
6c370518
authored
2月 14, 2025
作者:
贺阳
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改接口,同步小包进度的优化
上级
bd7afa21
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
68 行增加
和
49 行删除
+68
-49
cc_bill_loading.py
ccs_base/models/cc_bill_loading.py
+39
-2
order_controller.py
ccs_connect_tiktok/controllers/order_controller.py
+9
-36
cc_bill_loading.py
ccs_connect_tiktok/models/cc_bill_loading.py
+3
-1
mail_push.py
consumers/mail_push.py
+13
-9
push_ship_package_state.py
consumers/push_ship_package_state.py
+3
-0
push_ship_package_state.conf
...mers/supervisord_conf/conf.d/push_ship_package_state.conf
+1
-1
没有找到文件。
ccs_base/models/cc_bill_loading.py
浏览文件 @
6c370518
...
...
@@ -1068,19 +1068,23 @@ class CcBL(models.Model):
# print(wizard_obj.get_order())
wizard_obj
.
submit
()
def
try_callback_track
(
self
,
max_retries
=
3
):
def
try_callback_track
(
self
,
max_retries
=
3
,
ship_package_ids
=
[]
):
""" 封装的重试逻辑 """
for
i
in
range
(
max_retries
):
if
not
ship_package_ids
:
is_ok
=
self
.
callback_track
()
else
:
is_ok
=
self
.
package_callback_func
(
ship_package_ids
)
if
is_ok
:
return
True
logging
.
warning
(
f
"Attempt {i + 1}/{max_retries} failed. Retrying..."
)
return
False
def
mail_auto_push
(
self
,
mail_time
):
def
mail_auto_push
(
self
,
mail_time
=
False
,
ship_packages
=
[],
action_type
=
'tally'
):
self
=
self
.
with_context
(
dict
(
self
.
_context
,
is_mail
=
True
))
for
item
in
self
:
try
:
if
mail_time
:
utc_time
=
datetime
.
strptime
(
mail_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
before_min
=
self
.
env
[
'ir.config_parameter'
]
.
sudo
()
.
get_param
(
'before_min'
)
or
10
before_utc_time
=
utc_time
-
timedelta
(
minutes
=
int
(
before_min
))
...
...
@@ -1093,6 +1097,39 @@ class CcBL(models.Model):
logging
.
error
(
f
"Failed to push item after {3} attempts."
)
else
:
logging
.
error
(
f
"Failed to start process for item after {3} attempts."
)
elif
ship_packages
:
ship_package_ids
=
[
ship_package_dict
[
'id'
]
for
ship_package_dict
in
ship_packages
if
ship_package_dict
[
'id'
]]
tally_state
=
'checked_goods'
if
action_type
==
'tally'
else
'handover_completed'
node_obj
=
self
.
env
[
'cc.node'
]
.
sudo
()
.
search
([
(
'node_type'
,
'='
,
'package'
),
(
'tally_state'
,
'='
,
tally_state
)
# Check for both states
],
order
=
'seq asc'
)
# Order by sequence and creation date ascending
if
node_obj
:
for
index
,
node
in
enumerate
(
node_obj
):
for
ship_package_dict
in
ship_packages
:
ship_package_id
=
ship_package_dict
[
'id'
]
ship_package
=
self
.
env
[
'cc.ship.package'
]
.
browse
(
ship_package_id
)
# 小包
tally_time
=
ship_package_dict
[
'tally_time'
]
operation_time
=
(
datetime
.
strptime
(
tally_time
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
+
timedelta
(
minutes
=
20
*
(
index
+
1
)))
if
tally_time
else
fields
.
Datetime
.
now
()
+
timedelta
(
minutes
=
20
*
(
index
+
1
))
# Increment time by 20 minutes for each node
state_node_obj
=
self
.
env
[
'cc.node'
]
.
sudo
()
.
search
(
[(
'node_type'
,
'='
,
'package'
),
(
'name'
,
'='
,
ship_package
.
state
.
name
)],
limit
=
1
)
if
state_node_obj
.
seq
<
node
.
seq
:
# Ensure the current state is valid
ship_package
.
write
({
'state'
:
node
.
id
,
'process_time'
:
operation_time
,
'state_explain'
:
node
.
desc
,
'is_sync'
:
True
if
node
.
is_default
else
False
})
if
self
.
state
==
'draft'
and
self
.
ship_package_ids
.
filtered
(
lambda
line
:
line
.
state
.
tk_code
==
'cb_imcustoms_start'
):
self
.
ccing_func
()
# 同步状态
# 尝试调用 callback_track
self
.
try_callback_track
(
max_retries
=
2
,
ship_package_ids
=
ship_package_ids
)
except
Exception
as
err
:
logging
.
error
(
'fetch_mail_dlv--error:
%
s'
%
str
(
err
))
...
...
ccs_connect_tiktok/controllers/order_controller.py
浏览文件 @
6c370518
...
...
@@ -170,13 +170,13 @@ class OrderController(http.Controller):
tally_time
=
package_item
.
get
(
'tally_time'
)
if
package_type
==
'ship'
:
ship_packages
.
append
({
'id'
:
package_obj
,
'id'
:
package_obj
.
id
,
'tally_time'
:
tally_time
})
else
:
# if package.tally_state == 'unprocessed_goods'
for
package
in
package_obj
:
ship_packages
+=
[{
'id'
:
ship_package
,
'id'
:
ship_package
.
id
,
'tally_time'
:
tally_time
}
for
ship_package
in
package
.
ship_package_ids
if
package
.
tally_state
==
'unprocessed_goods'
]
# 小包
...
...
@@ -239,43 +239,16 @@ class OrderController(http.Controller):
'ship package'
,
[
exception_id
],
ship_package_ids
=
ship_package
,
send_email
=
True
,
email_language
=
lang
)
ship_wizard_obj
.
confirm
()
# 发送邮件
#
更新小包状态
res
[
'state'
]
=
200
#
有小包 就更新小包状态和同步
if
ship_packages
:
tally_state
=
'checked_goods'
if
action_type
==
'tally'
else
'handover_completed'
node_obj
=
request
.
env
[
'cc.node'
]
.
sudo
()
.
search
([
(
'node_type'
,
'='
,
'package'
),
(
'tally_state'
,
'='
,
tally_state
)
# Check for both states
],
order
=
'seq asc'
)
# Order by sequence and creation date ascending
if
node_obj
:
for
index
,
node
in
enumerate
(
node_obj
):
for
ship_package_dict
in
ship_packages
:
ship_package
=
ship_package_dict
[
'id'
]
tally_time
=
ship_package_dict
[
'tally_time'
]
operation_time
=
(
datetime
.
strptime
(
tally_time
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
+
timedelta
(
minutes
=
20
*
(
index
+
1
)))
if
tally_time
else
fields
.
Datetime
.
now
()
+
timedelta
(
minutes
=
20
*
(
index
+
1
))
# Increment time by 20 minutes for each node
state_node_obj
=
request
.
env
[
'cc.node'
]
.
sudo
()
.
search
(
[(
'node_type'
,
'='
,
'package'
),
(
'name'
,
'='
,
ship_package
.
state
.
name
)],
limit
=
1
)
if
state_node_obj
.
seq
<
node
.
seq
:
# Ensure the current state is valid
ship_package
.
write
({
'state'
:
node
.
id
,
'process_time'
:
operation_time
,
'state_explain'
:
node
.
desc
,
'is_sync'
:
True
if
node
.
is_default
else
False
})
if
bl_obj
.
state
==
'draft'
and
bl_obj
.
ship_package_ids
.
filtered
(
lambda
line
:
line
.
state
.
tk_code
==
'cb_imcustoms_start'
):
bl_obj
.
ccing_func
()
ship_package_ids
=
tuple
(
ship_package_dict
[
'id'
]
.
id
for
ship_package_dict
in
ship_packages
if
ship_package_dict
[
'id'
])
redis_conn
=
request
.
env
[
'common.common'
]
.
sudo
()
.
get_redis
()
if
redis_conn
and
redis_conn
!=
'no'
:
redis_conn
.
lpush
(
'push_ship_package_state'
,
json
.
dumps
(
{
'bl_id'
:
bl_obj
.
id
,
'ship_package_ids'
:
ship_package_ids
}))
res
[
'state'
]
=
200
# redis_conn.lpush('push_ship_package_state', json.dumps(
# {'bl_id': bl_obj.id, 'ship_package_ids': ship_package_ids}))
redis_conn
.
lpush
(
'mail_push_package_list'
,
json
.
dumps
(
{
'id'
:
bl_obj
.
id
,
'ship_packages'
:
str
(
ship_packages
),
'action_type'
:
action_type
}))
else
:
res
[
'message'
]
=
bill_noexist_msg_dic
[
pda_lang
]
# 提单不存在
else
:
...
...
ccs_connect_tiktok/models/cc_bill_loading.py
浏览文件 @
6c370518
...
...
@@ -131,7 +131,7 @@ class CcShipPackageSyncLog(models.Model):
class
CcShipPackage
(
models
.
Model
):
_inherit
=
"cc.ship.package"
is_sync
=
fields
.
Boolean
(
'Is Sync'
,
default
=
False
)
is_sync
=
fields
.
Boolean
(
'Is Sync'
,
default
=
False
,
index
=
True
)
tk_code
=
fields
.
Char
(
related
=
'state.tk_code'
,
store
=
True
,
string
=
'TK Code'
,
help
=
'TK Code'
)
# 增加同步日志纪录字段
...
...
@@ -270,6 +270,7 @@ class CcBl(models.Model):
同步小包状态
"""
ship_packages
=
self
.
env
[
'cc.ship.package'
]
.
search
([(
'id'
,
'in'
,
ship_package_ids
),
(
'is_sync'
,
'='
,
False
)])
logging
.
info
(
'package_callback_func ship_packages:
%
s'
%
len
(
ship_packages
))
is_ok
=
True
tt_api_obj
=
self
.
env
[
"ao.tt.api"
]
.
sudo
()
...
...
@@ -278,6 +279,7 @@ class CcBl(models.Model):
async
with
aiohttp
.
ClientSession
(
connector
=
aiohttp
.
TCPConnector
(
ssl
=
ssl_context
),
timeout
=
aiohttp
.
ClientTimeout
(
total
=
60
))
as
session
:
tasks
=
[]
logging
.
info
(
'------123'
)
for
index
,
package
in
enumerate
(
ship_packages
):
if
not
package
.
is_sync
and
package
.
state
and
package
.
state
.
tk_code
:
data
=
package
.
get_callback_track_data
()
...
...
consumers/mail_push.py
浏览文件 @
6c370518
# coding=utf-8
import
json
import
logging
import
odoorpc
import
redis
import
time
import
requests
import
odoorpc
from
requests.adapters
import
HTTPAdapter
import
time
from
datetime
import
datetime
import
config
from
requests.adapters
import
HTTPAdapter
import
config
# 默认字符gbk
# logging.basicConfig(filename='./push_data_logger.log', level=logging.INFO)
logging
.
basicConfig
(
filename
=
'./push_data_logger.log'
,
level
=
logging
.
INFO
)
# 设置文件字符为utf-8
logging
.
basicConfig
(
handlers
=
[
logging
.
FileHandler
(
'logs/mail_push.log'
,
'a'
,
'utf-8'
)],
format
=
'
%(asctime)
s
%(levelname)
s
%(message)
s'
,
level
=
logging
.
INFO
)
#
logging.basicConfig(handlers=[logging.FileHandler('logs/mail_push.log', 'a', 'utf-8')],
#
format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
class
Order_dispose
(
object
):
...
...
@@ -29,11 +31,13 @@ class Order_dispose(object):
try
:
data
=
json
.
loads
(
data
)
logging
.
info
(
'mail_push_data:
%
s'
,
data
)
ship_packages
=
eval
(
data
[
'ship_packages'
])
if
data
.
get
(
'ship_packages'
)
else
[]
# 小包
action_type
=
data
.
get
(
'action_type'
)
# 类型
bl_obj
=
self
.
odoo_db
.
env
[
'cc.bl'
]
bl_record
=
bl_obj
.
browse
(
data
[
'id'
])
# utc_time = datetime.strptime(data['utc_time'], "%Y-%m-%d %H:%M:%S")
utc_time
=
data
[
'utc_time'
]
bl_record
.
mail_auto_push
(
utc_time
)
utc_time
=
data
.
get
(
'utc_time'
)
bl_record
.
mail_auto_push
(
utc_time
,
ship_packages
,
action_type
)
except
Exception
as
ex
:
logging
.
error
(
'mail_auto_push error:
%
s'
%
str
(
ex
))
return
res_data
...
...
consumers/push_ship_package_state.py
浏览文件 @
6c370518
...
...
@@ -35,7 +35,10 @@ class Order_dispose(object):
bl_id
=
result
[
'bl_id'
]
logging
.
info
(
'push_ship_package_state kw:
%
s'
,
result
)
bl_obj
=
self
.
odoo_db
.
env
[
'cc.bl'
]
.
browse
(
bl_id
)
# 提单
logging
.
info
(
'bl_obj:
%
s'
%
bl_obj
)
logging
.
info
(
'ship_package_ids:
%
s'
%
len
(
ship_package_ids
))
is_ok
=
bl_obj
.
package_callback_func
(
ship_package_ids
)
# 调用同步包裹状态
logging
.
info
(
'is_ok:
%
s'
%
is_ok
)
# 失败的重复推送 重复推2次
for
i
in
range
(
2
):
if
not
is_ok
:
...
...
consumers/supervisord_conf/conf.d/push_ship_package_state.conf
浏览文件 @
6c370518
[
program
:
push_ship_consumer_1
]
[
program
:
push_ship_
package_state_
consumer_1
]
process_name
=%(
program_name
)
s_
%(
process_num
)
02
d
; 进程名称
directory
= /
mnt
/
extra
-
addons
; 程序的启动目录
command
= /
usr
/
bin
/
python3
/
mnt
/
extra
-
addons
/
push_ship_package_state
.
py
; 启动命令
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论