Accept Merge Request #2085: (feature/6694 -> develop)
Merge Request: 删除多余的打印代码 Created By: @胡尧 Accepted By: @胡尧 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2085?initial=true
This commit is contained in:
@@ -62,56 +62,6 @@ class JikimoPrinting(models.AbstractModel):
|
||||
pdf_data_str = pdf_data.decode('ascii', errors='ignore')
|
||||
decoded_data = base64.b64decode(pdf_data_str)
|
||||
|
||||
# 检查输入数据类型
|
||||
# _logger.info(f"输入数据类型: {type(pdf_data)}")
|
||||
|
||||
# # 如果数据是bytes类型但看起来是base64编码,先解码一次
|
||||
# if isinstance(pdf_data, bytes) and pdf_data[:10].decode('ascii', errors='ignore').isalnum():
|
||||
# try:
|
||||
# # 尝试将bytes转为字符串后解码
|
||||
# pdf_data_str = pdf_data.decode('ascii', errors='ignore')
|
||||
# decoded_data = base64.b64decode(pdf_data_str)
|
||||
# _logger.info(f"对bytes类型的base64数据进行解码,解码后前20字节: {decoded_data[:20]}")
|
||||
# # 检查是否是PDF格式
|
||||
# if decoded_data[:4] == b'%PDF':
|
||||
# _logger.info("解码后得到PDF格式数据")
|
||||
# pdf_data = decoded_data
|
||||
# except Exception as e:
|
||||
# _logger.error(f"base64解码bytes数据失败: {str(e)}")
|
||||
|
||||
# # 常规的数据处理
|
||||
# if isinstance(pdf_data, str):
|
||||
# _logger.info("输入数据是字符串类型")
|
||||
# try:
|
||||
# decoded_data = base64.b64decode(pdf_data)
|
||||
# _logger.info(f"成功解码base64数据,解码后前20字节: {decoded_data[:20]}")
|
||||
# except Exception as e:
|
||||
# _logger.error(f"base64解码失败: {str(e)}")
|
||||
# decoded_data = pdf_data.encode()
|
||||
# else:
|
||||
# _logger.info("处理bytes类型数据")
|
||||
# decoded_data = pdf_data
|
||||
|
||||
# # 检查解码后数据是否为PDF格式
|
||||
# is_pdf = False
|
||||
# try:
|
||||
# if decoded_data[:4] == b'%PDF':
|
||||
# is_pdf = True
|
||||
# _logger.info("数据是PDF格式")
|
||||
# else:
|
||||
# _logger.info(f"数据不是PDF格式,前20字节: {decoded_data[:20]}")
|
||||
# # 最后尝试直接以base64解码
|
||||
# try:
|
||||
# final_try = base64.b64decode(decoded_data)
|
||||
# if final_try[:4] == b'%PDF':
|
||||
# _logger.info("最后尝试解码成功")
|
||||
# decoded_data = final_try
|
||||
# is_pdf = True
|
||||
# except:
|
||||
# _logger.info("最后尝试解码失败")
|
||||
# except Exception as e:
|
||||
# _logger.error(f"检查PDF格式时出错: {str(e)}")
|
||||
|
||||
# 处理二进制数据
|
||||
pdf_buffer = BytesIO()
|
||||
pdf_buffer.write(decoded_data)
|
||||
@@ -127,17 +77,7 @@ class JikimoPrinting(models.AbstractModel):
|
||||
_logger.error("未找到默认打印机")
|
||||
return
|
||||
|
||||
# 使用正确的格式打印
|
||||
# try:
|
||||
# if is_pdf:
|
||||
# _logger.info("使用PDF格式打印")
|
||||
printer.print_document(report=None, content=pdf_content, doc_format='pdf')
|
||||
# else:
|
||||
# _logger.info("使用RAW格式打印")
|
||||
# printer.print_document(report=None, content=pdf_content, doc_format='raw')
|
||||
# except Exception as e:
|
||||
# _logger.error(f"打印时出错: {str(e)}")
|
||||
|
||||
# 清理资源
|
||||
pdf_buffer.close()
|
||||
_logger.info("PDF打印结束")
|
||||
@@ -19,7 +19,6 @@ class MrpWorkorder(models.Model):
|
||||
if pdf_data:
|
||||
try:
|
||||
# 执行打印
|
||||
_logger.info(f"准备打印工单 {wo.name} 的PDF")
|
||||
self.env['jikimo.printing'].print_pdf(pdf_data)
|
||||
wo.production_id.product_id.is_print_program = True
|
||||
_logger.info(f"工单 {wo.name} 的PDF已成功打印")
|
||||
|
||||
Reference in New Issue
Block a user