diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 46c73199fbd..d7b5b687da1 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -1408,7 +1408,7 @@ def validate_bom_no(item, bom_no): @frappe.whitelist() -def get_children(parent=None, return_all=True, fetch_phantom_items=False, is_root=False, **filters): +def get_children(parent=None, is_root=False, **filters): if not parent or parent == "BOM": frappe.msgprint(_("Please select a BOM")) return @@ -1420,13 +1420,10 @@ def get_children(parent=None, return_all=True, fetch_phantom_items=False, is_roo bom_doc = frappe.get_cached_doc("BOM", frappe.form_dict.parent) frappe.has_permission("BOM", doc=bom_doc, throw=True) - filters = [["parent", "=", frappe.form_dict.parent]] - if not return_all: - filters.append(["is_phantom_item", "=", cint(fetch_phantom_items)]) bom_items = frappe.get_all( "BOM Item", fields=["item_code", "bom_no as value", "stock_qty", "qty", "is_phantom_item", "bom_no"], - filters=filters, + filters=[["parent", "=", frappe.form_dict.parent]], order_by="idx", ) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index 85a5b79efd2..17ecc66e272 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -1661,23 +1661,6 @@ def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_d ] += d.get("qty") sub_assembly_items = {k[:2]: v for k, v in sub_assembly_items.items()} - data = [] - for row in doc.get("po_items"): - get_sub_assembly_items( - [], - frappe._dict(), - row.get("bom_no"), - data, - row.get("planned_qty"), - doc.get("company"), - warehouse=doc.get("sub_assembly_warehouse"), - skip_available_sub_assembly_item=doc.get("skip_available_sub_assembly_item"), - fetch_phantom_items=True, - ) - - for d in data: - sub_assembly_items[(d.get("production_item"), d.get("bom_no"))] += d.get("stock_qty") - for data in po_items: if not data.get("include_exploded_items") and doc.get("sub_assembly_items"): data["include_exploded_items"] = 1 @@ -1896,9 +1879,8 @@ def get_sub_assembly_items( warehouse=None, indent=0, skip_available_sub_assembly_item=False, - fetch_phantom_items=False, ): - data = get_bom_children(parent=bom_no, return_all=False, fetch_phantom_items=fetch_phantom_items) + data = get_bom_children(parent=bom_no) for d in data: if d.expandable: parent_item_code = frappe.get_cached_value("BOM", bom_no, "item") @@ -1921,31 +1903,32 @@ def get_sub_assembly_items( elif warehouse: bin_details.setdefault(d.item_code, get_bin_details(d, company, for_warehouse=warehouse)) - bom_data.append( - frappe._dict( - { - "actual_qty": bin_details[d.item_code][0].get("actual_qty", 0) - if bin_details.get(d.item_code) - else 0, - "parent_item_code": parent_item_code, - "description": d.description, - "production_item": d.item_code, - "item_name": d.item_name, - "stock_uom": d.stock_uom, - "uom": d.stock_uom, - "bom_no": d.value, - "is_sub_contracted_item": d.is_sub_contracted_item, - "bom_level": indent, - "indent": indent, - "stock_qty": stock_qty, - "required_qty": required_qty, - "projected_qty": bin_details[d.item_code][0].get("projected_qty", 0) - if bin_details.get(d.item_code) - else 0, - "main_bom": bom_no, - } + if not d.is_phantom_item: + bom_data.append( + frappe._dict( + { + "actual_qty": bin_details[d.item_code][0].get("actual_qty", 0) + if bin_details.get(d.item_code) + else 0, + "parent_item_code": parent_item_code, + "description": d.description, + "production_item": d.item_code, + "item_name": d.item_name, + "stock_uom": d.stock_uom, + "uom": d.stock_uom, + "bom_no": d.value, + "is_sub_contracted_item": d.is_sub_contracted_item, + "bom_level": indent, + "indent": indent, + "stock_qty": stock_qty, + "required_qty": required_qty, + "projected_qty": bin_details[d.item_code][0].get("projected_qty", 0) + if bin_details.get(d.item_code) + else 0, + "main_bom": bom_no, + } + ) ) - ) if d.value: get_sub_assembly_items( @@ -1958,7 +1941,6 @@ def get_sub_assembly_items( warehouse, indent=indent + 1, skip_available_sub_assembly_item=skip_available_sub_assembly_item, - fetch_phantom_items=fetch_phantom_items, ) diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py index 22738c5f639..03ff4beb339 100644 --- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py @@ -2422,9 +2422,17 @@ class TestProductionPlan(IntegrationTestCase): self.assertEqual(row.ordered_qty, 10.0) def test_phantom_bom_explosion(self): - from erpnext.manufacturing.doctype.bom.test_bom import create_tree_for_phantom_bom_tests + from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom - create_tree_for_phantom_bom_tests() + bom_tree_1 = { + "Top Level Parent": { + "Sub Assembly Level 1-1": {"Phantom Item Level 1-2": {"Item Level 1-3": {}}}, + "Phantom Item Level 2-1": {"Sub Assembly Level 2-2": {"Item Level 2-3": {}}}, + "Item Level 3-1": {}, + } + } + phantom_list = ["Phantom Item Level 1-2", "Phantom Item Level 2-1"] + create_nested_bom(bom_tree_1, prefix="", phantom_items=phantom_list) plan = create_production_plan( item_code="Top Level Parent", @@ -2442,8 +2450,13 @@ class TestProductionPlan(IntegrationTestCase): for d in mr_items: plan.append("mr_items", d) - self.assertEqual(plan.sub_assembly_items[0].production_item, "Sub Assembly Level 1-1") - self.assertEqual([item.item_code for item in plan.mr_items], ["Item Level 1-3", "Item Level 2-3"]) + self.assertEqual( + [item.production_item for item in plan.sub_assembly_items], + ["Sub Assembly Level 1-1", "Sub Assembly Level 2-2"], + ) + self.assertEqual( + [item.item_code for item in plan.mr_items], ["Item Level 1-3", "Item Level 2-3", "Item Level 3-1"] + ) def create_production_plan(**args):