mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-19 01:18:43 +00:00
test(job_card): cover manufactured qty check across previous operations
Work order with operations A and B at sequence 1 and C at sequence 2, tracking semi finished goods. C stays blocked while A's job card is submitted but its Manufacture entry is missing, and once A is manufactured for 3, C can only be completed for 3.
This commit is contained in:
@@ -10,6 +10,7 @@ from frappe.utils.data import add_to_date, now, today
|
||||
|
||||
from erpnext.manufacturing.doctype.job_card.job_card import (
|
||||
JobCardOverTransferError,
|
||||
OperationSequenceError,
|
||||
OverlapError,
|
||||
)
|
||||
from erpnext.manufacturing.doctype.job_card.mapper import (
|
||||
@@ -1289,6 +1290,144 @@ class TestJobCard(ERPNextTestSuite):
|
||||
8,
|
||||
)
|
||||
|
||||
def test_semi_fg_sequence_needs_previous_operations_manufactured(self):
|
||||
from erpnext.manufacturing.doctype.operation.test_operation import make_operation
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
|
||||
warehouse = "Stores - _TC"
|
||||
rm1 = make_item("Sequence Check RM 1", {"is_stock_item": 1}).name
|
||||
rm2 = make_item("Sequence Check RM 2", {"is_stock_item": 1}).name
|
||||
sfg1 = make_item("Sequence Check SFG 1", {"is_stock_item": 1}).name
|
||||
sfg2 = make_item("Sequence Check SFG 2", {"is_stock_item": 1}).name
|
||||
fg = make_item("Sequence Check FG 1", {"is_stock_item": 1}).name
|
||||
|
||||
semi_fg_boms = {}
|
||||
for semi_fg_item, raw_material in ((sfg1, rm1), (sfg2, rm2)):
|
||||
bom = frappe.new_doc("BOM", company="_Test Company", item=semi_fg_item, quantity=1)
|
||||
bom.append("items", {"item_code": raw_material, "qty": 1})
|
||||
bom.insert()
|
||||
bom.submit()
|
||||
semi_fg_boms[semi_fg_item] = bom.name
|
||||
|
||||
fg_bom = frappe.new_doc(
|
||||
"BOM",
|
||||
company="_Test Company",
|
||||
item=fg,
|
||||
quantity=1,
|
||||
with_operations=1,
|
||||
track_semi_finished_goods=1,
|
||||
)
|
||||
|
||||
operations = [
|
||||
{
|
||||
"operation": "Sequence Check Op A",
|
||||
"finished_good": sfg1,
|
||||
"bom_no": semi_fg_boms[sfg1],
|
||||
"sequence_id": 1,
|
||||
},
|
||||
{
|
||||
"operation": "Sequence Check Op B",
|
||||
"finished_good": sfg2,
|
||||
"bom_no": semi_fg_boms[sfg2],
|
||||
"sequence_id": 1,
|
||||
},
|
||||
{
|
||||
"operation": "Sequence Check Op C",
|
||||
"finished_good": fg,
|
||||
"is_final_finished_good": 1,
|
||||
"sequence_id": 2,
|
||||
},
|
||||
]
|
||||
|
||||
for row in operations:
|
||||
row.update(
|
||||
{
|
||||
"workstation": "_Test Workstation A",
|
||||
"finished_good_qty": 1,
|
||||
"time_in_mins": 60,
|
||||
"source_warehouse": warehouse,
|
||||
"fg_warehouse": warehouse,
|
||||
"skip_material_transfer": 1,
|
||||
}
|
||||
)
|
||||
|
||||
make_workstation(row)
|
||||
make_operation(row)
|
||||
fg_bom.append("operations", row)
|
||||
|
||||
fg_bom.append("items", {"item_code": sfg1, "qty": 1, "operation_row_id": 3})
|
||||
fg_bom.append("items", {"item_code": sfg2, "qty": 1, "operation_row_id": 3})
|
||||
fg_bom.insert()
|
||||
fg_bom.submit()
|
||||
|
||||
work_order = make_wo_order_test_record(
|
||||
item=fg,
|
||||
qty=5,
|
||||
source_warehouse=warehouse,
|
||||
fg_warehouse=warehouse,
|
||||
bom_no=fg_bom.name,
|
||||
skip_transfer=1,
|
||||
do_not_save=True,
|
||||
)
|
||||
|
||||
for row in work_order.operations:
|
||||
row.time_in_mins = 60
|
||||
|
||||
work_order.save()
|
||||
work_order.submit()
|
||||
|
||||
make_stock_entry(item_code=rm1, target=warehouse, qty=10, basic_rate=100)
|
||||
make_stock_entry(item_code=rm2, target=warehouse, qty=10, basic_rate=100)
|
||||
|
||||
def get_job_card(operation):
|
||||
return frappe.get_doc(
|
||||
"Job Card",
|
||||
frappe.db.get_value(
|
||||
"Job Card",
|
||||
{"work_order": work_order.name, "operation": operation, "docstatus": 0},
|
||||
"name",
|
||||
),
|
||||
)
|
||||
|
||||
def add_time_log(job_card, day, qty):
|
||||
job_card.append(
|
||||
"time_logs",
|
||||
{
|
||||
"from_time": f"2024-01-{day} 08:00:00",
|
||||
"to_time": f"2024-01-{day} 09:00:00",
|
||||
"completed_qty": qty,
|
||||
},
|
||||
)
|
||||
|
||||
jc_a = get_job_card("Sequence Check Op A")
|
||||
jc_a.for_quantity = 3
|
||||
add_time_log(jc_a, "01", 3)
|
||||
jc_a.submit()
|
||||
|
||||
jc_b = get_job_card("Sequence Check Op B")
|
||||
add_time_log(jc_b, "02", jc_b.for_quantity)
|
||||
jc_b.submit()
|
||||
frappe.get_doc(jc_b.make_stock_entry_for_semi_fg_item()).submit()
|
||||
|
||||
jc_c = get_job_card("Sequence Check Op C")
|
||||
jc_c.for_quantity = 3
|
||||
add_time_log(jc_c, "03", 3)
|
||||
self.assertRaises(OperationSequenceError, jc_c.save)
|
||||
|
||||
frappe.get_doc(jc_a.make_stock_entry_for_semi_fg_item()).submit()
|
||||
|
||||
jc_c.reload()
|
||||
jc_c.for_quantity = 4
|
||||
add_time_log(jc_c, "03", 4)
|
||||
self.assertRaises(OperationSequenceError, jc_c.save)
|
||||
|
||||
jc_c.reload()
|
||||
jc_c.for_quantity = 3
|
||||
add_time_log(jc_c, "03", 3)
|
||||
jc_c.submit()
|
||||
|
||||
self.assertEqual(jc_c.docstatus, 1)
|
||||
|
||||
def test_semi_fg_batch_auto_pull_on_manufacture(self):
|
||||
"""Batch produced by an operation should auto-pull into the next operation's
|
||||
semi-finished consumption row (skip-transfer Manufacture entry)."""
|
||||
|
||||
Reference in New Issue
Block a user