[IMP] point_of_sale: hold receipts until the printer is back online
authorFrédéric van der Essen <fva@openerp.com>
Thu, 30 Jan 2014 10:30:51 +0000 (11:30 +0100)
committerFrédéric van der Essen <fva@openerp.com>
Thu, 30 Jan 2014 10:30:51 +0000 (11:30 +0100)
bzr revid: fva@openerp.com-20140130103051-htsx7ts111axhhub

addons/point_of_sale/static/src/js/devices.js

index 57b23af..bb13503 100644 (file)
@@ -102,6 +102,8 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
             };    
             this.custom_payment_status = this.default_payment_status;
 
+            this.receipt_queue = [];
+
             this.notifications = {};
             this.bypass_proxy = false;
 
@@ -113,6 +115,13 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
 
             this.set_connection_status('disconnected');
 
+            this.on('change:status',this,function(eh,status){
+                status = status.newValue;
+                if(status.status === 'connected'){
+                    self.print_receipt();
+                }
+            });
+
             window.hw_proxy = this;
         },
         set_connection_status: function(status,drivers){
@@ -502,7 +511,23 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
          *    }
          */
         print_receipt: function(receipt){
-            return this.message('print_receipt',{receipt: receipt});
+            var self = this;
+            if(receipt){
+                this.receipt_queue.push(receipt);
+            }
+            var aborted = false;
+            function send_printing_job(){
+                if (self.receipt_queue.length > 0){
+                    var r = self.receipt_queue.shift();
+                    self.message('print_receipt',{ receipt: r },{ timeout: 5000 })
+                        .then(function(){
+                            send_printing_job();
+                        },function(){
+                            self.receipt_queue.unshift(r)
+                        });
+                }
+            }
+            send_printing_job();
         },
 
         // asks the proxy to log some information, as with the debug.log you can provide several arguments.