2015-06-16 20:24:56 +00:00
|
|
|
# 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
|
|
|
|
|
2018-02-15 05:58:55 +00:00
|
|
|
from six import iteritems
|
|
|
|
|
2015-06-16 20:24:56 +00:00
|
|
|
def execute(filters=None):
|
|
|
|
data = []
|
2015-06-16 20:42:06 +00:00
|
|
|
parents = {
|
2015-07-07 08:29:23 +00:00
|
|
|
"Product Bundle Item": "Product Bundle",
|
2015-06-16 20:42:06 +00:00
|
|
|
"BOM Explosion Item": "BOM",
|
|
|
|
"BOM Item": "BOM"
|
|
|
|
}
|
2015-06-16 20:24:56 +00:00
|
|
|
|
2015-07-07 08:29:23 +00:00
|
|
|
for doctype in ("Product Bundle Item",
|
2015-06-16 20:24:56 +00:00
|
|
|
"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)
|
|
|
|
|
2018-02-15 05:58:55 +00:00
|
|
|
for parent, items in iteritems(all_boms):
|
2015-06-16 20:24:56 +00:00
|
|
|
valid = True
|
2018-02-15 05:58:55 +00:00
|
|
|
for key, item in iteritems(filters):
|
2015-06-16 20:24:56 +00:00
|
|
|
if key != "search_sub_assemblies":
|
|
|
|
if item and item not in items:
|
|
|
|
valid = False
|
|
|
|
|
|
|
|
if valid:
|
2015-06-16 20:42:06 +00:00
|
|
|
data.append((parent, parents[doctype]))
|
2015-06-16 20:24:56 +00:00
|
|
|
|
|
|
|
return [{
|
|
|
|
"fieldname": "parent",
|
|
|
|
"label": "BOM",
|
|
|
|
"width": 200,
|
|
|
|
"fieldtype": "Dynamic Link",
|
|
|
|
"options": "doctype"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname": "doctype",
|
|
|
|
"label": "Type",
|
|
|
|
"width": 200,
|
|
|
|
"fieldtype": "Data"
|
|
|
|
}], data
|