Created
June 30, 2022 08:25
-
-
Save sehrishnaz/048833f79e85ea4a3919f24c00988d83 to your computer and use it in GitHub Desktop.
How to Generate QR Code using Python and Odoo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class res_company(models.Model): | |
_inherit = 'res.company' | |
@api.multi | |
def generate_qr(self, txt=''): | |
qr_code = qrcode.QRCode(version=4, box_size=4, border=1) | |
qr_code.add_data(txt) | |
qr_code.make(fit=True) | |
qr_img = qr_code.make_image() | |
im = qr_img._img.convert("RGB") | |
buffered = BytesIO() | |
im.save(buffered, format="JPEG") | |
img_str = base64.b64encode(buffered.getvalue()).decode('ascii') | |
return img_str | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to Generate QR Code using Python and Odoo