From a27d1aa3ce1a9e51a46aa8236e68fdc2c3add02c Mon Sep 17 00:00:00 2001 From: anhe-odoo Date: Mon, 28 Mar 2022 08:18:56 +0000 Subject: [PATCH] [FIX] POS: search from database doens't rewrite available_in_pos Observed Behaviour When loading limited number of products in POS, we have the "database search" functionnality allowing use to search in non-loaded product. Anyway, using this method will make all products found in the search available in POS, despite having set it to "False" on the product page. Desired Behaviour This search method should only search on the already checked "available in POS" products and shouldn't in any case write in the models. Fix Description A filter on "available_in_pos" property has been added to the search, and, because we now only search on already availaible products, rewriting on this fields isn't necessary. We then decided to add an optional parameters to the _addProducts method, set to true by default, which allow us to set (or not) the products as 'available in POS'. Related Issues/PR -opw-2766095 closes odoo/odoo#88386 X-original-commit: e19dca22c5740262449ca061d1681eb8555036f0 Signed-off-by: Hendrickx Anthony (anhe) --- .../ProductScreen/ProductsWidgetControlPanel.js | 4 ++-- addons/point_of_sale/static/src/js/models.js | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidgetControlPanel.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidgetControlPanel.js index 8ee678c4a06..87f13db6347 100644 --- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidgetControlPanel.js +++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidgetControlPanel.js @@ -54,7 +54,7 @@ odoo.define('point_of_sale.ProductsWidgetControlPanel', function(require) { let ProductIds = await this.rpc({ model: 'product.product', method: 'search', - args: [[['name', 'ilike', this.searchWordInput.el.value + "%"]]], + args: [['&', ['name', 'ilike', this.searchWordInput.el.value + "%"], ['available_in_pos', '=', true]]], context: this.env.session.user_context, }); if(!ProductIds.length) { @@ -63,7 +63,7 @@ odoo.define('point_of_sale.ProductsWidgetControlPanel', function(require) { body: this.env._t("No product found"), }); } else { - await this.env.pos._addProducts(ProductIds); + await this.env.pos._addProducts(ProductIds, false); } this.trigger('update-product-list'); } catch (error) { diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index e7b84b9e11a..f4c85fc33c7 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -990,13 +990,15 @@ class PosGlobalState extends PosModel { * Make the products corresponding to the given ids to be available_in_pos and * fetch them to be added on the loaded products. */ - async _addProducts(ids){ - await this.env.services.rpc({ - model: 'product.product', - method: 'write', - args: [ids, {'available_in_pos': true}], - context: this.env.session.user_context, - }); + async _addProducts(ids, setAvailable=true){ + if(setAvailable){ + await this.env.services.rpc({ + model: 'product.product', + method: 'write', + args: [ids, {'available_in_pos': true}], + context: this.env.session.user_context, + }); + } let product = await this.env.services.rpc({ model: 'pos.session', method: 'get_pos_ui_product_product_by_params',