--- product-old.py 2013-09-09 16:11:02.000000000 -0700 +++ product.py 2014-02-21 16:07:02.000000000 -0800 @@ -32,12 +32,15 @@ def ean_checksum(eancode): """returns the checksum of an ean string of length 13, returns -1 if the string has the wrong length""" - if len(eancode) <> 13: + if len(eancode) < 12 or len(eancode) > 13: return -1 oddsum=0 evensum=0 total=0 - eanvalue=eancode + if len(eancode) == 13: + eanvalue = eancode + else: + eanvalue = '0'+eancode reversevalue = eanvalue[::-1] finalean=reversevalue[1:] @@ -55,7 +58,7 @@ """returns True if eancode is a valid ean13 string, or null""" if not eancode: return True - if len(eancode) <> 13: + if len(eancode) < 12 or len(eancode) > 13: return False try: int(eancode) @@ -554,7 +557,7 @@ 'active': fields.boolean('Active', help="If unchecked, it will allow you to hide the product without removing it."), 'variants': fields.char('Variants', size=64), 'product_tmpl_id': fields.many2one('product.template', 'Product Template', required=True, ondelete="cascade", select=True), - 'ean13': fields.char('EAN13 Barcode', size=13, help="International Article Number used for product identification."), + 'ean13': fields.char('UPC-A/EAN13 Barcode', size=13, help="International Article Number used for product identification."), 'packaging' : fields.one2many('product.packaging', 'product_id', 'Logistical Units', help="Gives the different ways to package the same product. This has no impact on the picking order and is mainly used if you use the EDI module."), 'price_extra': fields.float('Variant Price Extra', digits_compute=dp.get_precision('Product Price')), 'price_margin': fields.float('Variant Price Margin', digits_compute=dp.get_precision('Product Price')), @@ -819,7 +822,11 @@ def checksum(ean): salt = '31' * 6 + '3' sum = 0 - for ean_part, salt_part in zip(ean, salt): + if len(ean) == 13: + eanc = ean + else: + eanc = '0'+ean + for ean_part, salt_part in zip(eanc, salt): sum += int(ean_part) * int(salt_part) return (10 - (sum % 10)) % 10 checksum = staticmethod(checksum)