From 77154418422074e9c125d6f5505b7891746d7efe Mon Sep 17 00:00:00 2001 From: noahjacob Date: Sun, 9 May 2021 20:02:23 +0530 Subject: [PATCH 1/6] feat: added supplier item group doctype --- .../doctype/supplier_item_group/__init__.py | 0 .../supplier_item_group.js | 8 +++ .../supplier_item_group.json | 51 +++++++++++++++++++ .../supplier_item_group.py | 10 ++++ .../test_supplier_item_group.py | 10 ++++ 5 files changed, 79 insertions(+) create mode 100644 erpnext/buying/doctype/supplier_item_group/__init__.py create mode 100644 erpnext/buying/doctype/supplier_item_group/supplier_item_group.js create mode 100644 erpnext/buying/doctype/supplier_item_group/supplier_item_group.json create mode 100644 erpnext/buying/doctype/supplier_item_group/supplier_item_group.py create mode 100644 erpnext/buying/doctype/supplier_item_group/test_supplier_item_group.py diff --git a/erpnext/buying/doctype/supplier_item_group/__init__.py b/erpnext/buying/doctype/supplier_item_group/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/buying/doctype/supplier_item_group/supplier_item_group.js b/erpnext/buying/doctype/supplier_item_group/supplier_item_group.js new file mode 100644 index 00000000000..f7da90d98d6 --- /dev/null +++ b/erpnext/buying/doctype/supplier_item_group/supplier_item_group.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Supplier Item Group', { + // refresh: function(frm) { + + // } +}); diff --git a/erpnext/buying/doctype/supplier_item_group/supplier_item_group.json b/erpnext/buying/doctype/supplier_item_group/supplier_item_group.json new file mode 100644 index 00000000000..1417ec23cf3 --- /dev/null +++ b/erpnext/buying/doctype/supplier_item_group/supplier_item_group.json @@ -0,0 +1,51 @@ +{ + "actions": [], + "creation": "2021-05-07 18:16:40.621421", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "supplier", + "item_group" + ], + "fields": [ + { + "fieldname": "supplier", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Supplier", + "options": "Supplier" + }, + { + "fieldname": "item_group", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Item Group", + "options": "Item Group" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2021-05-07 18:16:40.621421", + "modified_by": "Administrator", + "module": "Buying", + "name": "Supplier Item Group", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/buying/doctype/supplier_item_group/supplier_item_group.py b/erpnext/buying/doctype/supplier_item_group/supplier_item_group.py new file mode 100644 index 00000000000..6fbeb372429 --- /dev/null +++ b/erpnext/buying/doctype/supplier_item_group/supplier_item_group.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class SupplierItemGroup(Document): + pass diff --git a/erpnext/buying/doctype/supplier_item_group/test_supplier_item_group.py b/erpnext/buying/doctype/supplier_item_group/test_supplier_item_group.py new file mode 100644 index 00000000000..c75044d44eb --- /dev/null +++ b/erpnext/buying/doctype/supplier_item_group/test_supplier_item_group.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +# import frappe +import unittest + +class TestSupplierItemGroup(unittest.TestCase): + pass From ca2fb47d445a6cfeacf67fcd5538ed385105dd83 Mon Sep 17 00:00:00 2001 From: noahjacob Date: Wed, 12 May 2021 16:25:07 +0530 Subject: [PATCH 2/6] 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 } } } }); From 0ab0fcdd51cd4b982c67518217d5ca77fa4ea4f0 Mon Sep 17 00:00:00 2001 From: noahjacob Date: Tue, 18 May 2021 15:21:24 +0530 Subject: [PATCH 3/6] feat: added supplier item group link in supplier dashboard --- erpnext/buying/doctype/supplier/supplier.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/buying/doctype/supplier/supplier.json b/erpnext/buying/doctype/supplier/supplier.json index 4cc5753cbd0..38b8dfdf48d 100644 --- a/erpnext/buying/doctype/supplier/supplier.json +++ b/erpnext/buying/doctype/supplier/supplier.json @@ -383,8 +383,14 @@ "icon": "fa fa-user", "idx": 370, "image_field": "image", - "links": [], - "modified": "2021-01-06 19:51:40.939087", + "links": [ + { + "group": "Item Group", + "link_doctype": "Supplier Item Group", + "link_fieldname": "supplier" + } + ], + "modified": "2021-05-18 15:10:11.087191", "modified_by": "Administrator", "module": "Buying", "name": "Supplier", From 3768216dca811aea0bddcffcf08ef8199c42747d Mon Sep 17 00:00:00 2001 From: noahjacob Date: Wed, 19 May 2021 13:50:35 +0530 Subject: [PATCH 4/6] refactor: updated permissions and mandatory fields --- .../supplier_item_group.json | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/erpnext/buying/doctype/supplier_item_group/supplier_item_group.json b/erpnext/buying/doctype/supplier_item_group/supplier_item_group.json index 1417ec23cf3..1971458f61e 100644 --- a/erpnext/buying/doctype/supplier_item_group/supplier_item_group.json +++ b/erpnext/buying/doctype/supplier_item_group/supplier_item_group.json @@ -14,19 +14,21 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Supplier", - "options": "Supplier" + "options": "Supplier", + "reqd": 1 }, { "fieldname": "item_group", "fieldtype": "Link", "in_list_view": 1, "label": "Item Group", - "options": "Item Group" + "options": "Item Group", + "reqd": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-05-07 18:16:40.621421", + "modified": "2021-05-19 13:48:16.742303", "modified_by": "Administrator", "module": "Buying", "name": "Supplier Item Group", @@ -43,6 +45,30 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Purchase User", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Purchase Manager", + "share": 1, + "write": 1 } ], "sort_field": "modified", From 8e34c49ac9130a7b523c83cb8cc0c005421e545c Mon Sep 17 00:00:00 2001 From: noahjacob Date: Wed, 19 May 2021 13:51:36 +0530 Subject: [PATCH 5/6] refactor: using get_all instead of get_list --- erpnext/controllers/queries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index e71b056c6e2..f5668c51fea 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -217,7 +217,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals 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_group_list = frappe.get_all('Supplier Item Group', filters = {'supplier': filters.get('supplier')}, fields = ['item_group']) item_groups = [] for i in item_group_list: From bf7f0530e6cc14cb7722c767259c0c814fb1a8b8 Mon Sep 17 00:00:00 2001 From: noahjacob Date: Wed, 19 May 2021 13:53:22 +0530 Subject: [PATCH 6/6] fix: added error handling if entry already exists --- .../supplier_item_group/supplier_item_group.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/erpnext/buying/doctype/supplier_item_group/supplier_item_group.py b/erpnext/buying/doctype/supplier_item_group/supplier_item_group.py index 6fbeb372429..3a2e5d6dcef 100644 --- a/erpnext/buying/doctype/supplier_item_group/supplier_item_group.py +++ b/erpnext/buying/doctype/supplier_item_group/supplier_item_group.py @@ -3,8 +3,16 @@ # For license information, please see license.txt from __future__ import unicode_literals -# import frappe +import frappe +from frappe import _ from frappe.model.document import Document class SupplierItemGroup(Document): - pass + def validate(self): + exists = frappe.db.exists({ + 'doctype': 'Supplier Item Group', + 'supplier': self.supplier, + 'item_group': self.item_group + }) + if exists: + frappe.throw(_("Item Group has already been linked to this supplier.")) \ No newline at end of file