修改打印逻辑,先找默认打印机,未找到则直接返回
This commit is contained in:
@@ -17,6 +17,11 @@ class JikimoPrinting(models.AbstractModel):
|
||||
"""
|
||||
打印二维码
|
||||
"""
|
||||
printer = self.env['printing.printer'].get_default()
|
||||
if not printer:
|
||||
_logger.error("未找到默认打印机")
|
||||
return
|
||||
|
||||
# 生成二维码
|
||||
qr = qrcode.QRCode(version=1, box_size=10, border=5)
|
||||
qr.add_data(data)
|
||||
@@ -45,8 +50,7 @@ class JikimoPrinting(models.AbstractModel):
|
||||
|
||||
# 获取PDF内容并打印
|
||||
pdf_content = pdf_buffer.getvalue()
|
||||
printer = self.env['printing.printer'].get_default()
|
||||
_logger.info(f"打印内容: {pdf_content}")
|
||||
# _logger.info(f"打印内容: {pdf_content}")
|
||||
printer.print_document(report=None, content=pdf_content, doc_format='pdf')
|
||||
|
||||
# 清理资源
|
||||
@@ -57,6 +61,11 @@ class JikimoPrinting(models.AbstractModel):
|
||||
"""
|
||||
打印PDF
|
||||
"""
|
||||
printer = self.env['printing.printer'].get_default()
|
||||
if not printer:
|
||||
_logger.error("未找到默认打印机")
|
||||
return
|
||||
|
||||
_logger.info("PDF打印开始")
|
||||
|
||||
pdf_data_str = pdf_data.decode('ascii', errors='ignore')
|
||||
@@ -71,12 +80,6 @@ class JikimoPrinting(models.AbstractModel):
|
||||
pdf_content = pdf_buffer.getvalue()
|
||||
_logger.info(f"处理后的内容前20字节: {pdf_content[:20]}")
|
||||
|
||||
# 获取默认打印机
|
||||
printer = self.env['printing.printer'].get_default()
|
||||
if not printer:
|
||||
_logger.error("未找到默认打印机")
|
||||
return
|
||||
|
||||
printer.print_document(report=None, content=pdf_content, doc_format='pdf')
|
||||
# 清理资源
|
||||
pdf_buffer.close()
|
||||
|
||||
Reference in New Issue
Block a user