70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
from odoo import models, fields, api
|
|
|
|
class MaintenancePrinting(models.Model):
|
|
_inherit = 'maintenance.equipment'
|
|
|
|
def print_single_method(self):
|
|
|
|
print('self.name========== %s' % self.name)
|
|
self.ensure_one()
|
|
# maintenance_equipment_id = self.id
|
|
# # host = "192.168.50.110" # 可以根据实际情况修改
|
|
# # port = 9100 # 可以根据实际情况修改
|
|
|
|
# # 获取默认打印机配置
|
|
# printer_config = self.env['printer.configuration'].sudo().search([('model', '=', self._name)], limit=1)
|
|
# if not printer_config:
|
|
# raise UserError('请先配置打印机')
|
|
# host = printer_config.printer_id.ip_address
|
|
# port = printer_config.printer_id.port
|
|
# self.print_qr_code(maintenance_equipment_id, host, port)
|
|
|
|
# 切换成A4打印机
|
|
|
|
try:
|
|
self.env['jikimo.printing'].print_qr_code(self.MTcode)
|
|
except Exception as e:
|
|
raise UserError(f"打印失败: {str(e)}")
|
|
|
|
|
|
# def generate_zpl_code(self, code):
|
|
# """生成ZPL代码用于打印二维码标签
|
|
# Args:
|
|
# code: 需要编码的内容
|
|
# Returns:
|
|
# str: ZPL指令字符串
|
|
# """
|
|
# zpl_code = "^XA\n" # 开始ZPL格式
|
|
|
|
# # 设置打印参数
|
|
# zpl_code += "^LH0,0\n" # 设置标签起始位置
|
|
# zpl_code += "^CI28\n" # 设置中文编码
|
|
# zpl_code += "^PW400\n" # 设置打印宽度为400点
|
|
# zpl_code += "^LL300\n" # 设置标签长度为300点
|
|
|
|
# # 打印标题
|
|
# zpl_code += "^FO10,20\n" # 设置标题位置
|
|
# zpl_code += "^A0N,30,30\n" # 设置字体大小
|
|
# zpl_code += "^FD机床二维码^FS\n" # 打印标题文本
|
|
|
|
# # 打印二维码
|
|
# zpl_code += "^FO50,60\n" # 设置二维码位置
|
|
# zpl_code += f"^BQN,2,8\n" # 设置二维码参数:模式2,放大倍数8
|
|
# zpl_code += f"^FDLA,{code}^FS\n" # 二维码内容
|
|
|
|
# # 打印编码文本
|
|
# zpl_code += "^FO50,220\n" # 设置编码文本位置
|
|
# zpl_code += "^A0N,25,25\n" # 设置字体大小
|
|
# zpl_code += f"^FD编码: {code}^FS\n" # 打印编码文本
|
|
|
|
# # 打印日期
|
|
# zpl_code += "^FO50,260\n"
|
|
# zpl_code += "^A0N,20,20\n"
|
|
# zpl_code += f"^FD打印日期: {fields.Date.today()}^FS\n"
|
|
|
|
# zpl_code += "^PQ1\n" # 打印1份
|
|
# zpl_code += "^XZ\n" # 结束ZPL格式
|
|
|
|
# return zpl_code
|
|
|