From ec392a7bcf4eb46d2bbdbca2649366e26f5c558b Mon Sep 17 00:00:00 2001 From: pandiyan Date: Wed, 2 Sep 2026 10:04:05 +0530 Subject: [PATCH] fix(manufacturing): use item warehouses in production plan work orders (#58663) (cherry picked from commit e74ab38eeb19fd2849caac13bcbb987909ba56c7) # Conflicts: # erpnext/manufacturing/doctype/production_plan/services/work_order_planning.py --- .../production_plan/production_plan.py | 4 +- .../production_plan/test_production_plan.py | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index a9aaedc8894..9b992722fc7 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -929,8 +929,6 @@ class ProductionPlan(Document): wo = frappe.new_doc("Work Order") wo.update(item) - if not wo.source_warehouse: - wo.source_warehouse = item.get("fg_warehouse") wo.reserve_stock = self.reserve_stock wo.planned_start_date = item.get("planned_start_date") or item.get("schedule_date") @@ -939,7 +937,7 @@ class ProductionPlan(Document): wo.fg_warehouse = item.get("warehouse") wo.set_work_order_operations() - wo.set_required_items(reset_source_warehouse=True) + wo.set_required_items() try: wo.flags.ignore_mandatory = True diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py index 34467a516a6..7ba22675724 100644 --- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py @@ -128,6 +128,57 @@ class TestProductionPlan(ERPNextTestSuite): plan.reload() plan.cancel() + def test_subassembly_work_order_uses_raw_material_default_warehouses(self): + raw_material_warehouses = { + make_item( + properties={ + "is_stock_item": 1, + "item_defaults": [ + {"company": "_Test Company", "default_warehouse": "_Test Warehouse - _TC"} + ], + } + ).name: "_Test Warehouse - _TC", + make_item( + properties={ + "is_stock_item": 1, + "item_defaults": [ + {"company": "_Test Company", "default_warehouse": "_Test Warehouse 1 - _TC"} + ], + } + ).name: "_Test Warehouse 1 - _TC", + } + subassembly_item = make_item(properties={"is_stock_item": 1}).name + finished_item = make_item(properties={"is_stock_item": 1}).name + + make_bom(item=subassembly_item, raw_materials=raw_material_warehouses) + make_bom(item=finished_item, raw_materials=[subassembly_item]) + + plan = create_production_plan( + item_code=finished_item, + warehouse="Finished Goods - _TC", + sub_assembly_warehouse="Finished Goods - _TC", + skip_available_sub_assembly_item=1, + skip_getting_mr_items=1, + do_not_submit=1, + ) + plan.get_sub_assembly_items() + plan.save() + plan.submit() + plan.make_work_order() + + work_order_name = frappe.db.get_value( + "Work Order", + {"production_plan": plan.name, "production_item": subassembly_item}, + ) + work_order = frappe.get_doc("Work Order", work_order_name) + + self.assertFalse(work_order.source_warehouse) + self.assertEqual(work_order.fg_warehouse, plan.sub_assembly_warehouse) + self.assertEqual( + {row.item_code: row.source_warehouse for row in work_order.required_items}, + raw_material_warehouses, + ) + def test_production_plan_for_existing_ordered_qty(self): """ - Enable 'ignore_existing_ordered_qty'.