From 5e7cf3899bb6d841f4e96f12e8aa08db120b8ab0 Mon Sep 17 00:00:00 2001 From: Bhavan23 Date: Sat, 9 Nov 2024 19:54:50 +0530 Subject: [PATCH 1/3] feat: Add item group filtering for search results --- .../selling/page/point_of_sale/point_of_sale.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 2bb61a6439c..423fd427954 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -92,6 +92,20 @@ def search_by_term(search_term, warehouse, price_list): return {"items": [item]} +def filter_result_items(result, pos_profile): + if result and result.get("items"): + pos_item_groups = frappe.db.get_all("POS Item Group", {"parent": pos_profile}, pluck="item_group") + for i, item in enumerate(result.get("items")): + item_group = frappe.db.get_value( + "Item Group", frappe.db.get_value("Item", item.get("item_code"), "item_group"), "name" + ) + if item_group in pos_item_groups: + continue + else: + if result.get("items"): + result.get("items").pop(i) + + @frappe.whitelist() def get_items(start, page_length, price_list, item_group, pos_profile, search_term=""): warehouse, hide_unavailable_items = frappe.db.get_value( @@ -102,6 +116,7 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te if search_term: result = search_by_term(search_term, warehouse, price_list) or [] + filter_result_items(result, pos_profile) if result: return result From 488b60fc278bd0093056df8ac0b699bd43b139db Mon Sep 17 00:00:00 2001 From: Bhavan23 Date: Sat, 9 Nov 2024 19:55:50 +0530 Subject: [PATCH 2/3] refactor: Relocate doc variable for better scope management --- erpnext/selling/page/point_of_sale/pos_item_selector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/selling/page/point_of_sale/pos_item_selector.js b/erpnext/selling/page/point_of_sale/pos_item_selector.js index b5fa8849d60..0b6f1ce2b67 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_selector.js +++ b/erpnext/selling/page/point_of_sale/pos_item_selector.js @@ -138,7 +138,6 @@ erpnext.PointOfSale.ItemSelector = class { make_search_bar() { const me = this; - const doc = me.events.get_frm().doc; this.$component.find(".search-field").html(""); this.$component.find(".item-group-field").html(""); @@ -163,6 +162,7 @@ erpnext.PointOfSale.ItemSelector = class { me.filter_items(); }, get_query: function () { + const doc = me.events.get_frm().doc; return { query: "erpnext.selling.page.point_of_sale.point_of_sale.item_group_query", filters: { From f072b1266e298b4717443a4b1ae6b17498bb7303 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 12 Nov 2024 11:39:30 +0530 Subject: [PATCH 3/3] refactor: simpler filtering --- erpnext/selling/page/point_of_sale/point_of_sale.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) 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 423fd427954..ec9c9bd35dc 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -35,6 +35,7 @@ def search_by_term(search_term, warehouse, price_list): "description": item_doc.description, "is_stock_item": item_doc.is_stock_item, "item_code": item_doc.name, + "item_group": item_doc.item_group, "item_image": item_doc.image, "item_name": item_doc.item_name, "serial_no": serial_no, @@ -95,15 +96,7 @@ def search_by_term(search_term, warehouse, price_list): def filter_result_items(result, pos_profile): if result and result.get("items"): pos_item_groups = frappe.db.get_all("POS Item Group", {"parent": pos_profile}, pluck="item_group") - for i, item in enumerate(result.get("items")): - item_group = frappe.db.get_value( - "Item Group", frappe.db.get_value("Item", item.get("item_code"), "item_group"), "name" - ) - if item_group in pos_item_groups: - continue - else: - if result.get("items"): - result.get("items").pop(i) + result["items"] = [item for item in result.get("items") if item.get("item_group") in pos_item_groups] @frappe.whitelist()