diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 78b95f2c80c0..6b2dd77c471b 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -1549,6 +1549,9 @@ def get_scrap_items_from_sub_assemblies(bom_no, company, qty, scrap_items=None): fields=["bom_no", "qty"], order_by="idx asc", ) + # fetch Scrap Items for Parent Bom + items = get_bom_items_as_dict(bom_no, company, qty=qty, fetch_exploded=0, fetch_scrap_items=1) + scrap_items.update(items) for row in bom_items: if not row.bom_no: diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py index 396a0b107d5d..83e722cce50c 100644 --- a/erpnext/manufacturing/doctype/bom/test_bom.py +++ b/erpnext/manufacturing/doctype/bom/test_bom.py @@ -755,6 +755,19 @@ def test_do_not_include_manufacturing_and_fixed_items(self): self.assertTrue("_Test RM Item 2 Fixed Asset Item" not in items) self.assertTrue("_Test RM Item 3 Manufacture Item" in items) + def test_get_scrap_items_from_sub_assemblies(self): + from erpnext.manufacturing.doctype.bom.bom import get_scrap_items_from_sub_assemblies + + bom = frappe.copy_doc(test_records[1]) + bom.insert(ignore_mandatory=True) + + bom_scraped_items = [i.get("item_code") for i in bom.get("scrap_items", [])] + + # get scrapted items for parent bom + scraped_items = get_scrap_items_from_sub_assemblies(bom.name, bom.company, 2, None) + for item_code in scraped_items.keys(): + self.assertIn(item_code, bom_scraped_items, f"Item {item_code} not found in BOM scrap items") + def test_bom_raw_materials_stock_uom(self): rm_item = make_item( properties={"is_stock_item": 1, "valuation_rate": 1000.0, "stock_uom": "Nos"}