Odoo Help

5

0
1 Answer
5
Rafael Portilla United States
12/1/17, 7:45 AM

You can made your own module. I did, using qrcode library. https://pypi.python.org/pypi/qrcode


import qrcode

import base64

import cStringIO


class QrGenerator(osv.osv):

_inherit = 'product.template'

_columns = {

  'qr_product': fields.binary('QR Product'),

  'qr_product_name': fields.char(default="product_qr.png")

}


def generate_product_sku(self, cr, uid, ids, context=None):

  qr = qrcode.QRCode(

      version=1,

      error_correction=qrcode.constants.ERROR_CORRECT_L,

      box_size=20,

      border=4,

  )

  name = self.browse(cr, uid, ids, context).default_code+'_Product.png'

  qr.add_data(self.browse(cr, uid, ids, context).default_code) #you can put here any attribute SKU in my case

  qr.make(fit=True)

  img = qr.make_image()

  buffer = cStringIO.StringIO()

  img.save(buffer, format="PNG")

  img_str = base64.b64encode(buffer.getvalue())

  self.write(cr, uid, ids, {'qr_product': img_str,'qr_product_name':name})


#################################################################

for the new API just have to change some code (Note: I don't tested this code, but must work well ):


from openerp import models, fields, api
import qrcode
import base64
import cStringIO

class QrGenerator(models.Model):
    _inherit = 'product.template'

    qr_product = fields.Binary('QR Product')

    qr_product_name = fields.Char(default="product_qr.png")


    def generate_product_sku(self):    

        qr = qrcode.QRCode(version=1,error_correction=qrcode.constants.ERROR_CORRECT_L,box_size=20,border=4,)

        name = self.default_code+'_Product.png'

       qr.add_data(self.default_code) #you can put here any attribute SKU in my case

  qr.make(fit=True)

  img = qr.make_image()

        buffer = cStringIO.StringIO()

        img.save(buffer, format="PNG")

        img_str = base64.b64encode(buffer.getvalue())

        self.write({'qr_product': img_str,'qr_product_name':name})




1 Comment
Manish Kumar Bohra India
12/2/17, 12:25 AM

Hello,

You have any solution for new api odoov10 ?

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now