From 26f6752c1e1431d0258f7682887c89b8e93d24a5 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 9 Jun 2015 16:33:46 -0400 Subject: [PATCH] POS - search by Item Group --- erpnext/accounts/doctype/sales_invoice/pos.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index 6047378197..7d5613de27 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -7,6 +7,7 @@ import frappe @frappe.whitelist() def get_items(price_list, sales_or_purchase, item=None): condition = "" + order_by = "" args = {"price_list": price_list} if sales_or_purchase == "Sales": @@ -30,16 +31,25 @@ def get_items(price_list, sales_or_purchase, item=None): item_code[0]["barcode"] = item return item_code - condition += " and (CONCAT(i.name, i.item_name) like %(name)s or (i.variant_of like %(name)s))" + condition += " and ((CONCAT(i.name, i.item_name) like %(name)s) or (i.variant_of like %(name)s) or (i.item_group like %(name)s))" + order_by = """if(locate(%(_name)s, i.name), locate(%(_name)s, i.name), 99999), + if(locate(%(_name)s, i.item_name), locate(%(_name)s, i.item_name), 99999), + if(locate(%(_name)s, i.variant_of), locate(%(_name)s, i.variant_of), 99999), + if(locate(%(_name)s, i.item_group), locate(%(_name)s, i.item_group), 99999),""" args["name"] = "%%%s%%" % item + args["_name"] = item.replace("%", "") + # locate function is used to sort by closest match from the beginning of the value return frappe.db.sql("""select i.name, i.item_name, i.image, item_det.price_list_rate, item_det.currency from `tabItem` i LEFT JOIN (select item_code, price_list_rate, currency from - `tabItem Price` where price_list=%s) item_det + `tabItem Price` where price_list=%(price_list)s) item_det ON (item_det.item_code=i.name or item_det.item_code=i.variant_of) where ifnull(i.has_variants, 0) = 0 and - %s""" % ('%(price_list)s', condition), args, as_dict=1) + {condition} + order by + {order_by} + i.name""".format(condition=condition, order_by=order_by), args, as_dict=1)