打印配置初步优化并测试成功,自测流程成功

This commit is contained in:
mgw
2024-03-20 16:58:57 +08:00
parent 2407d2cfc7
commit c788392b36
9 changed files with 133 additions and 33 deletions

View File

@@ -219,7 +219,8 @@ class StockRule(models.Model):
class ProductionLot(models.Model):
_inherit = 'stock.lot'
_name = 'stock.lot'
_inherit = ['stock.lot', 'printing.utils']
@api.model
def generate_lot_names1(self, display_name, first_lot, count):
@@ -307,36 +308,53 @@ class ProductionLot(models.Model):
record.qr_code_image = encoded_image
def print_qr_code(self):
self.ensure_one() # 确保这个方法只为一个记录调用
# if not self.lot_id:
# raise UserError("没有找到序列号。")
# 假设_lot_qr_code方法已经生成了二维码并保存在字段中
def print_single_method(self):
self.ensure_one()
qr_code_data = self.qr_code_image
if not qr_code_data:
raise UserError("没有找到二维码数据。")
lot_name = self.name
# host = "192.168.50.110" # 可以根据实际情况修改
# port = 9100 # 可以根据实际情况修改
# 生成下载链接或直接触发下载
# 此处的实现依赖于你的具体需求,以下是触发下载的一种示例
attachment = self.env['ir.attachment'].sudo().create({
'datas': self.qr_code_image,
'type': 'binary',
'description': '二维码图片',
'name': self.name + '.png',
# 'res_id': invoice.id,
# 'res_model': 'stock.picking',
'public': True,
'mimetype': 'application/x-png',
# 'model_name': 'stock.picking',
})
# 返回附件的下载链接
download_url = '/web/content/%s?download=true' % attachment.id
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
return {
'type': 'ir.actions.act_url',
'url': str(base_url) + download_url,
'target': 'self',
}
# 获取默认打印机配置
printer_config = self.env['printer.configuration'].search([('model', '=', self._name)], limit=1)
if not printer_config:
raise UserError('请先配置打印机')
host = printer_config.ip_address
port = printer_config.port
self.print_qr_code(lot_name, host, port)
# self.ensure_one() # 确保这个方法只为一个记录调用
# # if not self.lot_id:
# # raise UserError("没有找到序列号。")
# # 假设_lot_qr_code方法已经生成了二维码并保存在字段中
# qr_code_data = self.qr_code_image
# if not qr_code_data:
# raise UserError("没有找到二维码数据。")
#
# # 生成下载链接或直接触发下载
# # 此处的实现依赖于你的具体需求,以下是触发下载的一种示例
# attachment = self.env['ir.attachment'].sudo().create({
# 'datas': self.qr_code_image,
# 'type': 'binary',
# 'description': '二维码图片',
# 'name': self.name + '.png',
# # 'res_id': invoice.id,
# # 'res_model': 'stock.picking',
# 'public': True,
# 'mimetype': 'application/x-png',
# # 'model_name': 'stock.picking',
# })
# # 返回附件的下载链接
# download_url = '/web/content/%s?download=true' % attachment.id
# base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
# return {
# 'type': 'ir.actions.act_url',
# 'url': str(base_url) + download_url,
# 'target': 'self',
# }
class StockPicking(models.Model):