feat: make Material Request for sub-assembly items
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index 1eb82a5..0cc0f80 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -521,6 +521,9 @@
subcontracted_po.setdefault(row.supplier, []).append(row)
continue
+ if row.type_of_manufacturing == "Material Request":
+ continue
+
work_order_data = {
"wip_warehouse": default_warehouses.get("wip_warehouse"),
"fg_warehouse": default_warehouses.get("fg_warehouse"),
@@ -1161,6 +1164,7 @@
subquery = frappe.qb.from_(wh).select(wh.name).where(wh.company == company)
+ warehouse = ""
if not all_warehouse:
warehouse = for_warehouse or row.get("source_warehouse") or row.get("default_warehouse")
@@ -1226,6 +1230,21 @@
doc["mr_items"] = []
po_items = doc.get("po_items") if doc.get("po_items") else doc.get("items")
+
+ if doc.get("sub_assembly_items"):
+ for sa_row in doc.sub_assembly_items:
+ sa_row = frappe._dict(sa_row)
+ if sa_row.type_of_manufacturing == "Material Request":
+ po_items.append(
+ frappe._dict(
+ {
+ "item_code": sa_row.production_item,
+ "required_qty": sa_row.qty,
+ "include_exploded_items": 0,
+ }
+ )
+ )
+
# Check for empty table or empty rows
if not po_items or not [row.get("item_code") for row in po_items if row.get("item_code")]:
frappe.throw(
diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
index a6d034d..2bf14c2 100644
--- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
@@ -840,6 +840,34 @@
self.assertEqual(row.uom, "Nos")
self.assertEqual(row.qty, 1)
+ def test_material_request_for_sub_assembly_items(self):
+ from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom
+
+ bom_tree = {
+ "Fininshed Goods1 For MR": {
+ "SubAssembly1 For MR": {"SubAssembly1-1 For MR": {"ChildPart1 For MR": {}}}
+ }
+ }
+
+ parent_bom = create_nested_bom(bom_tree, prefix="")
+ plan = create_production_plan(
+ item_code=parent_bom.item, planned_qty=10, ignore_existing_ordered_qty=1, do_not_submit=1
+ )
+
+ plan.get_sub_assembly_items()
+
+ mr_items = []
+ for row in plan.sub_assembly_items:
+ mr_items.append(row.production_item)
+ row.type_of_manufacturing = "Material Request"
+
+ plan.save()
+ items = get_items_for_material_requests(plan.as_dict())
+
+ validate_mr_items = [d.get("item_code") for d in items]
+ for item_code in mr_items:
+ self.assertTrue(item_code in validate_mr_items)
+
def create_production_plan(**args):
"""
diff --git a/erpnext/manufacturing/doctype/production_plan_sub_assembly_item/production_plan_sub_assembly_item.json b/erpnext/manufacturing/doctype/production_plan_sub_assembly_item/production_plan_sub_assembly_item.json
index 45ea26c..4eb6bf6 100644
--- a/erpnext/manufacturing/doctype/production_plan_sub_assembly_item/production_plan_sub_assembly_item.json
+++ b/erpnext/manufacturing/doctype/production_plan_sub_assembly_item/production_plan_sub_assembly_item.json
@@ -169,7 +169,7 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Manufacturing Type",
- "options": "In House\nSubcontract"
+ "options": "In House\nSubcontract\nMaterial Request"
},
{
"fieldname": "supplier",
@@ -188,7 +188,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
- "modified": "2022-01-30 21:31:10.527559",
+ "modified": "2022-11-28 13:50:15.116082",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Plan Sub Assembly Item",