[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) <anhe@odoo.com>
This commit is contained in:
anhe-odoo
2022-04-11 12:42:36 +02:00
parent 3801818150
commit a27d1aa3ce
2 changed files with 11 additions and 9 deletions
@@ -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) {
+9 -7
View File
@@ -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',