调整打印机模型结构
This commit is contained in:
@@ -1,12 +1,28 @@
|
||||
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):
|
||||
_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)
|
||||
printer_id = fields.Many2one('printer', 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_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
|
||||
|
@@ -1,17 +1,44 @@
|
||||
<odoo>
|
||||
<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">
|
||||
<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"/>
|
||||
<!-- 其他字段... -->
|
||||
|
||||
<field name="name"/>
|
||||
<field name="printer_id"/>
|
||||
<field name="model"/>
|
||||
<!-- 其他字段... -->
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -24,8 +51,7 @@
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="ip_address"/>
|
||||
<field name="port"/>
|
||||
<field name="printer_id"/>
|
||||
<field name="model"/>
|
||||
<!-- 其他字段... -->
|
||||
</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 -->
|
||||
<record id="action_printer_configuration" model="ir.actions.act_window">
|
||||
<field name="name">打印配置</field>
|
||||
@@ -44,10 +76,37 @@
|
||||
</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>
|
||||
<!-- <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> -->
|
||||
|
||||
<!-- <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>
|
||||
</odoo>
|
||||
|
||||
@@ -322,8 +322,8 @@ class ProductionLot(models.Model):
|
||||
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
|
||||
host = printer_config.printer_id.ip_address
|
||||
port = printer_config.printer_id.port
|
||||
self.print_qr_code(lot_name, host, port)
|
||||
|
||||
# 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)
|
||||
if not printer_config:
|
||||
raise UserError('请先配置打印机')
|
||||
host = printer_config.ip_address
|
||||
port = printer_config.port
|
||||
host = printer_config.printer_id.ip_address
|
||||
port = printer_config.printer_id.port
|
||||
self.print_qr_code(lot_name, host, port)
|
||||
|
||||
# 返回当前wizard页面
|
||||
@@ -984,6 +984,8 @@ class CustomStockMove(models.Model):
|
||||
|
||||
# 获取默认打印机配置
|
||||
printer_config = self.env['printer.configuration'].search([('model', '=', self._name)], limit=1)
|
||||
host = printer_config.ip_address
|
||||
port = printer_config.port
|
||||
if not printer_config:
|
||||
raise UserError('请先配置打印机')
|
||||
host = printer_config.printer_id.ip_address
|
||||
port = printer_config.printer_id.port
|
||||
record.print_qr_code(lot_name, host, port)
|
||||
|
||||
Reference in New Issue
Block a user