Roberto López López (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-pos_barcode_reader-rlo into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-pos_barcode_reader-rlo/+merge/98812

I have added to the point of sale screen the listener for the barcode reader.

Now, every time there's a barcode reader event, the client looks for the readed 
barcode into the products collection. If it finds it, it goes into the current 
order.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-pos_barcode_reader-rlo/+merge/98812
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-pos_barcode_reader-rlo.
=== modified file 'point_of_sale/__openerp__.py'
--- point_of_sale/__openerp__.py	2012-02-29 11:07:30 +0000
+++ point_of_sale/__openerp__.py	2012-03-22 10:40:27 +0000
@@ -82,7 +82,7 @@
     'application': True,
     'certificate' : '001156338024966477869',
     # Web client
-    'js': ['static/lib/backbone/backbone-0.5.3.js', 'static/src/js/pos.js'],
+    'js': ['static/lib/backbone/backbone-0.5.3.js', 'static/src/js/pos.js', 'static/lib/jquery-barcodelistener/jquery.barcodelistener-1.1-min.js'],
     'css': ['static/src/css/pos.css'],
     'qweb': ['static/src/xml/pos.xml'],
 }

=== modified file 'point_of_sale/static/src/js/pos.js'
--- point_of_sale/static/src/js/pos.js	2012-03-07 15:05:49 +0000
+++ point_of_sale/static/src/js/pos.js	2012-03-22 10:40:27 +0000
@@ -85,7 +85,7 @@
                 }, this));
             }, this));
             $.when(this.fetch('pos.category', ['name', 'parent_id', 'child_id']),
-                this.fetch('product.product', ['name', 'list_price', 'pos_categ_id', 'taxes_id', 'product_image_small'], [['pos_categ_id', '!=', 'false']]),
+                this.fetch('product.product', ['name', 'list_price', 'pos_categ_id', 'taxes_id', 'product_image_small', 'ean13'], [['pos_categ_id', '!=', 'false']]),
                 this.fetch('account.bank.statement', ['account_id', 'currency', 'journal_id', 'state', 'name'],
                     [['state', '=', 'open'], ['user_id', '=', this.session.uid]]),
                 this.fetch('account.journal', ['auto_cash', 'check_dtls', 'currency', 'name', 'type']),
@@ -1259,6 +1259,38 @@
             });
             (this.shop.get('products')).reset(products);
             var self = this;
+            // bind barcode reader event
+            codeNumbers = []
+            $('body').delegate('','keyup', function (e){
+                if (e.keyCode >= 48 && e.keyCode <= 57) {
+                    // a number
+                    if (codeNumbers.length==0) {
+                        codeNumbers.timeStamp = new Date().getTime()
+                    } else {
+                        if (codeNumbers.lastTimeStamp + 30 < new Date().getTime()) {
+                            // not a barcode reader
+                            console.log(e)
+                            codeNumbers = []
+                            codeNumbers.timeStamp = new Date().getTime()
+                        }
+                    }
+                    codeNumbers.push(e.keyCode - 48)
+                    codeNumbers.lastTimeStamp = new Date().getTime()
+                    if (codeNumbers.length == 13) {
+                        // a barcode reader
+                        console.log('barcode: ' + codeNumbers.join())
+                        selectedOrder = self.shop.get('selectedOrder')
+                        productsCollection = self.shop.get('products')
+                        scannedProductModel = _.detect(productsCollection.models, function(pc) { return pc.attributes.ean13 === codeNumbers.join('')})
+                        selectedOrder.addProduct(scannedProductModel)
+
+                        codeNumbers = []
+                    }
+                } else {
+                    // NaN
+                    codeNumbers = []
+                }
+            })
             $('.searchbox input').keyup(function() {
                 var m, s;
                 s = $(this).val().toLowerCase();
@@ -1325,6 +1357,8 @@
                 });
 
                 pos.app = new App(self.$element);
+
+
                 db.webclient.set_content_full_screen(true);
                 
                 if (pos.store.get('account.bank.statement').length === 0)
@@ -1373,6 +1407,9 @@
             }, this));
         },
         close: function() {
+            // remove barcode reader event listener
+            $('body').undelegate('', 'keyup')
+
             return new db.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_pos_close_statement']], ['res_id']).pipe(
                     _.bind(function(res) {
                 return this.rpc('/web/action/load', {'action_id': res[0]['res_id']}).pipe(_.bind(function(result) {

=== modified file 'product/product.py'
--- product/product.py	2012-02-22 11:53:32 +0000
+++ product/product.py	2012-03-22 10:40:27 +0000
@@ -517,7 +517,7 @@
         'active': fields.boolean('Active', help="If the active field is set to False, 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"),
-        'ean13': fields.char('EAN13', size=13),
+        'ean13': fields.char('EAN13', size=13, help='Barcode'),
         '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('Sale Price')),
         'price_margin': fields.float('Variant Price Margin', digits_compute=dp.get_precision('Sale Price')),

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to