diff --git a/addons/point_of_sale/static/src/js/devices.js b/addons/point_of_sale/static/src/js/devices.js index 835b7fe7b5a..9a74eec0c05 100644 --- a/addons/point_of_sale/static/src/js/devices.js +++ b/addons/point_of_sale/static/src/js/devices.js @@ -25,13 +25,15 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal }; this.custom_payment_status = this.default_payment_status; - this.connection = new instance.web.JsonRPC(); - this.connection.setup(url); + this.connection = new instance.web.Session(undefined,url); this.bypass_proxy = false; this.notifications = {}; }, + close: function(){ + this.connection.destroy(); + }, message : function(name,params){ var ret = new $.Deferred(); var callbacks = this.notifications[name] || []; diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 70fdc89246e..e4d69bca26f 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -71,6 +71,14 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }); }, + // releases ressources holds by the model at the end of life of the posmodel + destroy: function(){ + // FIXME, should wait for flushing, return a deferred to indicate successfull destruction + // this.flush(); + this.proxy.close(); + this.barcode_reader.disconnect(); + }, + // helper function to load data from the server fetch: function(model, fields, domain, ctx){ return new instance.web.Model(model).query(fields).filter(domain).context(ctx).all() diff --git a/addons/point_of_sale/static/src/js/widgets.js b/addons/point_of_sale/static/src/js/widgets.js index af0ff2ab746..bf7cf4d13af 100644 --- a/addons/point_of_sale/static/src/js/widgets.js +++ b/addons/point_of_sale/static/src/js/widgets.js @@ -990,7 +990,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa this.close_button = new module.HeaderButtonWidget(this,{ label: _t('Close'), - action: function(){ self.try_close(); }, + action: function(){ self.close(); }, }); this.close_button.appendTo(this.$('#rightheader')); @@ -1100,15 +1100,8 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa } } }, - try_close: function() { - var self = this; - //TODO : do the close after the flush... - self.pos.flush() - self.close(); - }, close: function() { var self = this; - this.pos.barcode_reader.disconnect(); return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_client_pos_menu']], ['res_id']).pipe( _.bind(function(res) { return this.rpc('/web/action/load', {'action_id': res[0]['res_id']}).pipe(_.bind(function(result) { @@ -1120,8 +1113,8 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa }, this)); }, destroy: function() { + this.pos.destroy(); instance.webclient.set_content_full_screen(false); - self.pos = undefined; this._super(); } });