İçereği Atla
Menü
This question has been flagged
5 Cevaplar
2965 Görünümler

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
Vazgeç
Best Answer

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
Vazgeç
Best Answer


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
Vazgeç
Üretici

not working same result ...

Which version you are using?

Can you give me generate_ean method also?

Üretici

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

Related Posts Cevaplar Görünümler Aktivite
0
Nis 24
1309
0
Ara 19
4061
0
Ağu 19
4
5
Ağu 19
2241
1
Şub 19
6382