コンテンツへスキップ
メニュー
この質問にフラグが付けられました
5 返信
2968 ビュー

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

アバター
破棄
最善の回答

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



アバター
破棄
最善の回答


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) 

アバター
破棄
著作者

not working same result ...

Which version you are using?

Can you give me generate_ean method also?

著作者

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

関連投稿 返信 ビュー 活動
0
4月 24
1309
0
12月 19
4061
0
8月 19
4
5
8月 19
2243
1
2月 19
6383