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

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

@@ -24,6 +24,7 @@
'views/tool_menu.xml',
'views/menu_fixture_view.xml',
'views/change_base_view.xml',
'views/Printer.xml',
],
'demo': [

View File

@@ -0,0 +1,12 @@
from odoo import models, fields
class PrinterConfiguration(models.Model):
_name = 'printer.configuration'
_description = 'Printer Configuration'
name = fields.Char(string='名称', required=True)
ip_address = fields.Char(string='IP 地址', required=True)
port = fields.Integer(string='端口', default=9100)
model = fields.Many2one('ir.model', string='模型名称')
# 其他相关字段...

View File

@@ -1 +1,2 @@
from . import common
from . import Printer

View File

@@ -54,7 +54,7 @@ class PrintingUtils(models.AbstractModel):
# 假设{code}文本需要位于资产编号和二维码下方,中间位置
# 设置{code}文本位置并启用自动换行
zpl_code += "^FO300,120\n" # {code}文本的起始位置
zpl_code += "^FB500,4,0,L,0\n" # 定义一个宽度为500点的文本框最多4行左对齐
zpl_code += "^FB400,4,0,L,0\n" # 定义一个宽度为500点的文本框最多4行左对齐
zpl_code += f"^A1N,40,40^FD{code}^FS\n"
# 在{code}文本框周围绘制线框

View File

@@ -188,3 +188,6 @@ access_sf_machine_brand_tags_group_sale_director,sf_machine_brand_tags_group_sal
access_sf_machine_brand_tags_group_plan_director,sf_machine_brand_tags_group_plan_director,model_sf_machine_brand_tags,sf_base.group_plan_director,1,0,0,0
access_sf_machine_brand_tags_group_purchase,sf_machine_brand_tags_group_purchase,model_sf_machine_brand_tags,sf_base.group_purchase,1,0,0,0
access_sf_machine_brand_tags_group_purchase_director,sf_machine_brand_tags_group_purchase_director,model_sf_machine_brand_tags,sf_base.group_purchase_director,1,0,0,0
access_printer_configuration,printer.configuration,model_printer_configuration,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
188
189
190
191
192
193

53
sf_base/views/Printer.xml Normal file
View File

@@ -0,0 +1,53 @@
<odoo>
<data>
<record id="view_printer_configuration_tree" model="ir.ui.view">
<field name="name">printer.configuration.tree</field>
<field name="model">printer.configuration</field>
<field name="arch" type="xml">
<tree string="Printer Configuration">
<field name="name"/>
<field name="ip_address"/>
<field name="port"/>
<field name="model"/>
<!-- 其他字段... -->
</tree>
</field>
</record>
<record id="view_printer_configuration_form" model="ir.ui.view">
<field name="name">printer.configuration.form</field>
<field name="model">printer.configuration</field>
<field name="arch" type="xml">
<form string="Printer Configuration">
<sheet>
<group>
<field name="name"/>
<field name="ip_address"/>
<field name="port"/>
<field name="model"/>
<!-- 其他字段... -->
</group>
</sheet>
</form>
</field>
</record>
<!-- 其他视图... -->
<!-- Action to open the printer configuration list -->
<record id="action_printer_configuration" model="ir.actions.act_window">
<field name="name">打印配置</field>
<field name="res_model">printer.configuration</field>
<field name="view_mode">tree,form</field>
</record>
<!-- Add a menu item for the printer configuration -->
<record id="menu_printer_configuration" model="ir.ui.menu">
<field name="name">打印配置</field>
<field name="action" ref="action_printer_configuration"/>
<field name="parent_id" ref="base.menu_administration"/>
</record>
</data>
</odoo>

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):

View File

@@ -10,7 +10,7 @@
</xpath>
<xpath expr="//sheet" position="before">
<header>
<button string="打印二维码" name="print_qr_code" type="object" class="btn-primary"/>
<button string="打印二维码" name="print_single_method" type="object" class="btn-primary"/>
</header>
</xpath>
</field>

View File

@@ -471,8 +471,15 @@ class Sf_stock_move_line(models.Model):
if not qr_code_data:
raise UserError("没有找到二维码数据。")
lot_name = self.lot_name
host = "192.168.50.110" # 可以根据实际情况修改
port = 9100 # 可以根据实际情况修改
# host = "192.168.50.110" # 可以根据实际情况修改
# port = 9100 # 可以根据实际情况修改
# 获取默认打印机配置
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)
# 返回当前wizard页面
@@ -972,6 +979,11 @@ class CustomStockMove(models.Model):
# todo 待控制
if not lot_name:
raise ValidationError("请先分配序列号")
host = "192.168.50.110" # 可以根据实际情况修改
port = 9100 # 可以根据实际情况修改
# host = "192.168.50.110" # 可以根据实际情况修改
# port = 9100 # 可以根据实际情况修改
# 获取默认打印机配置
printer_config = self.env['printer.configuration'].search([('model', '=', self._name)], limit=1)
host = printer_config.ip_address
port = printer_config.port
record.print_qr_code(lot_name, host, port)