Forgot to add pictures, handling of codebar scanning in popups, client mode payment...
authorFrédéric van der Essen <fva@openerp.com>
Tue, 8 May 2012 15:40:30 +0000 (17:40 +0200)
committerFrédéric van der Essen <fva@openerp.com>
Tue, 8 May 2012 15:40:30 +0000 (17:40 +0200)
bzr revid: fva@openerp.com-20120508154030-f62eahx7c801lxnz

addons/point_of_sale/static/src/css/pos.css
addons/point_of_sale/static/src/img/bancontact.png [new file with mode: 0644]
addons/point_of_sale/static/src/img/scale.png [new file with mode: 0644]
addons/point_of_sale/static/src/img/scan.png [new file with mode: 0644]
addons/point_of_sale/static/src/js/pos_devices.js
addons/point_of_sale/static/src/js/pos_screens.js
addons/point_of_sale/static/src/js/pos_widgets.js

index 4ba5520..e1d01ee 100644 (file)
@@ -1,6 +1,3 @@
-body{
-    overflow: hidden;
-}
 .point-of-sale {
     padding: 0;
     margin: 0;
diff --git a/addons/point_of_sale/static/src/img/bancontact.png b/addons/point_of_sale/static/src/img/bancontact.png
new file mode 100644 (file)
index 0000000..5c34fef
Binary files /dev/null and b/addons/point_of_sale/static/src/img/bancontact.png differ
diff --git a/addons/point_of_sale/static/src/img/scale.png b/addons/point_of_sale/static/src/img/scale.png
new file mode 100644 (file)
index 0000000..8f66d1f
Binary files /dev/null and b/addons/point_of_sale/static/src/img/scale.png differ
diff --git a/addons/point_of_sale/static/src/img/scan.png b/addons/point_of_sale/static/src/img/scan.png
new file mode 100644 (file)
index 0000000..e5eafbe
Binary files /dev/null and b/addons/point_of_sale/static/src/img/scan.png differ
index e9c6941..0a3fbe9 100644 (file)
@@ -88,12 +88,12 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa
 
         // called when the POS turns to cashier mode
         cashier_mode_activated: function(){
-            console.log('PROXY:');
+            console.log('PROXY: cashier mode activated');
         },
 
         // called when the POS turns to client mode
         cashier_mode_deactivated: function(){
-            console.log('PROXY:');
+            console.log('PROXY: client mode activated');
         },
     });
 
@@ -111,12 +111,28 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa
                 'client':  undefined,
                 'discount': undefined,
             };
+
+            this.action_callback_stack = [];
+
             this.price_prefix_set = attributes.price_prefix_set     ||  {'02':'', '22':'', '24':'', '26':'', '28':''};
             this.weight_prefix_set = attributes.weight_prefix_set   ||  {'21':'','23':'','27':'','29':'','25':''};
             this.client_prefix_set = attributes.weight_prefix_set   ||  {'42':''};
-            this.cashier_prefix_set = attributes.weight_prefix_set  ||  {'43':''};
+            this.cashier_prefix_set = attributes.weight_prefix_set  ||  {'40':''};
             this.discount_prefix_set = attributes.weight_prefix_set ||  {'44':''};
         },
+        save_callbacks: function(){
+            var callbacks = {};
+            for(name in this.action_callback){
+                callbacks[name] = this.action_callback[name];
+            }
+            this.action_callback_stack.push(callbacks);
+        },
+        restore_callbacks: function(){
+            if(this.action_callback_stack.length){
+                var callbacks = this.action_callback_stack.pop();
+                this.action_callback = callbacks;
+            }
+        },
        
         // when an ean is scanned and parsed, the callback corresponding
         // to its type is called with the parsed_ean as a parameter. 
@@ -240,64 +256,6 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa
             return parse_result;
         },
 
-        // returns a product that has a packaging with an EAN matching to provided ean string. 
-        // returns undefined if no such product is found.
-        get_product_by_ean: function(ean) {
-            var allProducts = this.pos.get('product_list');
-            var allPackages = this.pos.get('product.packaging');
-            var scannedProductModel = undefined;
-            var parse_result = this.parse_ean(ean);
-
-            console.log('getting products:',ean,parse_result,allProducts);
-
-            if (parse_result.type === 'price') {
-                var itemCode = parse_result.id;
-                var scannedPackaging = _.detect(allPackages, function(pack) { return pack.ean !== undefined && pack.ean.substring(0,7) === itemCode;});
-                if (scannedPackaging !== undefined) {
-                    scannedProductModel = _.detect(allProducts, function(pc) { return pc.id === scannedPackaging.product_id[0];});
-                    scannedProductModel.list_price = parse_result.value;
-                }
-            } else if (parse_result.type === 'weight') {
-                var weight = parse_result.value;
-                var itemCode = parse_result.id;
-                var scannedPackaging = _.detect(allPackages, function(pack) { return pack.ean !== undefined && pack.ean.substring(0,7) === itemCode;});
-                if (scannedPackaging !== undefined) {
-                    scannedProductModel = _.detect(allProducts, function(pc) { return pc.id === scannedPackaging.product_id[0];});
-                    scannedProductModel.list_price *= weight;
-                    scannedProductModel.name += ' - ' + weight + ' Kg.';
-                }
-            } else if(parse_result.type === 'unit'){
-                scannedProductModel = _.detect(allProducts, function(pc) { return pc.ean13 === ean;});   //TODO DOES NOT SCALE
-            }
-            return scannedProductModel;
-        },
-
-        // a default callback for the 'product' action. It will select the product
-        // corresponding to the ean and add it to the current order. 
-        scan_product_callback: function(parse_result){
-            var self = this;
-            var selectedOrder = self.pos.get('selectedOrder');
-            var scannedProductModel = self.get_product_by_ean(parse_result.ean);
-            if (scannedProductModel === undefined) {
-                // product not recognized, raise warning
-                $(QWeb.render('pos-scan-warning')).dialog({
-                    resizable: false,
-                    height:220,
-                    modal: true,
-                    title: "Warning",
-                    /*
-                    buttons: {
-                        "OK": function() {
-                            $( this ).dialog( "close" );
-                            return;
-                        },
-                    }*/
-                });
-            } else {
-                selectedOrder.addProduct(new module.Product(scannedProductModel));
-            }
-        },
-
         simulate : function(type){
 
             var parse_result = {
index a9c49bf..e693a6b 100644 (file)
@@ -221,18 +221,26 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
     module.ErrorPopupWidget = module.PopUpWidget.extend({
         template:'ErrorPopupWidget',
         show: function(){
+            var self = this;
             this._super();
             this.pos.proxy.help_needed();
-            var self = this;
-            
-            this.$element.find('.button').off('click').click(function(){
-                self.pos.screen_selector.close_popup();
-                self.pos.proxy.help_canceled();
+            this.pos.proxy.scan_item_error_unrecognized();
+
+            this.pos.barcode_reader.save_callbacks();
+            this.pos.barcode_reader.reset_action_callbacks();
+            console.log('actionz callbacks zwave been resetses');
+            this.pos.barcode_reader.set_action_callbacks({
+                'cashier': function(ean){
+                    clearInterval(this.intervalID);
+                    self.pos.proxy.cashier_mode_activated();
+                    self.pos.screen_selector.set_user_mode('cashier');
+                },
             });
         },
         hide:function(){
             this._super();
             this.pos.proxy.help_canceled();
+            this.pos.barcode_reader.restore_callbacks();
         },
     });
 
@@ -270,6 +278,21 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
                     }
                 }
             );
+
+            this.pos.barcode_reader.set_action_callbacks({
+                'cashier': function(ean){
+                    self.pos.proxy.cashier_mode_activated();
+                    self.pos.screen_selector.set_user_mode('cashier');
+                },
+                'product': function(ean){
+                    if(self.pos_widget.scan_product(ean)){
+                        self.pos.proxy.scan_item_success();
+                        self.pos.screen_selector.set_current_screen('scan');
+                    }else{
+                        self.pos.screen_selector.show_popup('error');
+                    }
+                },
+            });
         },
         hide: function(){
             this._super();
@@ -314,8 +337,17 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
                 );
                 this.pos.barcode_reader.set_action_callbacks({
                     'cashier': function(ean){
-                        self.proxy.cashier_mode_activated();
+                        self.pos.proxy.cashier_mode_activated();
+                        self.pos.screen_selector.set_user_mode('cashier');
                     },
+                    'product': function(ean){
+                        if(self.pos_widget.scan_product(ean)){
+                            self.pos.proxy.scan_item_success();
+                            self.pos.screen_selector.set_current_screen('scan');
+                        }else{
+                            self.pos.screen_selector.show_popup('error');
+                    }
+                },
                 });
                 this.product_list_widget.set_next_screen('scan');
             }else{  // user_mode === 'cashier'
@@ -370,15 +402,18 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
             this.pos_widget.action_bar.set_help_visible(true,function(){self.pos.screen_selector.show_popup('help');});
             this.pos_widget.action_bar.set_logout_visible(false);
 
-            this.pos.proxy.payment_request(0,'card','info');    //TODO TOTAL
+            this.pos.proxy.payment_request(this.pos.get('selectedOrder').getTotal(),'card','info');    //TODO TOTAL
 
             this.intervalID = setInterval(function(){
                 var payment = self.pos.proxy.is_payment_accepted();
                 if(payment === 'payment_accepted'){
                     clearInterval(this.intervalID);
-                    //TODO process the payment stuff
-                    self.pos.proxy.transaction_end();
-                    self.pos.screen_selector.set_current_screen('welcome');
+                    var currentOrder = self.pos.get('selectedOrder');
+                    self.pos.push_order(currentOrder.exportAsJSON()).then(function() {
+                        currentOrder.destroy();
+                        self.pos.proxy.transaction_end();
+                        self.pos.screen_selector.set_current_screen('welcome');
+                    });
                 }else if(payment === 'payment_rejected'){
                     clearInterval(this.intervalID);
                     //TODO show a tryagain thingie ? 
@@ -399,10 +434,9 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
 
             this.pos.barcode_reader.set_action_callbacks({
                 'cashier': function(ean){
-                    //TODO 'switch to cashier mode'
                     clearInterval(this.intervalID);
-                    self.proxy.cashier_mode_activated();
-                    self.pos.screen_selector.set_current_screen('products');
+                    self.pos.proxy.cashier_mode_activated();
+                    self.pos.screen_selector.set_user_mode('cashier');
                 },
             });
         },
@@ -441,15 +475,18 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
             );
             this.pos.barcode_reader.set_action_callbacks({
                 'product': function(ean){
-                    console.log('product!');
                     self.pos.proxy.transaction_start(); 
-                    self.pos.barcode_reader.scan_product_callback(ean);
-                    self.pos.screen_selector.set_current_screen('products');
+                    if(self.pos_widget.scan_product(ean)){
+                        self.pos.proxy.scan_item_success();
+                        self.pos.screen_selector.set_current_screen('scan');
+                    }else{
+                        self.pos.screen_selector.show_popup('error');
+                    }
                 },
                 'cashier': function(ean){
                     //TODO 'switch to cashier mode'
                     self.pos.proxy.cashier_mode_activated();
-                    self.pos.screen_selector.set_current_screen('products');
+                    self.pos.screen_selector.set_user_mode('cashier');
                 },
                 'client': function(ean){
                     self.pos.proxy.transaction_start(); 
@@ -498,16 +535,15 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
             );
             this.pos.barcode_reader.set_action_callbacks({
                 'product': function(ean){
-                    var success = self.pos.barcode_reader.scan_product_callback(ean);
-                    if(success){
-                        self.proxy.scan_item_success();
+                    if(self.pos_widget.scan_product(ean)){
+                        self.pos.proxy.scan_item_success();
                     }else{
-                        self.proxy.scan_item_error_unrecognized();
+                        self.pos.screen_selector.show_popup('error');
                     }
                 },
                 'cashier': function(ean){
-                    //TODO 'switch to cashier mode'
-                    self.proxy.cashier_mode_activated();
+                    self.pos.proxy.cashier_mode_activated();
+                    self.pos.screen_selector.set_user_mode('cashier');
                 },
                 'discount': function(ean){
                     // TODO : handle the discount
@@ -554,15 +590,15 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
             );
             this.pos.barcode_reader.set_action_callbacks({
                 'product': function(ean){
-                    var success = self.pos.barcode_reader.scan_product_callback(ean);
-                    if(success){
-                        self.proxy.scan_item_success();
+                    if(self.pos_widget.scan_product(ean)){
+                        self.pos.proxy.scan_item_success();
                     }else{
-                        self.proxy.scan_item_error_unrecognized();
+                        self.pos.screen_selector.show_popup('error');
                     }
                 },
                 'cashier': function(ean){
-                    self.proxy.cashier_mode_activated();
+                    self.pos.proxy.cashier_mode_activated();
+                    self.pos.screen_selector.set_user_mode('cashier');
                 },
                 'discount': function(ean){
                     // TODO : handle the discount
index 834ec0c..2410cb9 100644 (file)
@@ -962,6 +962,47 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
             this.pos.barcode_reader.connect();
             
         },
+
+        //FIXME this method is probably not at the right place ... 
+        scan_product: function(parsed_ean){
+            var selectedOrder = this.pos.get('selectedOrder');
+            var scannedProductModel = this.get_product_by_ean(parsed_ean.ean);
+            if (!scannedProductModel){
+                return false;
+            } else {
+                selectedOrder.addProduct(new module.Product(scannedProductModel));
+                return true;
+            }
+        },
+
+        // returns a product that has a packaging with an EAN matching to provided parsed ean . 
+        // returns undefined if no such product is found.
+        get_product_by_ean: function(parsed_ean) {
+            var allProducts = this.pos.get('product_list');
+            var allPackages = this.pos.get('product.packaging');
+            var scannedProductModel = undefined;
+
+            if (parsed_ean.type === 'price') {
+                var itemCode = parse_result.id;
+                var scannedPackaging = _.detect(allPackages, function(pack) { return pack.ean !== undefined && pack.ean.substring(0,7) === itemCode;});
+                if (scannedPackaging !== undefined) {
+                    scannedProductModel = _.detect(allProducts, function(pc) { return pc.id === scannedPackaging.product_id[0];});
+                    scannedProductModel.list_price = parsed_ean.value;
+                }
+            } else if (parsed_ean.type === 'weight') {
+                var weight = parsed_ean.value;
+                var itemCode = parsed_ean.id;
+                var scannedPackaging = _.detect(allPackages, function(pack) { return pack.ean !== undefined && pack.ean.substring(0,7) === itemCode;});
+                if (scannedPackaging !== undefined) {
+                    scannedProductModel = _.detect(allProducts, function(pc) { return pc.id === scannedPackaging.product_id[0];});
+                    scannedProductModel.list_price *= weight;
+                    scannedProductModel.name += ' - ' + weight + ' Kg.';
+                }
+            } else if(parsed_ean.type === 'unit'){
+                scannedProductModel = _.detect(allProducts, function(pc) { return pc.ean13 === parsed_ean.ean;});   //TODO DOES NOT SCALE
+            }
+            return scannedProductModel;
+        },
         createNewOrder: function() {
             var newOrder;
             newOrder = new module.Order({'pos': this.pos});