Browse Source

[UPDT] Barcode generate duplicate issue

pull/298/head
Ajmal Cybro 4 years ago
parent
commit
30593622a6
  1. 2
      product_barcode/__manifest__.py
  2. 21
      product_barcode/models/product_form.py

2
product_barcode/__manifest__.py

@ -22,7 +22,7 @@
{
'name': 'Product Barcode Generator',
'version': '14.0.1.0.0',
'version': '14.0.2.0.0',
'summary': 'Generates EAN13 Standard Barcode for Product.',
'live_test_url': 'https://www.youtube.com/watch?v=0BrFcOEkWu4&feature=youtu.be',
'category': 'Inventory',

21
product_barcode/models/product_form.py

@ -31,7 +31,15 @@ class ProductAutoBarcode(models.Model):
@api.model
def create(self, vals):
res = super(ProductAutoBarcode, self).create(vals)
ean = generate_ean(str(res.id))
barcode_id = res.id
barcode_search = False
while not barcode_search:
ean = generate_ean(str(barcode_id))
if self.env['product.product'].search([('barcode', '=', ean)]):
barcode_search = False
barcode_id += 1
else:
barcode_search = True
res.barcode = ean
return res
@ -80,6 +88,7 @@ def generate_ean(ean):
ean = ean[:13]
if len(ean) < 13:
ean = ean + '0' * (13 - len(ean))
print("barcode : ", ean[:-1] + str(ean_checksum(ean)))
return ean[:-1] + str(ean_checksum(ean))
@ -89,7 +98,15 @@ class ProductTemplateAutoBarcode(models.Model):
@api.model
def create(self, vals_list):
templates = super(ProductTemplateAutoBarcode, self).create(vals_list)
ean = generate_ean(str(templates.id))
barcode_id = templates.id
barcode_search = False
while not barcode_search:
ean = generate_ean(str(barcode_id))
if self.env['product.product'].search([('barcode', '=', ean)]):
barcode_search = False
barcode_id += 1
else:
barcode_search = True
templates.barcode = ean
return templates

Loading…
Cancel
Save