diff --git a/product_barcode/__manifest__.py b/product_barcode/__manifest__.py index 1727e6f11..3cca3fd51 100644 --- a/product_barcode/__manifest__.py +++ b/product_barcode/__manifest__.py @@ -23,7 +23,7 @@ { 'name': 'Product Barcode Generator', - 'version': '12.0.1.0.0', + 'version': '12.0.1.0.1', 'summary': 'Generates EAN13 Standard Barcode for Product.', 'category': 'Inventory', 'author': 'Cybrosys Techno solutions', diff --git a/product_barcode/models/product_form.py b/product_barcode/models/product_form.py index 0d0283723..cc00ae676 100644 --- a/product_barcode/models/product_form.py +++ b/product_barcode/models/product_form.py @@ -2,12 +2,11 @@ import math import re - from odoo import api, models class ProductAutoBarcode(models.Model): - _inherit = "product.product" + _inherit = 'product.product' @api.model def create(self, vals): @@ -16,7 +15,14 @@ class ProductAutoBarcode(models.Model): res.barcode = ean return res + @api.multi + def write(self, values): + ean = generate_ean(str(self.product_tmpl_id.id)) + values['barcode'] = ean + return super(ProductAutoBarcode, self).write(values) + +@api.multi def ean_checksum(eancode): """returns the checksum of an ean string of length 13, returns -1 if the string has the wrong length""" @@ -64,3 +70,20 @@ def generate_ean(ean): return ean[:-1] + str(ean_checksum(ean)) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + + +class ProductAutoBarcodeInherit(models.Model): + _inherit = 'product.template' + + @api.model + def create(self, vals): + res = super(ProductAutoBarcodeInherit, self).create(vals) + ean = generate_ean(str(res.id)) + res.barcode = ean + return res + + @api.multi + def write(self, values): + ean = generate_ean(str(self.id)) + values['barcode'] = ean + return super(ProductAutoBarcodeInherit, self).write(values) \ No newline at end of file diff --git a/product_barcode/views/product_label.xml b/product_barcode/views/product_label.xml index 1fc485fe0..798263857 100644 --- a/product_barcode/views/product_label.xml +++ b/product_barcode/views/product_label.xml @@ -48,5 +48,4 @@ -