From 53e5aa2017dd0a5fbc1c5bceffdd01c441e909c2 Mon Sep 17 00:00:00 2001
From: yuxianghui <3437689193@qq.com>
Date: Tue, 20 Feb 2024 14:32:13 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=80=E5=85=B7?=
=?UTF-8?q?=E7=BB=84=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_base/models/tool_base_new.py | 11 +++++++----
sf_tool_management/controllers/controllers.py | 3 ++-
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/sf_base/models/tool_base_new.py b/sf_base/models/tool_base_new.py
index 8f3eb86f..6666132c 100644
--- a/sf_base/models/tool_base_new.py
+++ b/sf_base/models/tool_base_new.py
@@ -263,11 +263,14 @@ class ToolGroups(models.Model):
headers = Common.get_headers(obj, token, sf_secret_key)
strurl = sf_sync_config['sf_url'] + create_url
device_id = ''
- for equipment_id in obj.equipment_ids:
- device_id = '%s,%s' % (device_id, equipment_id.name)
+ name = None
+ if obj:
+ for equipment_id in obj.equipment_ids:
+ device_id = '%s,%s' % (device_id, equipment_id.name)
+ name = obj.name
val = {
'DeviceId': device_id,
- 'GroupName': obj.name,
+ 'GroupName': name,
}
kw = json.dumps(val, ensure_ascii=False)
r = requests.post(strurl, json={}, data={'kw': kw, 'token': token}, headers=headers)
@@ -279,7 +282,7 @@ class ToolGroups(models.Model):
# def write(self, vals):
# obj = super().write(vals)
- # self._register_tool_groups(obj)
+ # self._register_tool_groups(self)
# return obj
#
# @api.model_create_multi
diff --git a/sf_tool_management/controllers/controllers.py b/sf_tool_management/controllers/controllers.py
index 0e60a57f..becf79ec 100644
--- a/sf_tool_management/controllers/controllers.py
+++ b/sf_tool_management/controllers/controllers.py
@@ -12,7 +12,7 @@ class Manufacturing_Connect(http.Controller):
cors="*")
def get_equipment_tool_Info(self, **kw):
"""
- 机床当前刀库实时信息
+ 机床刀库实时信息
:param kw:
:return:
"""
@@ -31,6 +31,7 @@ class Manufacturing_Connect(http.Controller):
for equipment_tool_id in item.product_template_ids:
functional_tool_id = self.env['sf.functional.cutting.tool.entity'].sudo().search(
[('code', '=', equipment_tool_id.tool_code)])
+
alarm_time = None
if functional_tool_id.functional_tool_status == '报警':
alarm_time = self.env['sf.functional.tool.warning'].sudo().search(
From bb519b8ab892bbc8a64035dfb813af905c2e8b49 Mon Sep 17 00:00:00 2001
From: yuxianghui <3437689193@qq.com>
Date: Tue, 20 Feb 2024 14:35:28 +0800
Subject: [PATCH 2/3] =?UTF-8?q?1=E3=80=81=E5=BA=8F=E5=88=97=E5=8F=B7?=
=?UTF-8?q?=E6=A8=A1=E5=9E=8B=E8=87=AA=E5=8A=A8=E8=B7=9F=E5=85=B7=E5=BA=8F?=
=?UTF-8?q?=E5=88=97=E5=8F=B7=E5=90=8D=E7=A7=B0=E7=94=9F=E6=88=90=E4=BA=8C?=
=?UTF-8?q?=E7=BB=B4=E7=A0=81=EF=BC=88=E6=9C=AA=E5=AE=8C=E6=88=90=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../models/maintenance_equipment.py | 31 +++++++++++++++++++
.../views/tool_material_search.xml | 1 +
2 files changed, 32 insertions(+)
diff --git a/sf_tool_management/models/maintenance_equipment.py b/sf_tool_management/models/maintenance_equipment.py
index 4b5fe89e..eb2f5990 100644
--- a/sf_tool_management/models/maintenance_equipment.py
+++ b/sf_tool_management/models/maintenance_equipment.py
@@ -1,5 +1,8 @@
+import qrcode
+import base64
from odoo import models, api, fields
from odoo.exceptions import ValidationError
+from io import BytesIO
class SfMaintenanceEquipmentTool(models.Model):
@@ -79,6 +82,34 @@ 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 158e83b9..85b3fd47 100644
--- a/sf_tool_management/views/tool_material_search.xml
+++ b/sf_tool_management/views/tool_material_search.xml
@@ -59,6 +59,7 @@
+
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 3/3] =?UTF-8?q?1=E3=80=81=E5=BA=8F=E5=88=97=E5=8F=B7?=
=?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=B7=BB=E5=8A=A0=E4=BA=8C=E7=BB=B4=E7=A0=81?=
=?UTF-8?q?=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8?=
=?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=BA=8F=E5=88=97=E5=8F=B7=E5=90=8D=E7=A7=B0?=
=?UTF-8?q?=E7=94=9F=E6=88=90=E4=BA=8C=E7=BB=B4=E7=A0=81=E7=9A=84=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=89=93=E5=8D=B0=E4=BA=8C?=
=?UTF-8?q?=E7=BB=B4=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 @@
-