[Fix] Auto add item in the cart if sinfle items found in the serach (#11072)
diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.js b/erpnext/selling/page/point_of_sale/point_of_sale.js
index 6601b9f..e9ff7b9 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.js
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.js
@@ -948,6 +948,7 @@
if (this.search_index[search_term]) {
const items = this.search_index[search_term];
this.render_items(items);
+ this.set_item_in_the_cart(items);
return;
}
} else if (item_group == "All Item Groups") {
@@ -961,19 +962,32 @@
}
this.render_items(items);
- if(serial_no) {
- this.events.update_cart(items[0].item_code,
- 'serial_no', serial_no);
- this.reset_search_field();
- }
- if(batch_no) {
- this.events.update_cart(items[0].item_code,
- 'batch_no', batch_no);
- this.reset_search_field();
- }
+ this.set_item_in_the_cart(items, serial_no, batch_no);
});
}
+ set_item_in_the_cart(items, serial_no, batch_no) {
+ if (serial_no) {
+ this.events.update_cart(items[0].item_code,
+ 'serial_no', serial_no);
+ this.reset_search_field();
+ return;
+ }
+
+ if (batch_no) {
+ this.events.update_cart(items[0].item_code,
+ 'batch_no', batch_no);
+ this.reset_search_field();
+ return;
+ }
+
+ if (items.length === 1) {
+ this.events.update_cart(items[0].item_code,
+ 'qty', '+1');
+ this.reset_search_field();
+ }
+ }
+
reset_search_field() {
this.search_field.set_value('');
this.search_field.$input.trigger("input");