From e0dfd1608eb52a2f08c1de4d5b6f4d61f66cb527 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Thu, 5 Oct 2017 18:30:51 +0530 Subject: [PATCH] [Fix] Auto add item in the cart if sinfle items found in the serach (#11072) --- .../page/point_of_sale/point_of_sale.js | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) 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 6601b9f47c7..e9ff7b91320 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 @@ class POSItems { 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 @@ class POSItems { } 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");