Accept Merge Request #814: (feature/序列号添加二维码 -> develop)
Merge Request: 序列号模型添加二维码字段,添加自动根据序列号名称生成二维码的功能,新增打印二维码功能; Created By: @禹翔辉 Reviewed By: @马广威 Approved By: @马广威 Accepted By: @禹翔辉 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/814?initial=true
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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'
|
||||
|
||||
18
sf_manufacturing/views/stock_lot_views.xml
Normal file
18
sf_manufacturing/views/stock_lot_views.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="stock_production_lot_form_generate_qr_code" model="ir.ui.view">
|
||||
<field name="name">stock.lot.form.quality</field>
|
||||
<field name="model">stock.lot</field>
|
||||
<field name="inherit_id" ref="stock.view_production_lot_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//form//sheet//group//group[2]" position="inside">
|
||||
<field name="qr_code_image" widget="image"/>
|
||||
</xpath>
|
||||
<xpath expr="//sheet" position="before">
|
||||
<header>
|
||||
<button string="打印二维码" name="print_qr_code" type="object" class="btn-primary"/>
|
||||
</header>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user