From f19a4b99aa39185f145d02ca1ff0a7361e49469b Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Mon, 31 May 2021 13:04:21 +0000 Subject: [PATCH] [FIX] point_of_sale: load missing products When loading pos, orders saved from the local storage is loaded. There is, however, a chance that the products used in the loaded orders are missing during the loading of pos. (Which can be caused by backend changes such as archiving a product.) This situation is similar when loading paid orders from the backend in the order management screen. This results to crashing of the pos app and force clearance of the local storage in order for pos to work again. In this commit, we try to rectify the issue by loading the unloaded products. The product remain inactive if it was archived, however, they can still be visible in the orderlines. closes odoo/odoo#72108 Signed-off-by: pimodoo --- addons/point_of_sale/static/src/js/db.js | 8 ++++++-- addons/point_of_sale/static/src/js/models.js | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/point_of_sale/static/src/js/db.js b/addons/point_of_sale/static/src/js/db.js index ca0afd28a83..a56e660e768 100644 --- a/addons/point_of_sale/static/src/js/db.js +++ b/addons/point_of_sale/static/src/js/db.js @@ -363,7 +363,9 @@ var PosDB = core.Class.extend({ var list = []; if (product_ids) { for (var i = 0, len = Math.min(product_ids.length, this.limit); i < len; i++) { - list.push(this.product_by_id[product_ids[i]]); + const product = this.product_by_id[product_ids[i]]; + if (!(product.active && product.available_in_pos)) continue; + list.push(product); } } return list; @@ -385,7 +387,9 @@ var PosDB = core.Class.extend({ var r = re.exec(this.category_search_string[category_id]); if(r){ var id = Number(r[1]); - results.push(this.get_product_by_id(id)); + const product = this.get_product_by_id(id); + if (!(product.active && product.available_in_pos)) continue; + results.push(product); }else{ break; } diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 9a6da2ffa79..3c179d2c95b 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -137,8 +137,8 @@ exports.PosModel = Backbone.Model.extend({ searchTerm: '', }; }, - after_load_server_data: function(){ - this.load_orders(); + after_load_server_data: async function(){ + await this.load_orders(); this.set_start_order(); if(this.config.use_proxy){ if (this.config.iface_customer_facing_display) { @@ -476,7 +476,7 @@ exports.PosModel = Backbone.Model.extend({ condition: function (self) { return !self.config.limited_products_loading; }, fields: ['display_name', 'lst_price', 'standard_price', 'categ_id', 'pos_categ_id', 'taxes_id', 'barcode', 'default_code', 'to_weight', 'uom_id', 'description_sale', 'description', - 'product_tmpl_id','tracking', 'write_date', 'available_in_pos', 'attribute_line_ids'], + 'product_tmpl_id','tracking', 'write_date', 'available_in_pos', 'attribute_line_ids', 'active'], order: _.map(['sequence','default_code','name'], function (name) { return {name: name}; }), domain: function(self){ var domain = ['&', '&', ['sale_ok','=',true],['available_in_pos','=',true],'|',['company_id','=',self.config.company_id[0]],['company_id','=',false]]; @@ -833,8 +833,9 @@ exports.PosModel = Backbone.Model.extend({ * Second load all orders belonging to the same config but from other sessions, * Only if tho order has orderlines. */ - load_orders: function(){ + load_orders: async function(){ var jsons = this.db.get_unpaid_orders(); + await this._loadMissingProducts(jsons); var orders = []; for (var i = 0; i < jsons.length; i++) {