Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
5 Replies
3741 Tampilan

class ProductAutoBarcode(models.Model): 

 _inherit = 'product.product'

@api.model 

def create(self, vals): 

res = super(ProductAutoBarcode, self).create(vals) 

ean = generate_ean(str(res.id))
res.barcode = ean 

 return res

note

on print its give me value on every time when product created --------------------->ean 

1 - this code is not working on first time when i create product with variants

when it work.

when i create product without variants and save button press then its giving me value else empty  


Error

Code

Avatar
Buang
Jawaban Terbai

Hi Usman,

To generate barcode, qrcode or any code in odoo, odoo provides default feature to do this.

There is one controller which will generate barcode. So what you need to do is, you need to call that controller from your create method.

Just search, controller "/report/barcode"


I hope it will useful for you.


Regards

Haresh Kansara



Avatar
Buang
Jawaban Terbai


class ProductAutoBarcode(models.Model): 

 _inherit = 'product.product'

 @api.model 

 def create(self, vals): 

  ean = generate_ean(str(res.id))

  vals.update({'barcode': ean})

  return super(ProductAutoBarcode, self).create(vals) 

Avatar
Buang
Penulis

not working same result ...

Which version you are using?

Can you give me generate_ean method also?

Penulis

v 13

def generate_ean(ean):

"""Creates and returns a valid ean13 from an invalid one"""

if not ean:

return

ean = re.sub("[A-Za-z]", "0", ean)

ean = re.sub("[^0-9]", "", ean)

ean = ean[:13]

if len(ean) < 13:

ean = ean + '0' * (13 - len(ean))

return ean[:-1] + str(ean_checksum(ean))

Post Terkait Replies Tampilan Aktivitas
0
Apr 24
1939
0
Des 19
4635
0
Agu 19
4
5
Agu 19
2806
1
Feb 19
6977