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
|
|
|
|
|
|
|
|
|
|
|
|
import frappe
|
2022-04-02 11:26:59 +00:00
|
|
|
from frappe import _
|
2018-02-15 05:58:55 +00:00
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
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 all_boms.items():
|
2015-06-16 20:24:56 +00:00
|
|
|
valid = True
|
2018-02-15 05:58:55 +00:00
|
|
|
for key, item in filters.items():
|
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",
|
2022-04-02 11:26:59 +00:00
|
|
|
"label": _("BOM"),
|
2015-06-16 20:24:56 +00:00
|
|
|
"width": 200,
|
|
|
|
"fieldtype": "Dynamic Link",
|
|
|
|
"options": "doctype",
|
|
|
|
},
|
2022-04-02 11:26:59 +00:00
|
|
|
{"fieldname": "doctype", "label": _("Type"), "width": 200, "fieldtype": "Data"},
|
2015-06-16 20:24:56 +00:00
|
|
|
], data
|