POS - search by Item Group
This commit is contained in:
parent
11fc4f85d0
commit
26f6752c1e
@ -7,6 +7,7 @@ import frappe
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_items(price_list, sales_or_purchase, item=None):
|
def get_items(price_list, sales_or_purchase, item=None):
|
||||||
condition = ""
|
condition = ""
|
||||||
|
order_by = ""
|
||||||
args = {"price_list": price_list}
|
args = {"price_list": price_list}
|
||||||
|
|
||||||
if sales_or_purchase == "Sales":
|
if sales_or_purchase == "Sales":
|
||||||
@ -30,16 +31,25 @@ def get_items(price_list, sales_or_purchase, item=None):
|
|||||||
item_code[0]["barcode"] = item
|
item_code[0]["barcode"] = item
|
||||||
return item_code
|
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"] = "%%%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,
|
return frappe.db.sql("""select i.name, i.item_name, i.image,
|
||||||
item_det.price_list_rate, item_det.currency
|
item_det.price_list_rate, item_det.currency
|
||||||
from `tabItem` i LEFT JOIN
|
from `tabItem` i LEFT JOIN
|
||||||
(select item_code, price_list_rate, currency from
|
(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
|
ON
|
||||||
(item_det.item_code=i.name or item_det.item_code=i.variant_of)
|
(item_det.item_code=i.name or item_det.item_code=i.variant_of)
|
||||||
where
|
where
|
||||||
ifnull(i.has_variants, 0) = 0 and
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user