Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
hh_ccs
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
贺阳
hh_ccs
Commits
1cdc26ee
提交
1cdc26ee
authored
10月 17, 2025
作者:
贺阳
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
调用接口测试
上级
5d24d257
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
5 行增加
和
57 行删除
+5
-57
batch_get_pod_info_wizard.py
ccs_base/wizard/batch_get_pod_info_wizard.py
+5
-57
没有找到文件。
ccs_base/wizard/batch_get_pod_info_wizard.py
浏览文件 @
1cdc26ee
...
...
@@ -42,10 +42,9 @@ class BatchGetPodInfoWizard(models.TransientModel):
Confirm operation # 确认操作
"""
bl_objs
=
self
.
get_order
()
# 调用接口获取提单pdf文件
#
pdf_file_arr = self._get_pdf_file_arr()
pdf_file_arr
=
self
.
_get_pdf_file_arr_test
()
pdf_file_arr
=
self
.
_get_pdf_file_arr
()
#
pdf_file_arr = self._get_pdf_file_arr_test()
if
not
pdf_file_arr
:
raise
ValidationError
(
_
(
'No PDF files found'
))
#提示:没有获取到PDF文件
# 处理PDF文件,匹配提单对象
...
...
@@ -165,21 +164,17 @@ class BatchGetPodInfoWizard(models.TransientModel):
if
response
.
status_code
==
200
:
result
=
response
.
json
()
# 检查API响应结构
if
not
result
:
_logger
.
error
(
"API返回空响应"
)
raise
ValidationError
(
_
(
'API returned empty response'
))
if
not
result
.
get
(
'success'
):
error_msg
=
result
.
get
(
'message'
,
'Unknown error'
)
_logger
.
error
(
f
"API返回失败状态: {error_msg}"
)
raise
ValidationError
(
_
(
'API returned error:
%
s'
)
%
error_msg
)
# 处理结果数据
results
=
result
.
get
(
'results'
,
[])
if
not
results
:
_logger
.
warning
(
"API调用成功,但没有PDF文件"
)
raise
ValidationError
(
_
(
'No PDF files found in API response'
))
#提示:API调用成功,但没有PDF文件
# 构建PDF文件数组
pdf_file_arr
=
[]
...
...
@@ -197,30 +192,15 @@ class BatchGetPodInfoWizard(models.TransientModel):
# 验证PDF文件
try
:
pdf_binary
=
base64
.
b64decode
(
base64_data
)
# 验证PDF文件头
if
not
pdf_binary
.
startswith
(
b
'
%
PDF-'
):
_logger
.
warning
(
f
"API返回的文件不是有效的PDF格式,提单号: {bill_number}"
)
continue
# 验证PDF可以打开
try
:
import
fitz
test_doc
=
fitz
.
open
(
stream
=
pdf_binary
,
filetype
=
"pdf"
)
page_count
=
len
(
test_doc
)
test_doc
.
close
()
_logger
.
info
(
f
"API PDF验证成功,页数: {page_count},提单号: {bill_number}"
)
except
Exception
as
e
:
_logger
.
warning
(
f
"API PDF文件无法打开,提单号: {bill_number}, 错误: {str(e)}"
)
continue
pdf_file_arr
.
append
({
'bl_no'
:
bill_number
,
'file_name'
:
filename
,
'file_data'
:
base64_data
})
_logger
.
info
(
f
"成功添加API PDF文件,提单号: {bill_number}, 文件名: {filename}"
)
except
Exception
as
e
:
_logger
.
warning
(
f
"API PDF文件验证失败,提单号: {bill_number}, 错误: {str(e)}"
)
continue
...
...
@@ -229,16 +209,11 @@ class BatchGetPodInfoWizard(models.TransientModel):
_logger
.
error
(
"所有API PDF文件验证都失败"
)
raise
ValidationError
(
_
(
'All API PDF files failed validation'
))
#提示:所有API PDF文件验证都失败
_logger
.
info
(
f
"API调用成功,获取到{len(pdf_file_arr)}个有效PDF文件"
)
return
pdf_file_arr
else
:
_logger
.
error
(
f
"API调用失败,状态码: {response.status_code}"
)
_logger
.
error
(
f
"响应内容: {response.text}"
)
raise
ValidationError
(
_
(
'Failed to get PDF file from API:
%
s'
)
%
response
.
text
)
except
requests
.
exceptions
.
RequestException
as
e
:
_logger
.
error
(
f
"API请求异常: {str(e)}"
)
raise
ValidationError
(
_
(
'API request failed:
%
s'
)
%
str
(
e
))
def
_write_pdf_file
(
self
,
processed_files
):
...
...
@@ -297,7 +272,7 @@ class BatchGetPodInfoWizard(models.TransientModel):
}
processed_files
.
append
(
processed_file
)
break
_logger
.
info
(
f
"匹配完成,成功匹配{len(processed_files)}个文件
,匹配结果: {processed_files}
"
)
_logger
.
info
(
f
"匹配完成,成功匹配{len(processed_files)}个文件"
)
return
processed_files
def
_sync_last_mile_pod
(
self
,
processed_files
):
...
...
@@ -339,40 +314,15 @@ class BatchGetPodInfoWizard(models.TransientModel):
# 使用OCR识别和删除指定文字
if
file_data
:
# 将base64数据转换为二进制
import
base64
try
:
pdf_binary
=
base64
.
b64decode
(
file_data
)
# _logger.info(f"Base64解码成功,数据大小: {len(pdf_binary)}字节,提单号: {bl.bl_no}")
# # 验证PDF文件头
# if not pdf_binary.startswith(b'%PDF-'):
# _logger.error(f"解码后的数据不是有效的PDF文件,提单号: {bl.bl_no}")
# _logger.error(f"文件头: {pdf_binary[:20]}")
# raise ValidationError(_('Decoded data is not a valid PDF file for BL %s') % bl.bl_no)#提示:解码后的数据不是有效的PDF文件
# # 验证PDF可以打开
# try:
# import fitz
# test_doc = fitz.open(stream=pdf_binary, filetype="pdf")
# page_count = len(test_doc)
# test_doc.close()
# _logger.info(f"PDF验证成功,页数: {page_count},提单号: {bl.bl_no}")
# except Exception as e:
# _logger.error(f"PDF文件无法打开,提单号: {bl.bl_no}, 错误: {str(e)}")
except
Exception
as
e
:
_logger
.
error
(
f
"Base64解码失败,提单号: {bl.bl_no}, 错误: {str(e)}"
)
# 使用OCR方法处理PDF
processed_pdf
=
self
.
_process_pdf_with_ocr
(
pdf_data
=
pdf_binary
,
bl_no
=
bl
.
bl_no
)
if
processed_pdf
:
# 将处理后的PDF转换回base64
processed_file_data
=
base64
.
b64encode
(
processed_pdf
)
.
decode
(
'utf-8'
)
_logger
.
info
(
f
"Successfully removed specified text from PDF for BL {bl.bl_no}"
)
_logger
.
info
(
f
"处理后的PDF base64数据长度: {len(processed_file_data)}"
)
# 更新文件信息,使用处理后的PDF数据
updated_file_info
=
file_info
.
copy
()
...
...
@@ -412,7 +362,7 @@ class BatchGetPodInfoWizard(models.TransientModel):
processed_pages
=
0
detected_texts
=
[]
all_recognized_texts
=
[]
result_data
=
False
# 处理每一页(完全按照HTML逻辑)
for
page_num
in
range
(
len
(
pdf_document
)):
page
=
pdf_document
[
page_num
]
...
...
@@ -726,8 +676,6 @@ class BatchGetPodInfoWizard(models.TransientModel):
:param file_info: 处理后的文件信息
:return: Odoo action to download the file
"""
import
base64
try
:
# 获取处理后的PDF数据
file_data
=
file_info
.
get
(
'file_data'
,
''
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论