From 3f309e1c205dbd62924e231447e1741a8dbfeff0 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 11 Oct 2017 02:07:09 +0530 Subject: [PATCH] Multiple items showing for single barcode --- .../selling/page/point_of_sale/point_of_sale.js | 2 +- .../selling/page/point_of_sale/point_of_sale.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 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 1c43e3970c3..8bbbc3fa63c 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -107,7 +107,7 @@ erpnext.pos.PointOfSale = class PointOfSale { } }); - this.payment.set_title() + this.payment.set_title(); } this.payment.open_modal(); } diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py index 5694ad9af2f..b92c6530302 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -9,6 +9,8 @@ from frappe.utils.nestedset import get_root_of def get_items(start, page_length, price_list, item_group, search_value=""): serial_no = "" batch_no = "" + barcode = "" + item_code = search_value if not frappe.db.exists('Item Group', item_group): item_group = get_root_of('Item Group') @@ -24,7 +26,12 @@ def get_items(start, page_length, price_list, item_group, search_value=""): if batch_no_data: batch_no, item_code = batch_no_data - item_code, condition = get_conditions(item_code, serial_no, batch_no) + if not serial_no and not batch_no: + barcode_data = frappe.db.get_value('Item', {'barcode': search_value}, ['name', 'barcode']) + if barcode_data: + item_code, barcode = barcode_data + + item_code, condition = get_conditions(item_code, serial_no, batch_no, barcode) lft, rgt = frappe.db.get_value('Item Group', item_group, ['lft', 'rgt']) # locate function is used to sort by closest match from the beginning of the value @@ -62,12 +69,12 @@ def get_items(start, page_length, price_list, item_group, search_value=""): return res -def get_conditions(item_code, serial_no, batch_no): - if serial_no or batch_no: +def get_conditions(item_code, serial_no, batch_no, barcode): + if serial_no or batch_no or barcode: return frappe.db.escape(item_code), "i.item_code = %(item_code)s" condition = """(i.item_code like %(item_code)s - or i.item_name like %(item_code)s or i.barcode like %(item_code)s)""" + or i.item_name like %(item_code)s)""" return '%%%s%%'%(frappe.db.escape(item_code)), condition