brotherton-erpnext/erpnext/stock/report/bom_search/bom_search.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.0 KiB
Python
Raw Normal View History

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
from frappe import _
2018-02-15 05:58:55 +00:00
2015-06-16 20:24:56 +00:00
def execute(filters=None):
data = []
parents = {
2015-07-07 08:29:23 +00:00
"Product Bundle Item": "Product Bundle",
"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:
data.append((parent, parents[doctype]))
2015-06-16 20:24:56 +00:00
return [
{
"fieldname": "parent",
"label": _("BOM"),
2015-06-16 20:24:56 +00:00
"width": 200,
"fieldtype": "Dynamic Link",
"options": "doctype",
},
{"fieldname": "doctype", "label": _("Type"), "width": 200, "fieldtype": "Data"},
2015-06-16 20:24:56 +00:00
], data