Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
30795 Vizualizări

Hi All,

I want to generate  QR code for Product information since i am unable to get the information of QR code generation in odoo.10 for any module..?Can anyone help me with my question.

Imagine profil
Abandonează
Cel mai bun răspuns

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})




Imagine profil
Abandonează
Autor

Hello,

You have any solution for new api odoov10 ?

Related Posts Răspunsuri Vizualizări Activitate
1
aug. 25
666
1
nov. 16
4695
1
mar. 15
5796
0
dec. 24
3747
1
mar. 21
6750