From b6fa154cbc153aef1db14cc44c5ecc15443a7b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Tue, 27 Mar 2012 10:25:45 +0200 Subject: [PATCH] [imp] add control digit bzr revid: rlo@openerp.com-20120327082545-y3fzc2rysefx0k2q --- addons/point_of_sale/static/src/js/pos.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 369c7fbc032..ecaecdf91d5 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -1281,7 +1281,28 @@ openerp.point_of_sale = function(db) { console.log('barcode: ' + barcode); var selectedOrder = self.shop.get('selectedOrder'); var productsCollection = self.shop.get('products'); - var controlDigit = Number(barcode.charAt(12)); + // EAN digit control calculation, based on http://es.wikipedia.org/wiki/EAN#Javascript , licensed under Creative Commons Attribution-Share-Alike License 3.0 + var checksum = 0; + ean13Reversed = codeNumbers.reverse(); + for (var pos in ean13Reversed) { + checksum += ean13Reversed[pos] * (3 - 2 * (pos % 2)); + } + checksum = (10 - (checksum % 10)) % 10; + // End of EAN digit control calculation + if (Number(barcode.charAt(12)) !== checksum) { + // barcode read error, raise warning + $(QWeb.render('pos-scan-warning')).dialog({ + resizable: false, + height:220, + modal: true, + title: "Warning", + buttons: { + "OK": function() { + $( this ).dialog( "close" ); + }, + } + }); + } if (barcode.substring(0,2) in ['02', '22', '24', '26', '28']) { // product with a specific price - specified into the barcode barcode = barcode.substring(2,5);