feat: updates item_code filters if item_group is linked to supplier

This commit is contained in:
noahjacob 2021-05-12 16:25:07 +05:30
parent 7715441842
commit ca2fb47d44
2 changed files with 15 additions and 4 deletions

View File

@ -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,

View File

@ -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 }
}
}
});