Merge pull request #30674 from marination/work-order-partial-transfer
fix: Handle multiple item transfer in separate SEs against WO
This commit is contained in:
commit
014298a867
@ -1144,6 +1144,56 @@ class TestWorkOrder(FrappeTestCase):
|
||||
for index, row in enumerate(ste_manu.get("items"), start=1):
|
||||
self.assertEqual(index, row.idx)
|
||||
|
||||
@change_settings(
|
||||
"Manufacturing Settings",
|
||||
{"backflush_raw_materials_based_on": "Material Transferred for Manufacture"},
|
||||
)
|
||||
def test_work_order_multiple_material_transfer(self):
|
||||
"""
|
||||
Test transferring multiple RMs in separate Stock Entries.
|
||||
"""
|
||||
work_order = make_wo_order_test_record(planned_start_date=now(), qty=1)
|
||||
test_stock_entry.make_stock_entry( # stock up RM
|
||||
item_code="_Test Item",
|
||||
target="_Test Warehouse - _TC",
|
||||
qty=1,
|
||||
basic_rate=5000.0,
|
||||
)
|
||||
test_stock_entry.make_stock_entry( # stock up RM
|
||||
item_code="_Test Item Home Desktop 100",
|
||||
target="_Test Warehouse - _TC",
|
||||
qty=2,
|
||||
basic_rate=1000.0,
|
||||
)
|
||||
|
||||
transfer_entry = frappe.get_doc(
|
||||
make_stock_entry(work_order.name, "Material Transfer for Manufacture", 1)
|
||||
)
|
||||
del transfer_entry.get("items")[0] # transfer only one RM
|
||||
transfer_entry.submit()
|
||||
|
||||
# WO's "Material Transferred for Mfg" shows all is transferred, one RM is pending
|
||||
work_order.reload()
|
||||
self.assertEqual(work_order.material_transferred_for_manufacturing, 1)
|
||||
self.assertEqual(work_order.required_items[0].transferred_qty, 0)
|
||||
self.assertEqual(work_order.required_items[1].transferred_qty, 2)
|
||||
|
||||
final_transfer_entry = frappe.get_doc( # transfer last RM with For Quantity = 0
|
||||
make_stock_entry(work_order.name, "Material Transfer for Manufacture", 0)
|
||||
)
|
||||
final_transfer_entry.save()
|
||||
|
||||
self.assertEqual(final_transfer_entry.fg_completed_qty, 0.0)
|
||||
self.assertEqual(final_transfer_entry.items[0].qty, 1)
|
||||
|
||||
final_transfer_entry.submit()
|
||||
work_order.reload()
|
||||
|
||||
# WO's "Material Transferred for Mfg" shows all is transferred, no RM is pending
|
||||
self.assertEqual(work_order.material_transferred_for_manufacturing, 1)
|
||||
self.assertEqual(work_order.required_items[0].transferred_qty, 1)
|
||||
self.assertEqual(work_order.required_items[1].transferred_qty, 2)
|
||||
|
||||
|
||||
def update_job_card(job_card, jc_qty=None):
|
||||
employee = frappe.db.get_value("Employee", {"status": "Active"}, "name")
|
||||
|
@ -540,8 +540,10 @@ erpnext.work_order = {
|
||||
|| frm.doc.transfer_material_against == 'Job Card') ? 0 : 1;
|
||||
|
||||
if (show_start_btn) {
|
||||
if ((flt(doc.material_transferred_for_manufacturing) < flt(doc.qty))
|
||||
&& frm.doc.status != 'Stopped') {
|
||||
let pending_to_transfer = frm.doc.required_items.some(
|
||||
item => flt(item.transferred_qty) < flt(item.required_qty)
|
||||
);
|
||||
if (pending_to_transfer && frm.doc.status != 'Stopped') {
|
||||
frm.has_start_btn = true;
|
||||
frm.add_custom_button(__('Create Pick List'), function() {
|
||||
erpnext.work_order.create_pick_list(frm);
|
||||
|
@ -1186,7 +1186,11 @@ def make_stock_entry(work_order_id, purpose, qty=None):
|
||||
stock_entry.from_bom = 1
|
||||
stock_entry.bom_no = work_order.bom_no
|
||||
stock_entry.use_multi_level_bom = work_order.use_multi_level_bom
|
||||
stock_entry.fg_completed_qty = qty or (flt(work_order.qty) - flt(work_order.produced_qty))
|
||||
# accept 0 qty as well
|
||||
stock_entry.fg_completed_qty = (
|
||||
qty if qty is not None else (flt(work_order.qty) - flt(work_order.produced_qty))
|
||||
)
|
||||
|
||||
if work_order.bom_no:
|
||||
stock_entry.inspection_required = frappe.db.get_value(
|
||||
"BOM", work_order.bom_no, "inspection_required"
|
||||
|
@ -1803,7 +1803,9 @@ class StockEntry(StockController):
|
||||
or (desire_to_transfer > 0 and backflush_based_on == "Material Transferred for Manufacture")
|
||||
or allow_overproduction
|
||||
):
|
||||
item_dict[item]["qty"] = desire_to_transfer
|
||||
# "No need for transfer but qty still pending to transfer" case can occur
|
||||
# when transferring multiple RM in different Stock Entries
|
||||
item_dict[item]["qty"] = desire_to_transfer if (desire_to_transfer > 0) else pending_to_issue
|
||||
elif pending_to_issue > 0:
|
||||
item_dict[item]["qty"] = pending_to_issue
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user