brotherton-erpnext/erpnext/stock/report/bom_search/bom_search.py
Chillar Anand 915b34391c
chore: Clean up imports (#27302)
* chore: Added isort to pre-commit config

* chore: Sort imports with isort

* chore: Clean up imports with pycln

* chore: Sort imports with isort

* chore: Fix import issues

* chore: Clean up sider issues

* chore: Remove import errors from flake8 ignore list

* chore: Clean up lint issues
2021-09-02 16:44:59 +05:30

47 lines
1.1 KiB
Python

# 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
from six import iteritems
def execute(filters=None):
data = []
parents = {
"Product Bundle Item": "Product Bundle",
"BOM Explosion Item": "BOM",
"BOM Item": "BOM"
}
for doctype in ("Product Bundle 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 iteritems(all_boms):
valid = True
for key, item in iteritems(filters):
if key != "search_sub_assemblies":
if item and item not in items:
valid = False
if valid:
data.append((parent, parents[doctype]))
return [{
"fieldname": "parent",
"label": "BOM",
"width": 200,
"fieldtype": "Dynamic Link",
"options": "doctype"
},
{
"fieldname": "doctype",
"label": "Type",
"width": 200,
"fieldtype": "Data"
}], data