From b45a6bcb882b65c26e01baddb76c11a37a4acb07 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 17 Jun 2015 01:54:56 +0530 Subject: [PATCH 1/3] [report] BOM Search --- erpnext/config/manufacturing.py | 6 +++ erpnext/config/selling.py | 6 +++ erpnext/stock/report/bom_search/__init__.py | 0 erpnext/stock/report/bom_search/bom_search.js | 42 +++++++++++++++++++ .../stock/report/bom_search/bom_search.json | 17 ++++++++ erpnext/stock/report/bom_search/bom_search.py | 42 +++++++++++++++++++ 6 files changed, 113 insertions(+) create mode 100644 erpnext/stock/report/bom_search/__init__.py create mode 100644 erpnext/stock/report/bom_search/bom_search.js create mode 100644 erpnext/stock/report/bom_search/bom_search.json create mode 100644 erpnext/stock/report/bom_search/bom_search.py diff --git a/erpnext/config/manufacturing.py b/erpnext/config/manufacturing.py index c2dacad495..5b51b0f967 100644 --- a/erpnext/config/manufacturing.py +++ b/erpnext/config/manufacturing.py @@ -103,6 +103,12 @@ def get_data(): "name": "Completed Production Orders", "doctype": "Production Order" }, + { + "type": "report", + "is_query_report": True, + "name": "BOM Search", + "doctype": "BOM" + }, ] }, { diff --git a/erpnext/config/selling.py b/erpnext/config/selling.py index 7f8d517ae9..78c73d8822 100644 --- a/erpnext/config/selling.py +++ b/erpnext/config/selling.py @@ -237,6 +237,12 @@ def get_data(): "route": "query-report/Sales Person Target Variance Item Group-Wise", "doctype": "Sales Person", }, + { + "type": "report", + "is_query_report": True, + "name": "BOM Search", + "doctype": "BOM" + }, { "type": "report", "is_query_report": True, diff --git a/erpnext/stock/report/bom_search/__init__.py b/erpnext/stock/report/bom_search/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/stock/report/bom_search/bom_search.js b/erpnext/stock/report/bom_search/bom_search.js new file mode 100644 index 0000000000..e9e763cb88 --- /dev/null +++ b/erpnext/stock/report/bom_search/bom_search.js @@ -0,0 +1,42 @@ +// Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and Contributors and contributors +// For license information, please see license.txt + +frappe.query_reports["BOM Search"] = { + "filters": [ + { + fieldname: "item1", + label: __("Item 1"), + fieldtype: "Link", + options: "Item" + }, + { + fieldname: "item2", + label: __("Item 2"), + fieldtype: "Link", + options: "Item" + }, + { + fieldname: "item3", + label: __("Item 3"), + fieldtype: "Link", + options: "Item" + }, + { + fieldname: "item4", + label: __("Item 4"), + fieldtype: "Link", + options: "Item" + }, + { + fieldname: "item5", + label: __("Item 5"), + fieldtype: "Link", + options: "Item" + }, + { + fieldname: "search_sub_assemblies", + label: __("Search Sub Assemblies"), + fieldtype: "Check", + }, + ] +} diff --git a/erpnext/stock/report/bom_search/bom_search.json b/erpnext/stock/report/bom_search/bom_search.json new file mode 100644 index 0000000000..2857c176d3 --- /dev/null +++ b/erpnext/stock/report/bom_search/bom_search.json @@ -0,0 +1,17 @@ +{ + "add_total_row": 0, + "apply_user_permissions": 0, + "creation": "2015-06-16 15:16:11.930954", + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "is_standard": "Yes", + "modified": "2015-06-16 15:16:29.850834", + "modified_by": "Administrator", + "module": "Stock", + "name": "BOM Search", + "owner": "Administrator", + "ref_doctype": "BOM", + "report_name": "BOM Search", + "report_type": "Script Report" +} \ No newline at end of file diff --git a/erpnext/stock/report/bom_search/bom_search.py b/erpnext/stock/report/bom_search/bom_search.py new file mode 100644 index 0000000000..cf1e339551 --- /dev/null +++ b/erpnext/stock/report/bom_search/bom_search.py @@ -0,0 +1,42 @@ +# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and Contributors and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe, json + +def execute(filters=None): + data = [] + + for doctype in ("Sales BOM Item", + "BOM Explosion Item" if filters.search_sub_assemblies else "BOM Item"): + all_boms = {} + for d in frappe.get_all(doctype, fields=["parent", "item_code"]): + all_boms.setdefault(d.parent, []).append(d.item_code) + + for parent, items in all_boms.iteritems(): + valid = True + for key, item in filters.iteritems(): + if key != "search_sub_assemblies": + if item and item not in items: + valid = False + + if valid: + data.append((parent, doctype[:-5])) + + return [{ + "fieldname": "parent", + "label": "BOM", + "width": 200, + "fieldtype": "Dynamic Link", + "options": "doctype" + }, + { + "fieldname": "doctype", + "label": "Type", + "width": 200, + "fieldtype": "Data" + }], data + + #print json.dumps(all_boms, indent=1) + #columns, data = [], [] + #return columns, data From bf4547ca5fb240fe709aabac8eee78e6c5271e41 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 17 Jun 2015 02:12:06 +0530 Subject: [PATCH 2/3] [fix] dynamic link in BOM Search report --- erpnext/stock/report/bom_search/bom_search.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/report/bom_search/bom_search.py b/erpnext/stock/report/bom_search/bom_search.py index cf1e339551..3e803fb0d2 100644 --- a/erpnext/stock/report/bom_search/bom_search.py +++ b/erpnext/stock/report/bom_search/bom_search.py @@ -6,6 +6,11 @@ import frappe, json def execute(filters=None): data = [] + parents = { + "Sales BOM Item": "Sales BOM", + "BOM Explosion Item": "BOM", + "BOM Item": "BOM" + } for doctype in ("Sales BOM Item", "BOM Explosion Item" if filters.search_sub_assemblies else "BOM Item"): @@ -21,7 +26,7 @@ def execute(filters=None): valid = False if valid: - data.append((parent, doctype[:-5])) + data.append((parent, parents[doctype])) return [{ "fieldname": "parent", From ed9d5cfdafe134013cf24a8cb9b723e2b45b9bb2 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 17 Jun 2015 02:13:03 +0530 Subject: [PATCH 3/3] [minor] cleanup --- erpnext/stock/report/bom_search/bom_search.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/stock/report/bom_search/bom_search.py b/erpnext/stock/report/bom_search/bom_search.py index 3e803fb0d2..b8a7b789e5 100644 --- a/erpnext/stock/report/bom_search/bom_search.py +++ b/erpnext/stock/report/bom_search/bom_search.py @@ -41,7 +41,3 @@ def execute(filters=None): "width": 200, "fieldtype": "Data" }], data - - #print json.dumps(all_boms, indent=1) - #columns, data = [], [] - #return columns, data