From ca2fb47d445a6cfeacf67fcd5538ed385105dd83 Mon Sep 17 00:00:00 2001 From: noahjacob Date: Wed, 12 May 2021 16:25:07 +0530 Subject: [PATCH] feat: updates item_code filters if item_group is linked to supplier --- erpnext/controllers/queries.py | 15 +++++++++++++-- erpnext/public/js/controllers/buying.js | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index bc1ac5ea069..e71b056c6e2 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -204,7 +204,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals if "description" in searchfields: searchfields.remove("description") - + columns = '' extra_searchfields = [field for field in searchfields if not field in ["name", "item_group", "description"]] @@ -216,11 +216,22 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals if not field in searchfields] searchfields = " or ".join([field + " like %(txt)s" for field in searchfields]) + if filters.get('supplier'): + item_group_list = frappe.get_list('Supplier Item Group', filters = {'supplier': filters.get('supplier')}, fields = ['item_group']) + + item_groups = [] + for i in item_group_list: + item_groups.append(i.item_group) + + del filters['supplier'] + + if item_groups: + filters['item_group'] = ['in', item_groups] + description_cond = '' if frappe.db.count('Item', cache=True) < 50000: # scan description only if items are less than 50000 description_cond = 'or tabItem.description LIKE %(txt)s' - return frappe.db.sql("""select tabItem.name, if(length(tabItem.item_name) > 40, concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name, diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index cdfd909b046..e7dcd410682 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -84,13 +84,13 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ if (me.frm.doc.is_subcontracted == "Yes") { return{ query: "erpnext.controllers.queries.item_query", - filters:{ 'is_sub_contracted_item': 1 } + filters:{ 'supplier': me.frm.doc.supplier, 'is_sub_contracted_item': 1 } } } else { return{ query: "erpnext.controllers.queries.item_query", - filters: {'is_purchase_item': 1} + filters: { 'supplier': me.frm.doc.supplier, 'is_purchase_item': 1 } } } });