fix: do not make MR against raw materials of available sub assemblies (#40085)
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index fdef8fe..517b2b0 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -1507,19 +1507,17 @@
frappe.throw(_("For row {0}: Enter Planned Qty").format(data.get("idx")))
if bom_no:
- if (
- data.get("include_exploded_items")
- and doc.get("sub_assembly_items")
- and doc.get("skip_available_sub_assembly_item")
- ):
- item_details = get_raw_materials_of_sub_assembly_items(
- item_details,
- company,
- bom_no,
- include_non_stock_items,
- sub_assembly_items,
- planned_qty=planned_qty,
- )
+ if data.get("include_exploded_items") and doc.get("skip_available_sub_assembly_item"):
+ item_details = {}
+ if doc.get("sub_assembly_items"):
+ item_details = get_raw_materials_of_sub_assembly_items(
+ item_details,
+ company,
+ bom_no,
+ include_non_stock_items,
+ sub_assembly_items,
+ planned_qty=planned_qty,
+ )
elif data.get("include_exploded_items") and include_subcontracted_items:
# fetch exploded items from BOM
diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
index 1c748a8..53537f9 100644
--- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
@@ -1232,6 +1232,35 @@
if row.item_code == "SubAssembly2 For SUB Test":
self.assertEqual(row.quantity, 10)
+ def test_sub_assembly_and_their_raw_materials_exists(self):
+ from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom
+
+ bom_tree = {
+ "FG1 For SUB Test": {
+ "SAB1 For SUB Test": {"CP1 For SUB Test": {}},
+ "SAB2 For SUB Test": {},
+ }
+ }
+
+ parent_bom = create_nested_bom(bom_tree, prefix="")
+ for item in ["SAB1 For SUB Test", "SAB2 For SUB Test"]:
+ make_stock_entry(item_code=item, qty=10, rate=100, target="_Test Warehouse - _TC")
+
+ plan = create_production_plan(
+ item_code=parent_bom.item,
+ planned_qty=10,
+ ignore_existing_ordered_qty=1,
+ do_not_submit=1,
+ skip_available_sub_assembly_item=1,
+ warehouse="_Test Warehouse - _TC",
+ )
+
+ items = get_items_for_material_requests(
+ plan.as_dict(), warehouses=[{"warehouse": "_Test Warehouse - _TC"}]
+ )
+
+ self.assertFalse(items)
+
def test_transfer_and_purchase_mrp_for_purchase_uom(self):
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse