refactor(subcontracting): dedup validate_manufacture consumption checks

The `skip_transfer` and transfer branches of `validate_manufacture` ran the
same per-item validation loop — look the row up or throw "not a part of",
check overconsumption, guard against duplicates, record — differing only in
the data source (SCIO Received Item vs Work Order Item), the available-qty
basis, the source-warehouse check (skip_transfer only) and the message text.

Split each branch into a small method that builds a normalised
`{item_code: {consumed_qty, available_qty}}` lookup, and share the loop via
`_validate_customer_provided_consumption`. Branch-specific throw messages are
passed as callbacks so the user-facing strings (and their translations) are
unchanged, and the order in which checks fire is preserved. Also drops the
unused `name` column from the skip_transfer query.

Adds a test for the non-skip-transfer manufacture flow (Material Transfer for
Manufacture -> Manufacture), which exercises the Work Order branch that the
existing suite — all of whose manufacture tests set skip_transfer=1 — never
covered. Full subcontracting-inward suite passes on MariaDB and PostgreSQL.
This commit is contained in:
Mihir Kandoi
2026-06-22 08:09:09 +05:30
parent 23f1fc6235
commit b129daedc8
2 changed files with 142 additions and 110 deletions

View File

@@ -330,6 +330,31 @@ class IntegrationTestSubcontractingInwardOrder(ERPNextTestSuite):
self.assertEqual(scio.items[0].delivered_qty, 2)
self.assertEqual(scio.items[0].returned_qty, 1)
def test_manufacture_consumption_validates_against_work_order(self):
"""Cover the non-skip-transfer manufacture path, where consumption is validated
against the Work Order's transferred quantity (the Work Order branch of
validate_manufacture)."""
so, scio = create_so_scio()
frappe.new_doc("Stock Entry").update(scio.make_rm_stock_entry_inward()).submit()
scio.reload()
wo = frappe.get_doc("Work Order", scio.make_work_order()[0])
wo.wip_warehouse = "Work In Progress - _TC"
next(
item for item in wo.required_items if item.item_code == "Self RM"
).source_warehouse = "Stores - _TC"
wo.submit()
frappe.new_doc("Stock Entry").update(
make_stock_entry_from_wo(wo.name, "Material Transfer for Manufacture")
).submit()
manufacture = frappe.new_doc("Stock Entry").update(make_stock_entry_from_wo(wo.name, "Manufacture"))
manufacture.submit()
scio.reload()
self.assertEqual(scio.items[0].produced_qty, 5)
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_delivery_of_overproduced_qty": 1})
@ERPNextTestSuite.change_settings(
"Manufacturing Settings", {"overproduction_percentage_for_work_order": 20}