# -*- coding: utf-8 -*-
import qrcode
# odoo create
@api.model
def create(self, vals):
result = super(odoo, self).create(vals)
#
img_file = create_qrcode(result.code)
result.qrcode_file = base64.encodestring(img_file)
return result
# code
def create_qrcode(code):
#
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(code)
qr.make(fit=True)
img = qr.make_image()
#
img.save('D:\\test.png')
img_file = open('D:\\test.png', 'rb').read()
return img_file