From c12dddf7a7cc1db3bd7293f181cb8cf2762992a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Wed, 23 May 2012 18:02:55 +0200 Subject: [PATCH] [FIX] point_of_sale: removed debug_devices. now uses real devices bzr revid: fva@openerp.com-20120523160255-fkoosqnpvcms3ro2 --- .../static/src/js/pos_devices.js | 35 ++++++++++++++++--- .../point_of_sale/static/src/js/pos_models.js | 8 ++++- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos_devices.js b/addons/point_of_sale/static/src/js/pos_devices.js index 0441702a240..de036e8a9bc 100644 --- a/addons/point_of_sale/static/src/js/pos_devices.js +++ b/addons/point_of_sale/static/src/js/pos_devices.js @@ -19,9 +19,16 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal init: function(options){ options = options || {}; url = options.url || 'http://localhost:8069'; + + this.weight = 0; + this.weighting = false; + + this.paying = false; + this.payment_status = 'waiting_for_payment'; this.connection = new instance.web.JsonRPC(); this.connection.setup(url); + }, message : function(name,params,callback){ var success_callback = function(result){ console.log('PROXY SUCCESS:'+name+': ',result); } @@ -52,6 +59,8 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal //the client is starting to weight weighting_start: function(){ + this.weight = 0; + this.weighting = true; this.message('weighting_start'); }, @@ -59,12 +68,20 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal // is called at regular interval (up to 10x/sec) between a weighting_start() // and a weighting_end() weighting_read_kg: function(){ - this.message('weighting_read_kg'); - return window.debug_devices.weight; + var self = this; + this.message('weighting_read_kg',{},function(weight){ + if(self.weighting){ + console.log('PROXY SUCCESSFULLY READ WEIGHT:',weight); + self.weight = weight; + } + }); + return self.weight; }, // the client has finished weighting products weighting_end: function(){ + this.weight = 0; + this.weighting = false; this.message('weighting_end'); }, @@ -72,6 +89,8 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal // method: 'mastercard' | 'cash' | ... ? TBD // info: 'extra information to display on the payment terminal' ... ? TBD payment_request: function(price, method, info){ + this.paying = true; + this.payment_status = 'waiting_for_payment'; this.message('payment_request',{'price':price,'method':method,'info':info}); }, @@ -79,13 +98,19 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal // has paid the required money // returns 'waiting_for_payment' | 'payment_accepted' | 'payment_rejected' is_payment_accepted: function(){ - this.message('is_payment_accepted'); - //return 'waiting_for_payment'; // 'payment_accepted' | 'payment_rejected' - return window.debug_devices.payment_status; + var self = this; + this.message('is_payment_accepted', {}, function(payment_status){ + if(self.paying){ + self.payment_status = payment_status; + } + }); + return self.payment_status; }, // the client cancels his payment payment_canceled: function(){ + this.paying = false; + this.payment_status = 'waiting_for_payment'; this.message('payment_canceled'); }, diff --git a/addons/point_of_sale/static/src/js/pos_models.js b/addons/point_of_sale/static/src/js/pos_models.js index d2a44634b37..3d0cab89754 100644 --- a/addons/point_of_sale/static/src/js/pos_models.js +++ b/addons/point_of_sale/static/src/js/pos_models.js @@ -219,6 +219,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal push_order: function(record) { var self = this; + console.log('push_order',record); return this.dao.add_operation(record).pipe(function(){ return self.flush(); }); @@ -236,6 +237,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal // it has been confirmed that they have been received. flush: function() { //this makes sure only one _int_flush is called at the same time + console.log('flush operations'); return this.flush_mutex.exec(_.bind(function() { return this._int_flush(); }, this)); @@ -244,6 +246,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal var self = this; this.dao.get_operations().pipe(function(operations) { + console.log('_int_flushing ' + operations.length + ' operations'); self.set( {'nbr_pending_operations':operations.length} ); if(operations.length === 0){ return $.when(); @@ -253,15 +256,18 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal // we prevent the default error handler and assume errors // are a normal use case, except we stop the current iteration - return new instance.web.Model('pos.order').get_func('create_from_ui')([op]) + return (new instance.web.Model('pos.order')).get_func('create_from_ui')([op]) .fail(function(unused, event){ + console.log('failed to flush?'); event.preventDefault(); }) .pipe(function(){ + console.log('success ?'); self.dao.remove_operation(operations[0].id).pipe(function(){ return self._int_flush(); }); }, function(){ + console.log('retrying'); return $.when(); }); });