This article will teach you how to create and generate QR codes in Odoo using Python for QWEB Custom Reports. After generating the QR code we will redirect to the given URL.
What is QR code and why do we need this in reporting
It's machine-readable code with a mix of patterns, URLs, and numbers. In Odoo we can use these QR codes in QWEB reporting. This article will provide an insight into how to generate QR codes with URLs, for QWEB reports in the Odoo platform.
Read More: How to Create Custom Report in QWEB
Odoo supports any string in QR code so you can provide any string or number or URL as a pattern to generate the QR code. In this article, I am going to show you two methods to create QR codes for your QWEB Reports.
Read More: How to Add Custom Header and Footer in QWEB Report in Odoo
How to Generate QR Code using Python and Odoo (Method 1)
To generate QR codes using python we need to install the following python packages.
- import base64
- import qrcode
- from io import BytesIO
To install python packages using the below command.
py -m pip install qrcode
Similarly, just change the name of the package and install your desired python module/library. Now create a function inside any Odoo model, I am going to use 'res.company' model.
Read More: How to Link Custom Paper Format in QWEB Report in Odoo
How to put URL inside QR Code in odoo
base64_qr = self.env['res.company'].generate_qr(base_url)
<div class="col-xs-6 mt6"><img t-if="qr" t-att-src="'data:image/png;base64,%s' % base64_qr" style="max-height: 100px;"/></div>
How to Generate QR Code using Python and Odoo (Method 2)
Read More: How to Add Page Number in QWEB Report
<div><img t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('QR', 'redirect_url_goes_here', 200, 200)"/></div>
0 Comments