test(manufacturing): add test to validate the transferred raw materials from work order

This commit is contained in:
Sudharsanan11
2026-06-16 16:51:30 +05:30
parent 7e9c1efab7
commit b22096a640

View File

@@ -3631,6 +3631,58 @@ class TestWorkOrder(FrappeTestCase):
self.assertEqual(bin1_at_completion.reserved_qty_for_production, 0)
@change_settings(
"Manufacturing Settings",
{"allow_editing_of_items_and_quantities_in_work_order": 1},
)
def test_manufacture_se_fetches_edited_qty_from_work_order(self):
"""When a raw material qty is edited on the Work Order, the Manufacture Stock Entry
must consume the edited quantity (scaled to fg_completed_qty) from the Work Order,
not the original BOM quantity."""
warehouse = "_Test Warehouse - _TC"
wo_order = make_wo_order_test_record(
item="_Test FG Item", qty=10, skip_transfer=1, source_warehouse=warehouse
)
# edit a required item's qty
wo_order.required_items[0].db_set("required_qty", flt(wo_order.required_items[0].required_qty) + 7)
wo_order.reload()
edited_row = wo_order.required_items[0]
fg_qty = 5
se = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", fg_qty))
se_qty = {row.item_code: row.qty for row in se.items if row.s_warehouse}
precision = frappe.get_precision("Stock Entry Detail", "qty")
expected = flt(edited_row.required_qty / wo_order.qty * fg_qty, precision)
self.assertEqual(flt(se_qty.get(edited_row.item_code)), expected)
@change_settings(
"Manufacturing Settings",
{"allow_editing_of_items_and_quantities_in_work_order": 1},
)
def test_manufacture_se_fetches_item_not_in_bom_from_work_order(self):
"""A raw material that is present on the Work Order but not on the BOM must still be
fetched into the Manufacture Stock Entry, proving items are sourced from the Work
Order's required_items rather than re-derived from the BOM."""
extra_item = make_item(
"_Test WO Extra Raw Material", {"is_stock_item": 1, "valuation_rate": 100}
).name
warehouse = "_Test Warehouse - _TC"
wo_order = make_wo_order_test_record(
item="_Test FG Item", qty=10, skip_transfer=1, source_warehouse=warehouse
)
original_item = wo_order.required_items[0].item_code
wo_order.required_items[0].db_set("item_code", extra_item)
wo_order.reload()
se = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 5))
se_items = [row.item_code for row in se.items if row.s_warehouse]
self.assertIn(extra_item, se_items)
self.assertNotIn(original_item, se_items)
def make_stock_in_entries_and_get_batches(rm_item, source_warehouse, wip_warehouse):
from erpnext.stock.doctype.stock_entry.test_stock_entry import (