1、序列号模型自动跟具序列号名称生成二维码(未完成)

This commit is contained in:
yuxianghui
2024-02-20 14:35:28 +08:00
parent 53e5aa2017
commit bb519b8ab8
2 changed files with 32 additions and 0 deletions

View File

@@ -1,5 +1,8 @@
import qrcode
import base64
from odoo import models, api, fields from odoo import models, api, fields
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from io import BytesIO
class SfMaintenanceEquipmentTool(models.Model): class SfMaintenanceEquipmentTool(models.Model):
@@ -79,6 +82,34 @@ class StockLot(models.Model):
record.tool_material_search_id = tool_material_search record.tool_material_search_id = tool_material_search
return records 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): class ProductProduct(models.Model):
_inherit = 'product.product' _inherit = 'product.product'

View File

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