Skip to content
Snippets Groups Projects
Commit b55bc6fd authored by Joseph Caburnay's avatar Joseph Caburnay
Browse files

[FIX] point_of_sale: add product on single search result


In this commit, we restore the following behavior from v13: when search
resulted to a single product and 'Enter' key is pressed, the product is
added to the order and the search field is cleared. This works for both
manual keyboard input and barcode input.

closes odoo/odoo#59765

X-original-commit: 225e3898f25ddac061be99c43501c99d4bd3226b
Signed-off-by: default avatarJoseph Caburnay (jcb) <caburj@users.noreply.github.com>
parent c1b8c1d8
Branches
Tags
No related merge requests found
......@@ -15,6 +15,7 @@ odoo.define('point_of_sale.ProductsWidget', function(require) {
super(...arguments);
useListener('switch-category', this._switchCategory);
useListener('update-search', this._updateSearch);
useListener('try-add-product', this._tryAddProduct);
useListener('clear-search', this._clearSearch);
this.state = useState({ searchWord: '' });
}
......@@ -63,6 +64,18 @@ odoo.define('point_of_sale.ProductsWidget', function(require) {
_updateSearch(event) {
this.state.searchWord = event.detail;
}
_tryAddProduct(event) {
const searchResults = this.productsToDisplay;
// If the search result contains one item, add the product and clear the search.
if (searchResults.length === 1) {
const { searchWordInput } = event.detail;
this.trigger('click-product', searchResults[0]);
// the value of the input element is not linked to the searchWord state,
// so we clear both the state and the element's value.
searchWordInput.el.value = '';
this._clearSearch();
}
}
_clearSearch() {
this.state.searchWord = '';
}
......
......@@ -9,7 +9,6 @@ odoo.define('point_of_sale.ProductsWidgetControlPanel', function(require) {
class ProductsWidgetControlPanel extends PosComponent {
constructor() {
super(...arguments);
this.searchTimeout = null;
this.searchWordInput = useRef('search-word-input');
this.updateSearch = debounce(this.updateSearch, 100);
}
......@@ -19,6 +18,11 @@ odoo.define('point_of_sale.ProductsWidgetControlPanel', function(require) {
}
updateSearch(event) {
this.trigger('update-search', event.target.value);
if (event.key === 'Enter') {
// We are passing the searchWordInput ref so that when necessary,
// it can be modified by the parent.
this.trigger('try-add-product', { searchWordInput: this.searchWordInput });
}
}
}
ProductsWidgetControlPanel.template = 'ProductsWidgetControlPanel';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment