diff --git a/sf_base/__manifest__.py b/sf_base/__manifest__.py
index 59ad967a..ceedcdd0 100644
--- a/sf_base/__manifest__.py
+++ b/sf_base/__manifest__.py
@@ -24,6 +24,7 @@
'views/tool_menu.xml',
'views/menu_fixture_view.xml',
'views/change_base_view.xml',
+ 'views/Printer.xml',
],
'demo': [
diff --git a/sf_base/commons/Printer.py b/sf_base/commons/Printer.py
new file mode 100644
index 00000000..894a274c
--- /dev/null
+++ b/sf_base/commons/Printer.py
@@ -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='模型名称')
+ # 其他相关字段...
diff --git a/sf_base/commons/__init__.py b/sf_base/commons/__init__.py
index e4193cf0..63b820e7 100644
--- a/sf_base/commons/__init__.py
+++ b/sf_base/commons/__init__.py
@@ -1 +1,2 @@
from . import common
+from . import Printer
diff --git a/sf_base/commons/common.py b/sf_base/commons/common.py
index 683e8ece..9f359c9c 100644
--- a/sf_base/commons/common.py
+++ b/sf_base/commons/common.py
@@ -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}文本框周围绘制线框
diff --git a/sf_base/security/ir.model.access.csv b/sf_base/security/ir.model.access.csv
index 92bebe5b..81cec454 100644
--- a/sf_base/security/ir.model.access.csv
+++ b/sf_base/security/ir.model.access.csv
@@ -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
\ No newline at end of file
diff --git a/sf_base/views/Printer.xml b/sf_base/views/Printer.xml
new file mode 100644
index 00000000..97099f42
--- /dev/null
+++ b/sf_base/views/Printer.xml
@@ -0,0 +1,53 @@
+
+
+
+
+ printer.configuration.tree
+ printer.configuration
+
+
+
+
+
+
+
+
+
+
+
+
+
+ printer.configuration.form
+ printer.configuration
+
+
+
+
+
+
+
+
+
+ 打印配置
+ printer.configuration
+ tree,form
+
+
+
+
+
+
diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py
index c9c2ebf2..2b0066b6 100644
--- a/sf_manufacturing/models/stock.py
+++ b/sf_manufacturing/models/stock.py
@@ -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):
diff --git a/sf_manufacturing/views/stock_lot_views.xml b/sf_manufacturing/views/stock_lot_views.xml
index f637d401..bd04005c 100644
--- a/sf_manufacturing/views/stock_lot_views.xml
+++ b/sf_manufacturing/views/stock_lot_views.xml
@@ -10,7 +10,7 @@
diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py
index bdf4ce32..b9f048e8 100644
--- a/sf_warehouse/models/model.py
+++ b/sf_warehouse/models/model.py
@@ -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)