调整打印机模型结构
This commit is contained in:
@@ -1,12 +1,28 @@
|
|||||||
from odoo import models, fields
|
from odoo import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
class Printer(models.Model):
|
||||||
|
_name = 'printer'
|
||||||
|
_description = 'Printer'
|
||||||
|
|
||||||
|
name = fields.Char(string='名称', required=True)
|
||||||
|
ip_address = fields.Char(string='IP 地址', required=True)
|
||||||
|
port = fields.Integer(string='端口', default=9100)
|
||||||
|
|
||||||
|
|
||||||
|
class TableStyle(models.Model):
|
||||||
|
_name = 'table.style'
|
||||||
|
_description = '标签样式'
|
||||||
|
|
||||||
|
name = fields.Char(string='名称', required=True)
|
||||||
|
# todo
|
||||||
|
|
||||||
|
|
||||||
class PrinterConfiguration(models.Model):
|
class PrinterConfiguration(models.Model):
|
||||||
_name = 'printer.configuration'
|
_name = 'printer.configuration'
|
||||||
_description = 'Printer Configuration'
|
_description = 'Printer Configuration'
|
||||||
|
|
||||||
name = fields.Char(string='名称', required=True)
|
name = fields.Char(string='名称', required=True)
|
||||||
ip_address = fields.Char(string='IP 地址', required=True)
|
printer_id = fields.Many2one('printer', string='打印机')
|
||||||
port = fields.Integer(string='端口', default=9100)
|
|
||||||
model = fields.Many2one('ir.model', string='模型名称')
|
model = fields.Many2one('ir.model', string='模型名称')
|
||||||
# 其他相关字段...
|
# # 其他相关字段...
|
||||||
|
|||||||
@@ -190,4 +190,5 @@ access_sf_machine_brand_tags_group_purchase,sf_machine_brand_tags_group_purchase
|
|||||||
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_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,printer,model_printer,base.group_user,1,1,1,1
|
||||||
access_printer_configuration,printer.configuration,model_printer_configuration,base.group_user,1,1,1,1
|
access_printer_configuration,printer.configuration,model_printer_configuration,base.group_user,1,1,1,1
|
||||||
|
@@ -1,17 +1,44 @@
|
|||||||
<odoo>
|
<odoo>
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
|
<record id="view_printer_tree" model="ir.ui.view">
|
||||||
|
<field name="name">printer.tree</field>
|
||||||
|
<field name="model">printer</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="Printer">
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="ip_address"/>
|
||||||
|
<field name="port"/>
|
||||||
|
<!-- 其他字段... -->
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_printer_form" model="ir.ui.view">
|
||||||
|
<field name="name">printer.form</field>
|
||||||
|
<field name="model">printer</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Printer">
|
||||||
|
<sheet>
|
||||||
|
<group>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="ip_address"/>
|
||||||
|
<field name="port"/>
|
||||||
|
</group>
|
||||||
|
</sheet>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
<record id="view_printer_configuration_tree" model="ir.ui.view">
|
<record id="view_printer_configuration_tree" model="ir.ui.view">
|
||||||
<field name="name">printer.configuration.tree</field>
|
<field name="name">printer.configuration.tree</field>
|
||||||
<field name="model">printer.configuration</field>
|
<field name="model">printer.configuration</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Printer Configuration">
|
<tree string="Printer Configuration">
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="ip_address"/>
|
<field name="printer_id"/>
|
||||||
<field name="port"/>
|
<field name="model"/>
|
||||||
<field name="model"/>
|
<!-- 其他字段... -->
|
||||||
<!-- 其他字段... -->
|
|
||||||
|
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
@@ -24,8 +51,7 @@
|
|||||||
<sheet>
|
<sheet>
|
||||||
<group>
|
<group>
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="ip_address"/>
|
<field name="printer_id"/>
|
||||||
<field name="port"/>
|
|
||||||
<field name="model"/>
|
<field name="model"/>
|
||||||
<!-- 其他字段... -->
|
<!-- 其他字段... -->
|
||||||
</group>
|
</group>
|
||||||
@@ -36,6 +62,12 @@
|
|||||||
|
|
||||||
<!-- 其他视图... -->
|
<!-- 其他视图... -->
|
||||||
|
|
||||||
|
<record id="action_printer" model="ir.actions.act_window">
|
||||||
|
<field name="name">打印机</field>
|
||||||
|
<field name="res_model">printer</field>
|
||||||
|
<field name="view_mode">tree,form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
<!-- Action to open the printer configuration list -->
|
<!-- Action to open the printer configuration list -->
|
||||||
<record id="action_printer_configuration" model="ir.actions.act_window">
|
<record id="action_printer_configuration" model="ir.actions.act_window">
|
||||||
<field name="name">打印配置</field>
|
<field name="name">打印配置</field>
|
||||||
@@ -44,10 +76,37 @@
|
|||||||
</record>
|
</record>
|
||||||
|
|
||||||
<!-- Add a menu item for the printer configuration -->
|
<!-- Add a menu item for the printer configuration -->
|
||||||
<record id="menu_printer_configuration" model="ir.ui.menu">
|
<!-- <record id="menu_printer_configuration" model="ir.ui.menu"> -->
|
||||||
<field name="name">打印配置</field>
|
<!-- <field name="name">打印配置</field> -->
|
||||||
<field name="action" ref="action_printer_configuration"/>
|
<!-- <field name="action" ref="action_printer_configuration"/> -->
|
||||||
<field name="parent_id" ref="base.menu_administration"/>
|
<!-- <field name="parent_id" ref="base.menu_administration"/> -->
|
||||||
</record>
|
<!-- </record> -->
|
||||||
|
|
||||||
|
<!-- <record id="menu_printer" model="ir.ui.menu"> -->
|
||||||
|
<!-- <field name="name">打印机</field> -->
|
||||||
|
<!-- <field name="action" ref="action_printer"/> -->
|
||||||
|
<!-- <field name="parent_id" ref="menu_printer"/> -->
|
||||||
|
<!-- </record> -->
|
||||||
|
|
||||||
|
<menuitem
|
||||||
|
id="printer_main_menu"
|
||||||
|
name="打印配置"
|
||||||
|
sequence="10"
|
||||||
|
parent="base.menu_administration"/>
|
||||||
|
|
||||||
|
<menuitem
|
||||||
|
id="menu_printer"
|
||||||
|
name="打印机"
|
||||||
|
action="action_printer"
|
||||||
|
sequence="1"
|
||||||
|
parent="printer_main_menu"/>
|
||||||
|
|
||||||
|
<menuitem
|
||||||
|
id="menu_printer_configuration"
|
||||||
|
name="打印配置"
|
||||||
|
action="action_printer_configuration"
|
||||||
|
sequence="2"
|
||||||
|
parent="printer_main_menu"/>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
@@ -322,8 +322,8 @@ class ProductionLot(models.Model):
|
|||||||
printer_config = self.env['printer.configuration'].search([('model', '=', self._name)], limit=1)
|
printer_config = self.env['printer.configuration'].search([('model', '=', self._name)], limit=1)
|
||||||
if not printer_config:
|
if not printer_config:
|
||||||
raise UserError('请先配置打印机')
|
raise UserError('请先配置打印机')
|
||||||
host = printer_config.ip_address
|
host = printer_config.printer_id.ip_address
|
||||||
port = printer_config.port
|
port = printer_config.printer_id.port
|
||||||
self.print_qr_code(lot_name, host, port)
|
self.print_qr_code(lot_name, host, port)
|
||||||
|
|
||||||
# self.ensure_one() # 确保这个方法只为一个记录调用
|
# self.ensure_one() # 确保这个方法只为一个记录调用
|
||||||
|
|||||||
@@ -478,8 +478,8 @@ class Sf_stock_move_line(models.Model):
|
|||||||
printer_config = self.env['printer.configuration'].search([('model', '=', self._name)], limit=1)
|
printer_config = self.env['printer.configuration'].search([('model', '=', self._name)], limit=1)
|
||||||
if not printer_config:
|
if not printer_config:
|
||||||
raise UserError('请先配置打印机')
|
raise UserError('请先配置打印机')
|
||||||
host = printer_config.ip_address
|
host = printer_config.printer_id.ip_address
|
||||||
port = printer_config.port
|
port = printer_config.printer_id.port
|
||||||
self.print_qr_code(lot_name, host, port)
|
self.print_qr_code(lot_name, host, port)
|
||||||
|
|
||||||
# 返回当前wizard页面
|
# 返回当前wizard页面
|
||||||
@@ -984,6 +984,8 @@ class CustomStockMove(models.Model):
|
|||||||
|
|
||||||
# 获取默认打印机配置
|
# 获取默认打印机配置
|
||||||
printer_config = self.env['printer.configuration'].search([('model', '=', self._name)], limit=1)
|
printer_config = self.env['printer.configuration'].search([('model', '=', self._name)], limit=1)
|
||||||
host = printer_config.ip_address
|
if not printer_config:
|
||||||
port = printer_config.port
|
raise UserError('请先配置打印机')
|
||||||
|
host = printer_config.printer_id.ip_address
|
||||||
|
port = printer_config.printer_id.port
|
||||||
record.print_qr_code(lot_name, host, port)
|
record.print_qr_code(lot_name, host, port)
|
||||||
|
|||||||
Reference in New Issue
Block a user