diff options
| author | Pedram (PEBR) <pebr@odoo.com> | 2025-01-14 09:21:07 +0100 |
|---|---|---|
| committer | Pedram (PEBR) <pebr@odoo.com> | 2025-02-06 17:59:35 +0000 |
| commit | dead43dafd890d4a95cb368ff0be3e2ae62c8a9b (patch) | |
| tree | 133747175639bba599b6cd3fc7f4175bc25e40d7 | |
| parent | 429a8332b2d99600df75fd73ab78bdeb3a048ad2 (diff) | |
[FIX] point_of_sale: restore category filtering when searching
Before this commit, it wasn't possible to filter products by category
when searching. This functionality was available in previous versions
but was removed during refactoring.
opw-4439314
closes odoo/odoo#193503
Signed-off-by: Adrien Guilliams (adgu) <adgu@odoo.com>
| -rw-r--r-- | addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js b/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js index 3e1e044f976..1b33ea3e402 100644 --- a/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js +++ b/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js @@ -54,6 +54,7 @@ export class ProductScreen extends Component { currentOffset: 0, quantityByProductTmplId: {}, }); + this._searchTriggered = false; onMounted(() => { this.pos.openOpeningControl(); this.pos.addPendingOrder([this.currentOrder.id]); @@ -341,11 +342,18 @@ export class ProductScreen extends Component { let list = []; if (this.searchWord !== "") { + if (!this._searchTriggered) { + this.pos.setSelectedCategory(0); + this._searchTriggered = true; + } list = this.addMainProductsToDisplay(this.getProductsBySearchWord(this.searchWord)); - } else if (this.pos.selectedCategory?.id) { - list = this.getProductsByCategory(this.pos.selectedCategory); } else { - list = this.products; + this._searchTriggered = false; + if (this.pos.selectedCategory?.id) { + list = this.getProductsByCategory(this.pos.selectedCategory); + } else { + list = this.products; + } } if (!list || list.length === 0) { @@ -375,13 +383,17 @@ export class ProductScreen extends Component { getProductsBySearchWord(searchWord) { const words = searchWord.toLowerCase(); - const exactMatches = this.products.filter((product) => product.exactMatch(words)); + const products = this.pos.selectedCategory?.id + ? this.getProductsByCategory(this.pos.selectedCategory) + : this.products; + + const exactMatches = products.filter((product) => product.exactMatch(words)); if (exactMatches.length > 0 && words.length > 2) { return exactMatches; } - const matches = this.products.filter((p) => + const matches = products.filter((p) => unaccent(p.searchString, false).toLowerCase().includes(words) ); |
