diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py index 2cb3989b6b55f4d2b83ea61fa8e09be813e7dbdd..efba1498705efdb44306783de3bdf6e8ed12d1d1 100644 --- a/erpnext/manufacturing/doctype/bom/test_bom.py +++ b/erpnext/manufacturing/doctype/bom/test_bom.py @@ -781,7 +781,7 @@ def level_order_traversal(node): return traversal -def create_nested_bom(tree, prefix="_Test bom "): +def create_nested_bom(tree, prefix="_Test bom ", submit=True): """Helper function to create a simple nested bom from tree describing item names. (along with required items)""" def create_items(bom_tree): @@ -815,7 +815,8 @@ def create_nested_bom(tree, prefix="_Test bom "): bom.company = "_Test Company" bom.currency = "INR" bom.insert() - bom.submit() + if submit: + bom.submit() return bom # parent bom is last bom diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py index bf0137b7f2b2225b8b6afb0b6a25108a63d02a38..e6d9bf329e847bd4ed810aa320283ec861008e75 100644 --- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py @@ -1344,6 +1344,79 @@ class TestProductionPlan(FrappeTestCase): self.assertTrue(row.warehouse == mrp_warhouse) self.assertEqual(row.quantity, 12.0) + def test_mr_qty_for_complex_bom(self): + from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom + from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse + + def set_bom_qty(item_code, qtys): + # assumes qtys is in same order as children + bom = frappe.get_doc("BOM", {"item": item_code}) + for i, child in enumerate(bom.items): + child.qty = qtys[i] + bom.submit() + return bom + + bom_tree = { + "Test FG Complex": { + "Test SubAssyL1-1": { # x3 + "Test SubAssyL2-1": { # x2 + "Test SAL2-1 Item1": {}, # x3 + "Test SAL2-1 Item2": {}, # x5 + }, + "Test SubAssyL2-2": { # x7 + "Test SAL2-2 Item1": {}, # x2 + "Test SAL2-2 Item2": {}, # x13 + }, + "Test SAL1-1 Item1": {}, # x6 + }, + "Test SubAssyL1-2": { # x5 + "Test SubAssyL2-3": { # x1 + "Test SAL2-3 Item1": {}, # x4 + "Test SAL2-3 Item2": {}, # x11 + }, + "Test SAL1-2 Item1": {}, # x9 + }, + "Test FG Item1": {}, # x8 + } + } + test_qtys = { + "Test SAL2-1 Item1": 18, + "Test SAL2-1 Item2": 30, + "Test SAL2-2 Item1": 42, + "Test SAL2-2 Item2": 273, + "Test SAL1-1 Item1": 18, + "Test SAL2-3 Item1": 20, + "Test SAL2-3 Item2": 55, + "Test SAL1-2 Item1": 45, + "Test FG Item1": 8, + } + + create_nested_bom(bom_tree, prefix="", submit=False) + # set quantities + set_bom_qty("Test SubAssyL2-1", [3, 5]) + set_bom_qty("Test SubAssyL2-2", [2, 13]) + set_bom_qty("Test SubAssyL2-3", [4, 11]) + + set_bom_qty("Test SubAssyL1-1", [2, 7, 6]) + set_bom_qty("Test SubAssyL1-2", [1, 9]) + + parent_bom = set_bom_qty("Test FG Complex", [3, 5, 8]) + + plan = create_production_plan( + item_code=parent_bom.item, + planned_qty=3, + do_not_submit=1, + warehouse="_Test Warehouse - _TC", + ) + + stock_warehouse = create_warehouse("Stock Warehouse", company="_Test Company") + plan.for_warehouse = stock_warehouse + + items = get_items_for_material_requests(plan.as_dict(), warehouses=[]) + + for row in items: + self.assertEqual(row["quantity"], test_qtys[row["item_code"]] * 3) + def test_mr_qty_for_same_rm_with_different_sub_assemblies(self): from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom