From cf3ec1b6ae84923756ed899fc5b9c4d2a00035d4 Mon Sep 17 00:00:00 2001
From: yuxianghui <3437689193@qq.com>
Date: Tue, 20 Feb 2024 15:59:58 +0800
Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=BA=8F=E5=88=97=E5=8F=B7=E6=A8=A1?=
=?UTF-8?q?=E5=9E=8B=E6=B7=BB=E5=8A=A0=E4=BA=8C=E7=BB=B4=E7=A0=81=E5=AD=97?=
=?UTF-8?q?=E6=AE=B5=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E6=A0=B9?=
=?UTF-8?q?=E6=8D=AE=E5=BA=8F=E5=88=97=E5=8F=B7=E5=90=8D=E7=A7=B0=E7=94=9F?=
=?UTF-8?q?=E6=88=90=E4=BA=8C=E7=BB=B4=E7=A0=81=E7=9A=84=E5=8A=9F=E8=83=BD?=
=?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=89=93=E5=8D=B0=E4=BA=8C=E7=BB=B4?=
=?UTF-8?q?=E7=A0=81=E5=8A=9F=E8=83=BD=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_manufacturing/__manifest__.py | 1 +
sf_manufacturing/models/stock.py | 56 +++++++++++++++++++
sf_manufacturing/views/stock_lot_views.xml | 18 ++++++
.../models/maintenance_equipment.py | 31 ----------
.../views/tool_material_search.xml | 1 -
5 files changed, 75 insertions(+), 32 deletions(-)
create mode 100644 sf_manufacturing/views/stock_lot_views.xml
diff --git a/sf_manufacturing/__manifest__.py b/sf_manufacturing/__manifest__.py
index 3834e25f..6a122097 100644
--- a/sf_manufacturing/__manifest__.py
+++ b/sf_manufacturing/__manifest__.py
@@ -17,6 +17,7 @@
'security/ir.model.access.csv',
'wizard/workpiece_delivery_views.xml',
'views/mrp_views_menus.xml',
+ 'views/stock_lot_views.xml',
'views/mrp_production_addional_change.xml',
'views/mrp_routing_workcenter_view.xml',
'views/production_line_view.xml',
diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py
index f13abf6b..5cb51953 100644
--- a/sf_manufacturing/models/stock.py
+++ b/sf_manufacturing/models/stock.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import base64
+import qrcode
from collections import defaultdict, namedtuple
import logging
import json
@@ -12,6 +13,7 @@ from odoo.tools import float_compare
from odoo.addons.stock.models.stock_rule import ProcurementException
from odoo.addons.sf_base.commons.common import Common
from odoo.exceptions import UserError
+from io import BytesIO
class StockRule(models.Model):
@@ -264,6 +266,60 @@ class ProductionLot(models.Model):
return "%s-%s-%03d" % (product.cutting_tool_model_id.code, now, 1)
return "%s-%03d" % (product.name, 1)
+ qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')
+
+ @api.depends('name')
+ def _generate_qr_code(self):
+ for record in self:
+ # Generate QR code
+ qr = qrcode.QRCode(
+ version=1,
+ error_correction=qrcode.constants.ERROR_CORRECT_L,
+ box_size=10,
+ border=4,
+ )
+ qr.add_data(record.name)
+ qr.make(fit=True)
+ qr_image = qr.make_image(fill_color="black", back_color="white")
+
+ # Encode the image data in base64
+ image_stream = BytesIO()
+ qr_image.save(image_stream, format="PNG")
+ encoded_image = base64.b64encode(image_stream.getvalue())
+
+ record.qr_code_image = encoded_image
+
+ def print_qr_code(self):
+ 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):
_inherit = 'stock.picking'
diff --git a/sf_manufacturing/views/stock_lot_views.xml b/sf_manufacturing/views/stock_lot_views.xml
new file mode 100644
index 00000000..f637d401
--- /dev/null
+++ b/sf_manufacturing/views/stock_lot_views.xml
@@ -0,0 +1,18 @@
+
+
+
+ stock.lot.form.quality
+ stock.lot
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sf_tool_management/models/maintenance_equipment.py b/sf_tool_management/models/maintenance_equipment.py
index eb2f5990..4b5fe89e 100644
--- a/sf_tool_management/models/maintenance_equipment.py
+++ b/sf_tool_management/models/maintenance_equipment.py
@@ -1,8 +1,5 @@
-import qrcode
-import base64
from odoo import models, api, fields
from odoo.exceptions import ValidationError
-from io import BytesIO
class SfMaintenanceEquipmentTool(models.Model):
@@ -82,34 +79,6 @@ class StockLot(models.Model):
record.tool_material_search_id = tool_material_search
return records
- qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')
-
- @api.depends('name')
- def _generate_qr_code(self):
- for record in self:
- # Generate QR code
- qr = qrcode.QRCode(
- version=1,
- error_correction=qrcode.constants.ERROR_CORRECT_L,
- box_size=10,
- border=4,
- )
- qr.add_data(record.name)
- qr.make(fit=True)
-
- # Create an image from the QR Code instance
- qr_image = qr.make_image(fill_color="black", back_color="white")
-
- # Save the image to a BytesIO object
- image_stream = BytesIO()
- qr_image.save(image_stream, format="PNG")
-
- # Store the BytesIO object in the binary field
- record.qr_code_image = base64.b64decode(image_stream.getvalue())
- # record.qr_code_image = image_stream.getvalue()
-
- print(record.qr_code_image)
-
class ProductProduct(models.Model):
_inherit = 'product.product'
diff --git a/sf_tool_management/views/tool_material_search.xml b/sf_tool_management/views/tool_material_search.xml
index 85b3fd47..158e83b9 100644
--- a/sf_tool_management/views/tool_material_search.xml
+++ b/sf_tool_management/views/tool_material_search.xml
@@ -59,7 +59,6 @@
-