diff --git a/addons/point_of_sale/static/src/js/Screens/OrderManagementScreen/OrderFetcher.js b/addons/point_of_sale/static/src/js/Screens/OrderManagementScreen/OrderFetcher.js index 57a0263567b2cbd178227ecafb0145cf8c0b4bab..810d108d547bf6eaa47ee1348eefbf75cc055cb5 100644 --- a/addons/point_of_sale/static/src/js/Screens/OrderManagementScreen/OrderFetcher.js +++ b/addons/point_of_sale/static/src/js/Screens/OrderManagementScreen/OrderFetcher.js @@ -133,6 +133,7 @@ odoo.define('point_of_sale.OrderFetcher', function (require) { const idsNotInCache = ids.filter((id) => !(id in this.cache)); if (idsNotInCache.length > 0) { const fetchedOrders = await this._fetchOrders(idsNotInCache); + await this.comp.env.pos._loadMissingProducts(fetchedOrders); // Cache these fetched orders so that next time, no need to fetch // them again, unless invalidated. See `invalidateCache`. fetchedOrders.forEach((order) => { diff --git a/addons/point_of_sale/static/src/js/db.js b/addons/point_of_sale/static/src/js/db.js index 5153ed761537210deb9aff2cdffb9dfaee0a1573..a0d3182366223db82c414f20668c734001b1f295 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 5641636464e376a4e06154a48b0a0affb5510795..29e00b483a6d42c3f4f60d437f82e2c7aca9ee30 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -428,7 +428,7 @@ exports.PosModel = Backbone.Model.extend({ model: 'product.product', 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]]; @@ -777,8 +777,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++) { @@ -810,7 +811,27 @@ exports.PosModel = Backbone.Model.extend({ this.get('orders').add(orders); } }, - + async _loadMissingProducts(orders) { + const missingProductIds = new Set([]); + for (const order of orders) { + for (const line of order.lines) { + const productId = line[2].product_id; + if (missingProductIds.has(productId)) continue; + if (!this.db.get_product_by_id(productId)) { + missingProductIds.add(productId); + } + } + } + const productModel = _.find(this.models, function(model){return model.model === 'product.product';}); + const fields = productModel.fields; + const products = await this.rpc({ + model: 'product.product', + method: 'read', + args: [[...missingProductIds], fields], + context: Object.assign(this.session.user_context, { display_default_code: false }), + }); + productModel.loaded(this, products); + }, set_start_order: function(){ var orders = this.get('orders').models;