diff --git a/addons/point_of_sale/static/src/js/devices.js b/addons/point_of_sale/static/src/js/devices.js index 57b23afd49f..bb13503d903 100644 --- a/addons/point_of_sale/static/src/js/devices.js +++ b/addons/point_of_sale/static/src/js/devices.js @@ -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.