From 50c147514ef9f1359e674a39fd70cf37d60ed2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Mon, 29 Jun 2015 14:59:02 +0200 Subject: [FIX] barcodes: correctly recompute the checksum of the product barcode when guessing it from a value encoding barcode --- addons/barcodes/static/src/js/barcode_parser.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'addons/barcodes/static/src/js/barcode_parser.js') diff --git a/addons/barcodes/static/src/js/barcode_parser.js b/addons/barcodes/static/src/js/barcode_parser.js index 55bedf95c38..681997249f6 100644 --- a/addons/barcodes/static/src/js/barcode_parser.js +++ b/addons/barcodes/static/src/js/barcode_parser.js @@ -119,7 +119,7 @@ openerp.barcodes = function(instance) { // - value: the numerical value encoded in the barcode (0 if no value encoded) // - base_code: the barcode in which numerical content is replaced by 0's // - match: boolean - match_pattern: function (barcode, pattern){ + match_pattern: function (barcode, pattern, encoding){ var match = { value: 0, base_code: barcode, @@ -153,6 +153,16 @@ openerp.barcodes = function(instance) { base_pattern += pattern.substr(num_start+num_length,pattern.length-1); match['base_code'] = match['base_code'].replace("\\\\", "\\").replace("\{", "{").replace("\}","}").replace("\.","."); + + var base_code = match.base_code.split('') + if (encoding === 'ean13') { + base_code[12] = '' + this.ean_checksum(match.base_code); + } else if (encoding === 'ean8') { + base_code[7] = '' + this.ean8_checksum(match.base_code); + } else if (encoding === 'upca') { + base_code[11] = '' + this.ean_checksum('0' + match.base_code); + } + match.base_code = base_code.join('') } if (base_pattern[0] !== '^') { @@ -208,7 +218,7 @@ openerp.barcodes = function(instance) { continue; } - var match = this.match_pattern(cur_barcode,rules[i].pattern); + var match = this.match_pattern(cur_barcode, rules[i].pattern, rule.encoding); if (match.match) { if(rules[i].type === 'alias') { barcode = rules[i].alias; -- cgit v1.2.3