تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
30786 أدوات العرض

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.

الصورة الرمزية
إهمال
أفضل إجابة

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




الصورة الرمزية
إهمال
الكاتب

Hello,

You have any solution for new api odoov10 ?

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أغسطس 25
665
1
نوفمبر 16
4691
1
مارس 15
5795
0
ديسمبر 24
3744
1
مارس 21
6738