From a70f9a3d84c6d20433bcfe4f3fbe60fe0282c602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Sun, 21 Dec 2014 04:36:22 +0100 Subject: [PATCH] [WIP] point_of_sale: simplify the loading sequence --- addons/point_of_sale/static/src/js/chrome.js | 5 +--- addons/point_of_sale/static/src/js/models.js | 25 +++++--------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/addons/point_of_sale/static/src/js/chrome.js b/addons/point_of_sale/static/src/js/chrome.js index 3bdd01013ba..32f11aeeb88 100644 --- a/addons/point_of_sale/static/src/js/chrome.js +++ b/addons/point_of_sale/static/src/js/chrome.js @@ -420,12 +420,9 @@ openerp.point_of_sale.load_chrome = function load_chrome(instance, module){ //mo this.pos.ready.done(function(){ self.build_chrome(); - self.pos.on_chrome_started(); - self.started.resolve(); self.build_widgets(); - self.pos.on_chrome_ready(); - self.ready.resolve(); self.disable_rubberbanding(); + self.ready.resolve(); self.loading_hide(); }).fail(function(err){ // error when loading models data from the backend self.loading_error(err); diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 28c1a5be910..b1634927392 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -28,16 +28,12 @@ openerp.point_of_sale.load_models = function load_models(instance, module){ //mo this.proxy = new module.ProxyDevice(this); // used to communicate to the hardware devices via a local proxy this.barcode_reader = new module.BarcodeReader({'pos': this, proxy:this.proxy}); - this.chrome.ready.then(function(){ - self.barcode_reader.connect(); - }); this.proxy_queue = new module.JobQueue(); // used to prevent parallels communications to the proxy this.db = new module.PosDB(); // a local database used to search trough products and categories & store pending orders this.debug = jQuery.deparam(jQuery.param.querystring()).debug !== undefined; //debug mode // Business data; loaded from the server at launch - this.accounting_precision = 2; //TODO this.company_logo = null; this.company_logo_base64 = ''; this.currency = null; @@ -80,21 +76,19 @@ openerp.point_of_sale.load_models = function load_models(instance, module){ //mo // We fetch the backend data on the server asynchronously. this is done only when the pos user interface is launched, // Any change on this data made on the server is thus not reflected on the point of sale until it is relaunched. // when all the data has loaded, we compute some stuff, and declare the Pos ready to be used. - this.ready = this.load_server_data(); - + this.ready = this.load_server_data().then(function(){ + return self.after_load_server_data(); + });; }, - on_chrome_started: function(){ + after_load_server_data: function(){ this.barcode_reader.connect(); this.load_orders(); this.set_start_order(); - }, - on_chrome_ready: function(){ + this.push_order(); if(this.config.use_proxy){ return this.connect_to_proxy(); } - this.push_order(); }, - // 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 @@ -103,6 +97,7 @@ openerp.point_of_sale.load_models = function load_models(instance, module){ //mo this.barcode_reader.disconnect(); this.barcode_reader.disconnect_from_proxy(); }, + connect_to_proxy: function(){ var self = this; var done = new $.Deferred(); @@ -126,13 +121,6 @@ openerp.point_of_sale.load_models = function load_models(instance, module){ //mo return done; }, - // helper function to load data from the server. Obsolete use the models loader below. - fetch: function(model, fields, domain, ctx){ - this._load_progress = (this._load_progress || 0) + 0.05; - this.chrome.loading_message(_t('Loading')+' '+model,this._load_progress); - return new instance.web.Model(model).query(fields).filter(domain).context(ctx).all() - }, - // Server side model loaders. This is the list of the models that need to be loaded from // the server. The models are loaded one by one by this list's order. The 'loaded' callback // is used to store the data in the appropriate place once it has been loaded. This callback @@ -603,7 +591,6 @@ openerp.point_of_sale.load_models = function load_models(instance, module){ //mo var self = this; if(order){ - this.proxy.log('push_order',order.export_as_JSON()); this.db.add_order(order.export_as_JSON()); }