1、序列号模型添加二维码字段,添加自动根据序列号名称生成二维码的功能,新增打印二维码功能;

This commit is contained in:
yuxianghui
2024-02-20 15:59:58 +08:00
parent bb519b8ab8
commit cf3ec1b6ae
5 changed files with 75 additions and 32 deletions

View File

@@ -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'

View File

@@ -59,7 +59,6 @@
<tree>
<field name="name"/>
<field name="tool_material_status"/>
<field name="qr_code_image" widget="image"/>
</tree>
</field>
</page>