From 4e88157ed78562d5e0ac752d9ee70f6ec8613030 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 2 Jul 2026 00:02:50 +0530 Subject: [PATCH] test: stock raw materials before manufacture to avoid negative stock in CI --- .../test_production_plan_summary.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/erpnext/manufacturing/report/production_plan_summary/test_production_plan_summary.py b/erpnext/manufacturing/report/production_plan_summary/test_production_plan_summary.py index 44901b63da8..fc47a3065d1 100644 --- a/erpnext/manufacturing/report/production_plan_summary/test_production_plan_summary.py +++ b/erpnext/manufacturing/report/production_plan_summary/test_production_plan_summary.py @@ -7,6 +7,7 @@ from erpnext.manufacturing.doctype.production_plan.test_production_plan import c from erpnext.manufacturing.doctype.work_order.mapper import make_stock_entry as make_se_from_wo from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record from erpnext.manufacturing.report.production_plan_summary.production_plan_summary import execute +from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.tests.utils import ERPNextTestSuite @@ -38,6 +39,17 @@ class TestProductionPlanSummary(ERPNextTestSuite): wo.submit() return wo + def stock_required_materials(self, wo): + # make sure every raw material is available in its source warehouse before manufacturing, + # otherwise a clean database raises NegativeStockError + for item in wo.required_items: + make_stock_entry( + item_code=item.item_code, + to_warehouse=item.source_warehouse or "_Test Warehouse - _TC", + qty=item.required_qty + 10, + rate=100, + ) + def get_work_order_row(self, data, item_code): for row in data: if row.get("item_code") == item_code and row.get("document_type") == "Work Order": @@ -84,6 +96,7 @@ class TestProductionPlanSummary(ERPNextTestSuite): """Producing part of the work order updates produced and pending quantities.""" plan = self.make_plan(planned_qty=2) wo = self.make_submitted_work_order(plan, qty=2) + self.stock_required_materials(wo) se = frappe.get_doc(make_se_from_wo(wo.name, "Manufacture", 1)) se.submit()