Skip to content

Instantly share code, notes, and snippets.

@sehrishnaz
Created June 30, 2022 08:25
Show Gist options
  • Save sehrishnaz/048833f79e85ea4a3919f24c00988d83 to your computer and use it in GitHub Desktop.
Save sehrishnaz/048833f79e85ea4a3919f24c00988d83 to your computer and use it in GitHub Desktop.
How to Generate QR Code using Python and Odoo
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
@sehrishnaz
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment