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 53b72dfb765..d361f90f1ac 100644 --- a/addons/point_of_sale/static/src/js/pos_devices.js +++ b/addons/point_of_sale/static/src/js/pos_devices.js @@ -4,8 +4,15 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal var QWeb = instance.web.qweb; //TODO FIXME this should NOT be of any use in this file window.debug_devices = new (instance.web.Class.extend({ + active: false, payment_status: 'waiting_for_payment', weight: 0, + activate: function(){ + this.active = true; + }, + deactivate: function(){ + this.active = false; + }, accept_payment: function(){ this.payment_status = 'payment_accepted'; }, reject_payment: function(){ this.payment_status = 'payment_rejected'; }, delay_payment: function(){ this.payment_status = 'waiting_for_payment'; }, @@ -34,7 +41,11 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal var success_callback = function(result){}; //console.log('PROXY SUCCESS:'+name+': ',result); } var error_callback = function(result){}; // console.log('PROXY ERROR:'+name+': ',result); } //console.log('PROXY: '+name); - this.connection.rpc('/pos/'+name, params || {}, callback || success_callback, error_callback); + if(debug_devices.active){ + console.log('PROXY:',name,params); + }else{ + this.connection.rpc('/pos/'+name, params || {}, callback || success_callback, error_callback); + } }, //a product has been scanned and recognized with success @@ -60,6 +71,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal //the client is starting to weight weighting_start: function(){ this.weight = 0; + debug_devices.weigth = 0; this.weighting = true; this.message('weighting_start'); }, @@ -69,13 +81,17 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal // and a weighting_end() weighting_read_kg: function(){ 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; + if(debug_devices.active){ + return debug_devices.weight; + }else{ + 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 @@ -91,6 +107,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal payment_request: function(price, method, info){ this.paying = true; this.payment_status = 'waiting_for_payment'; + debug_devices.payment_status = 'waiting_for_payment'; this.message('payment_request',{'price':price,'method':method,'info':info}); }, @@ -99,12 +116,16 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal // returns 'waiting_for_payment' | 'payment_accepted' | 'payment_rejected' is_payment_accepted: function(){ var self = this; - this.message('is_payment_accepted', {}, function(payment_status){ - if(self.paying){ - self.payment_status = payment_status; - } - }); - return self.payment_status; + if(debug_devices.active){ + return debug_devices.payment_status; + }else{ + 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 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 7473397576f..6174bb3f5e2 100644 --- a/addons/point_of_sale/static/src/js/pos_models.js +++ b/addons/point_of_sale/static/src/js/pos_models.js @@ -29,14 +29,22 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }); }, _get: function(key, default_) { - var txt = localStorage[key]; + var txt = localStorage['oe_pos_dao_'+key]; if (! txt) return default_; return JSON.parse(txt); }, _set: function(key, value) { - localStorage[key] = JSON.stringify(value); + localStorage['oe_pos_dao_'+key] = JSON.stringify(value); }, + reset_stored_data: function(){ + for(key in localStorage){ + if(key.indexOf('oe_pos_dao_') === 0){ + delete localStorage[key]; + } + } + }, + }); var fetch = function(osvModel, fields, domain){ @@ -65,6 +73,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal this.session = session; this.categories = {}; this.root_category = null; + this.weightable_categories = []; // a flat list of all categories that directly contain weightable products this.barcode_reader = new module.BarcodeReader({'pos': this}); // used to read barcodes this.proxy = new module.ProxyDevice(); // used to communicate to the hardware devices via a local proxy @@ -85,10 +94,11 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal 'user': null, 'orders': new module.OrderCollection(), - 'products': new module.ProductCollection(), + //this is the product list as seen by the product list widgets, it will change based on the category filters + 'products': new module.ProductCollection(), 'cashRegisters': null, - 'product_list': null, + 'product_list': null, // the list of all products. 'bank_statements': null, 'taxes': null, 'pos_session': null, @@ -109,7 +119,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal var prod_def = fetch( 'product.product', - undefined, //['name', 'list_price', 'pos_categ_id', 'taxes_id','product_image_small', 'ean13'], + ['name', 'list_price', 'pos_categ_id', 'taxes_id','product_image_small', 'ean13', 'to_weight'], [['pos_categ_id','!=', false]] ).then(function(result){ self.set({'product_list': result}); @@ -314,12 +324,12 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal if(operations.length === 0){ return $.when(); } - var op = operations[0]; + var order = operations[0]; // 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')([order]) .fail(function(unused, event){ // wtf ask niv event.preventDefault(); @@ -395,6 +405,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal cat.product_set = {}; // [product.id] === true if product is in category cat.weightable_product_list = []; cat.weightable_product_set = {}; + cat.weightable = false; //true if directly contains weightable products } this.root_category = root_category; @@ -408,12 +419,22 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal if(cat){ cat.product_list.push(product); cat.product_set[product.id] = true; - if(product.weightable){ + if(product.to_weight){ cat.weightable_product_list.push(product); cat.weightable_product_set[product.id] = true; + cat.weightable = true; } } } + + // we build a flat list of all categories that directly contains weightable products + this.weightable_categories = []; + for(var i = 0, len = categories.length; i < len; i++){ + var cat = categories[i]; + if(cat.weightable){ + this.weightable_categories.push(cat); + } + } // add ancestor field to categories, contains the list of parents of parents, from root to parent function make_ancestors(cat, ancestors){ @@ -739,7 +760,8 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal amount_tax: this.getTax(), amount_return: this.getChange(), lines: orderLines, - statement_ids: paymentLines + statement_ids: paymentLines, + pos_session_id: this.pos.get('pos_session').id, }; }, }); diff --git a/addons/point_of_sale/static/src/js/pos_screens.js b/addons/point_of_sale/static/src/js/pos_screens.js index e4b36f79a8f..459b28c2670 100644 --- a/addons/point_of_sale/static/src/js/pos_screens.js +++ b/addons/point_of_sale/static/src/js/pos_screens.js @@ -303,6 +303,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa start: function(){ this.product_categories_widget = new module.ProductCategoriesWidget(this,{ pos:this.pos, + product_type: 'weightable', }); this.product_categories_widget.replace($('.placeholder-ProductCategoriesWidget')); @@ -464,11 +465,6 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa this.pos_widget.action_bar.add_new_button( { - label:'scan', - click: function(){ - self.pos_widget.screen_selector.set_current_screen('scan'); - } - },{ label: 'weight', icon: '/point_of_sale/static/src/img/icons/png48/scale.png', click: function(){ diff --git a/addons/point_of_sale/static/src/js/pos_widgets.js b/addons/point_of_sale/static/src/js/pos_widgets.js index b7db970891d..1b8ecb6cf24 100644 --- a/addons/point_of_sale/static/src/js/pos_widgets.js +++ b/addons/point_of_sale/static/src/js/pos_widgets.js @@ -400,6 +400,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa init: function(parent, options){ var self = this; this._super(parent,options); + this.product_type = options.product_type || 'all'; // 'all' | 'weightable' this.onlyWeightable = options.onlyWeightable || false; this.category = this.pos.root_category; this.breadcrumb = []; @@ -425,7 +426,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa if(this.category !== this.pos.root_category){ this.breadcrumb.push(this.category); } - if(this.onlyWeightable){ + if(this.product_type === 'weightable'){ this.subcategories = []; for(var i = 0; i < this.category.childrens.length; i++){ if(this.category.childrens[i].weightable_product_list.length > 0){ @@ -448,6 +449,11 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa self.search_and_categories(category); }); }, + + set_product_type: function(type){ // 'all' | 'weightable' + this.product_type = type; + this.reset_category(); + }, // resets the current category to the root category reset_category: function(){ @@ -465,7 +471,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa // find all products belonging to the current category var products = []; - if(this.onlyWeightable){ + if(this.product_type === 'weightable'){ products = all_products.filter( function(product){ return self.category.weightable_product_set[product.id]; }); @@ -770,6 +776,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa this._super(arguments[0],{}); this.pos = new module.PosModel(this.session); + window.pos = this.pos; this.pos_widget = this; //So that pos_widget's childs have pos_widget set automatically this.numpad_visible = true;