Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
30084 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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




Ảnh đại diện
Huỷ bỏ
Tác giả

Hello,

You have any solution for new api odoov10 ?

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 25
146
1
thg 11 16
4316
1
thg 3 15
5247
0
thg 12 24
3261
1
thg 3 21
6283