Reputation: 741
I'm using odoo 9 and i'm trying to install custom module named odoo_qr_code which allow to add qr code in products form and create qr image for products and products variants. But when i press save after adding my qr code in product forms it shows error. Any help please ?
File "D:\Projet_Odoo\odoo-9.0rc20180515\openerp\addons\odoo_qr_code\models\models.py", line 23, in _generate_qr_code
img.save(buffer, format="PNG")
TypeError: save() got an unexpected keyword argument 'format'
models.py
import base64
import cStringIO
import qrcode
from openerp import models, fields, api
class ProductTemplateQRCode(models.Model):
_inherit = 'product.template'
@api.multi
@api.depends('product_qr_code')
def _generate_qr_code(self):
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=20, border=4)
if self.product_qr_code:
name = self.product_qr_code + '_product.png'
qr.add_data(self.product_qr_code)
qr.make(fit=True)
img = qr.make_image()
buffer = cStringIO.StringIO()
img.save(buffer, format="PNG")
qrcode_img = base64.b64encode(buffer.getvalue())
self.update({'qr_code': qrcode_img, 'qr_code_name': name})
product_qr_code = fields.Char('QR Code')
qr_code = fields.Binary('QR Code', compute="_generate_qr_code")
qr_code_name = fields.Char(default="qr_code.png")
class ProductProductQRCode(models.Model):
_inherit = 'product.product'
@api.multi
@api.depends('product_qr_code')
def _generate_qr_code(self):
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=20, border=4)
if self.product_qr_code:
name = self.product_qr_code + '_product.png'
qr.add_data(self.product_qr_code)
qr.make(fit=True)
img = qr.make_image()
buffer = cStringIO.StringIO()
img.save(buffer, format="PNG")
qrcode_img = base64.b64encode(buffer.getvalue())
self.update({'qr_code': qrcode_img, 'qr_code_name': name})
Upvotes: 0
Views: 2758