提交 df7602c3 authored 作者: 贺阳's avatar 贺阳

每次获取尾程pod都新生成一条附件信息,不进行覆盖

上级 1cdc26ee
......@@ -44,7 +44,6 @@ class BatchGetPodInfoWizard(models.TransientModel):
bl_objs = self.get_order()
# 调用接口获取提单pdf文件
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文件,匹配提单对象
......@@ -70,72 +69,6 @@ class BatchGetPodInfoWizard(models.TransientModel):
if self.sync_last_mile_pod:
self._sync_last_mile_pod(processed_files)
def _get_pdf_file_arr_test(self):
"""
Get PDF file from test data # 从测试数据获取PDF文件
"""
pdf_file_arr = []
bl_objs = self.get_order()
for bl in bl_objs:
clearance_file = self.env['cc.clearance.file'].sudo().search_clearance_file(bl.id,
'尾程交接POD(待大包数量和箱号)') #查找清关文件
if clearance_file and clearance_file.file:
try:
# 验证原始文件数据
file_data = clearance_file.file
if isinstance(file_data, bytes):
# 验证PDF文件头
if not file_data.startswith(b'%PDF-'):
# 检查是否是base64编码的字符串
try:
decoded_data = base64.b64decode(file_data)
if decoded_data.startswith(b'%PDF-'):
file_data = decoded_data
else:
continue
except Exception as e:
continue
elif isinstance(file_data, str):
# 尝试base64解码
try:
decoded_data = base64.b64decode(file_data)
if decoded_data.startswith(b'%PDF-'):
file_data = decoded_data
else:
continue
except Exception as e:
continue
else:
continue
# # 验证PDF可以打开
# try:
# import fitz
# test_doc = fitz.open(stream=file_data, filetype="pdf")
# page_count = len(test_doc)
# test_doc.close()
# _logger.info(f"清关文件PDF验证成功,页数: {page_count},提单号: {bl.bl_no}")
# except Exception as e:
# _logger.warning(f"清关文件PDF无法打开,提单号: {bl.bl_no}, 错误: {str(e)}")
# continue
# 转换为base64
file_data_base64 = base64.b64encode(file_data).decode('utf-8')
pdf_file_arr.append({
'bl_no': self.env['common.common'].sudo().process_match_str(bl.bl_no),
'file_name': clearance_file.attachment_name or clearance_file.file_name,
'file_data': file_data_base64
})
except Exception as e:
_logger.error(f"处理清关文件失败,提单号: {bl.bl_no}, 错误: {str(e)}")
continue
else:
_logger.warning(f"未找到清关文件,提单号: {bl.bl_no}")
return pdf_file_arr
# 写一个方法掉接口获取提单pdf文件
def _get_pdf_file_arr(self):
"""
......@@ -227,24 +160,13 @@ class BatchGetPodInfoWizard(models.TransientModel):
bl = file_info['bl']
file_name = file_info['file_name']
file_data = file_info['file_data']
# 查找或创建清关文件记录
clearance_file = self.env['cc.clearance.file'].sudo().search_clearance_file(bl.id,
'尾程交接POD(待大包数量和箱号)')
if not clearance_file:
# 创建新的清关文件记录
clearance_file = self.env['cc.clearance.file'].create({
'bl_id': bl.id,
'file_name': '尾程交接POD(待大包数量和箱号)',
'attachment_name': file_name,
'file': file_data
})
else:
# 更新现有记录
clearance_file.write({
'attachment_name': file_name,
'file': file_data
})
# 创建新的清关文件记录
clearance_file = self.env['cc.clearance.file'].create({
'bl_id': bl.id,
'file_name': '尾程交接POD(待大包数量和箱号)',
'attachment_name': file_name,
'file': file_data
})
file_info['clearance_file'] = clearance_file
def _match_bl_by_file_name(self, pdf_file_arr):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论