Bài học

Bài học thuộc : Odoo tip Trạng thái bài học : Chưa hoàn thành

How to Generate QR Code in Odoo 13

We were first introduced to Quick Response Code or the QR code in the mid-1990s in Japan. QR code is nothing but a two-dimensional barcode or a matrix barcode. The data can be embedded in the QR code using four standardized encoding modes (numeric, alphanumeric, byte/binary, and kanji).

The QR code quickly gained popularity among mass for its faster readability and greater storage capacity. It can be used for product tracking, item identification, time tracking, document managing, and general marketing.

Now let’s see how to generate a QR code for a product in Odoo. Here we are generating the QR code based on the internal reference of the product. More information on the product can be added to the QR code.

PYTHON CODE:

import qrcode
import base64
from io import BytesIO
from odoo import models, fields, api
class ProductQR(models.Model):
    _inherit = "product.template"
    qr_code = fields.Binary("QR Code", attachment=True, store=True)
    @api.onchange('default_code')
    def generate_qr_code(self):
        qr = qrcode.QRCode(
            version=1,
            error_correction=qrcode.constants.ERROR_CORRECT_L,
            box_size=10,
            border=4,
        )
        qr.add_data(self.default_code)
        qr.make(fit=True)
        img = qr.make_image()
        temp = BytesIO()
        img.save(temp, format="PNG")
        qr_image = base64.b64encode(temp.getvalue())
        self.qr_code = qr_image

There is a python library that helps in the generation of QR code image called “QRcode”.

https://www.cybrosys.com/blog/generate-qr-code-in-odoo-13


Tags:


Gắn sao :  

Tác giả : admin admin

`
×