diff options
| author | Frédéric van der Essen <fvdessen@gmail.com> | 2015-06-29 14:59:02 +0200 |
|---|---|---|
| committer | Frédéric van der Essen <fvdessen@gmail.com> | 2015-06-29 15:43:15 +0200 |
| commit | 50c147514ef9f1359e674a39fd70cf37d60ed2a8 (patch) | |
| tree | 76ca574e390cad6acff742007f86a1143a57a952 /addons | |
| parent | 125ec28e71ea110ce574852c7f073a1d81fa26e9 (diff) | |
[FIX] barcodes: correctly recompute the checksum of the product barcode when guessing it from a value encoding barcode
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_parser.js | 14 |
1 files changed, 12 insertions, 2 deletions
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; |
