Accept Merge Request #2048: (feature/6694 -> develop)
Merge Request: 调整机台二维码使用A4打印机 Created By: @胡尧 Accepted By: @胡尧 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2048?initial=true
This commit is contained in:
2
jikimo_printing/__init__.py
Normal file
2
jikimo_printing/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import models
|
||||
18
jikimo_printing/__manifest__.py
Normal file
18
jikimo_printing/__manifest__.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
{
|
||||
'name': '机企猫 打印模块',
|
||||
'version': '1.0',
|
||||
'summary': """ 包含机台二维码,程序单打印等 """,
|
||||
'author': '机企猫',
|
||||
'website': 'https://www.jikimo.com',
|
||||
'category': '机企猫',
|
||||
'depends': ['sf_manufacturing', 'sf_maintenance', 'base_report_to_printer'],
|
||||
'data': [
|
||||
|
||||
],
|
||||
|
||||
'application': True,
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
'license': 'LGPL-3',
|
||||
}
|
||||
4
jikimo_printing/models/__init__.py
Normal file
4
jikimo_printing/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import maintenance_printing
|
||||
from . import workorder_printing
|
||||
|
||||
72
jikimo_printing/models/maintenance_printing.py
Normal file
72
jikimo_printing/models/maintenance_printing.py
Normal file
@@ -0,0 +1,72 @@
|
||||
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()
|
||||
qr_code_data = self.qr_code_image
|
||||
if not qr_code_data:
|
||||
raise UserError("没有找到二维码数据。")
|
||||
# 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打印机
|
||||
printer = self.env['printing.printer'].get_default()
|
||||
try:
|
||||
printer.print_document(report=None, content = qr_code_data)
|
||||
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
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
import logging
|
||||
from io import BytesIO
|
||||
from odoo import models, fields, api
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -17,6 +17,8 @@ class MainController(http.Controller):
|
||||
model_id = data.get('model_id')
|
||||
if not maintenance_equipment_id or not model_id:
|
||||
return {'code': 400, 'message': '参数错误'}
|
||||
if not isinstance(maintenance_equipment_id, int) and not isinstance(model_id, str):
|
||||
return {'code': 400, 'message': '参数类型错误'}
|
||||
maintenance_equipment = request.env['maintenance.equipment'].sudo().browse(int(maintenance_equipment_id))
|
||||
if not maintenance_equipment:
|
||||
return {'code': 400, 'message': '机台不存在,请扫描正确的机台二维码'}
|
||||
|
||||
@@ -36,8 +36,7 @@ class SfMaintenanceEquipmentAGVLog(models.Model):
|
||||
|
||||
|
||||
class SfMaintenanceEquipment(models.Model):
|
||||
_name = 'maintenance.equipment'
|
||||
_inherit = ['maintenance.equipment', 'printing.utils']
|
||||
_inherit = 'maintenance.equipment'
|
||||
_description = '设备'
|
||||
|
||||
crea_url = "/api/machine_tool/create"
|
||||
@@ -857,66 +856,6 @@ class SfMaintenanceEquipment(models.Model):
|
||||
|
||||
record.qr_code_image = encoded_image
|
||||
|
||||
def print_single_method(self):
|
||||
|
||||
print('self.name========== %s' % self.name)
|
||||
self.ensure_one()
|
||||
qr_code_data = self.qr_code_image
|
||||
if not qr_code_data:
|
||||
raise UserError("没有找到二维码数据。")
|
||||
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)
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
class SfRobotAxisNum(models.Model):
|
||||
_name = 'sf.robot.axis.num'
|
||||
|
||||
@@ -18,4 +18,3 @@ from . import quick_easy_order
|
||||
from . import purchase_order
|
||||
from . import quality_check
|
||||
from . import purchase_request_line
|
||||
from . import workorder_printer
|
||||
|
||||
Reference in New Issue
Block a user