diff --git a/beesdoo_product/__openerp__.py b/beesdoo_product/__openerp__.py index c7728aa..dfee764 100644 --- a/beesdoo_product/__openerp__.py +++ b/beesdoo_product/__openerp__.py @@ -25,6 +25,7 @@ # always loaded 'data': [ 'data/product_label.xml', + 'data/barcode_rule.xml', 'views/beesdoo_product.xml', 'wizard/views/label_printing_utils.xml', 'security/ir.model.access.csv', diff --git a/beesdoo_product/data/barcode_rule.xml b/beesdoo_product/data/barcode_rule.xml new file mode 100644 index 0000000..2c32b2a --- /dev/null +++ b/beesdoo_product/data/barcode_rule.xml @@ -0,0 +1,13 @@ + + + + + Beescoop Product Barcodes + 1 + product + 043 + 45 + ean13 + + + \ No newline at end of file diff --git a/beesdoo_product/models/beesdoo_product.py b/beesdoo_product/models/beesdoo_product.py index 7f8177d..d0cebd8 100644 --- a/beesdoo_product/models/beesdoo_product.py +++ b/beesdoo_product/models/beesdoo_product.py @@ -2,6 +2,7 @@ from openerp import models, fields, api from openerp.tools.translate import _ from openerp.exceptions import UserError +import uuid class BeesdooProduct(models.Model): _inherit = "product.template" @@ -26,6 +27,20 @@ class BeesdooProduct(models.Model): note = fields.Text('Comments') + @api.one + def generate_barcode(self): + print 'generate barcode', self.barcode, self.barcode == '' + rule = self.env['barcode.rule'].search([('name', '=', 'Beescoop Product Barcodes')])[0] + size = 13 - len(rule.pattern) + ean = rule.pattern + str(uuid.uuid4().fields[-1])[:size] + bc = ean[0:12] + str(self.env['barcode.nomenclature'].ean_checksum(ean)) + # Make sure there is no other active member with the same barcode + while(self.search_count([('barcode', '=', bc)]) > 1): + ean = rule.pattern + str(uuid.uuid4().fields[-1])[:size] + bc = ean[0:12] + str(self.env['barcode.nomenclature'].ean_checksum(ean)) + print 'barcode :', bc + self.barcode = bc + @api.one @api.depends('seller_ids', 'seller_ids.date_start') def _compute_main_seller_id(self): diff --git a/beesdoo_product/views/beesdoo_product.xml b/beesdoo_product/views/beesdoo_product.xml index 36761ef..bb72b21 100644 --- a/beesdoo_product/views/beesdoo_product.xml +++ b/beesdoo_product/views/beesdoo_product.xml @@ -1,12 +1,14 @@ - bees.product.template.form product.template + +