mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-09 20:51:46 +00:00
Compare commits
8 Commits
pg-audit/c
...
job-card-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c131d5819 | ||
|
|
e042d09975 | ||
|
|
2565a56ade | ||
|
|
3fab303e51 | ||
|
|
6ef498e352 | ||
|
|
9815d90b0f | ||
|
|
fb763848da | ||
|
|
c2654c1380 |
@@ -99,7 +99,8 @@ frappe.ui.form.on("Job Card", {
|
||||
doc.docstatus === 1 &&
|
||||
!doc.is_subcontracted &&
|
||||
(doc.skip_material_transfer || doc.transferred_qty > 0) &&
|
||||
flt(doc.manufactured_qty) + flt(doc.process_loss_qty) < flt(doc.for_quantity);
|
||||
flt(doc.manufactured_qty) + flt(doc.process_loss_qty) <
|
||||
flt(doc.for_quantity) - flt(doc.pending_qty);
|
||||
|
||||
if (!can_make_stock_entry) return;
|
||||
|
||||
@@ -248,6 +249,7 @@ frappe.ui.form.on("Job Card", {
|
||||
change() {
|
||||
const dialog = frm.job_completion_dialog;
|
||||
dialog.set_value("completed_qty", dialog.get_value("for_quantity"));
|
||||
dialog.set_value("pending_qty", 0);
|
||||
dialog.set_value("process_loss_qty", 0);
|
||||
},
|
||||
},
|
||||
@@ -259,8 +261,21 @@ frappe.ui.form.on("Job Card", {
|
||||
default: pending_qty,
|
||||
change() {
|
||||
const dialog = frm.job_completion_dialog;
|
||||
const remaining = dialog.get_value("for_quantity") - dialog.get_value("completed_qty");
|
||||
if (remaining > 0 && remaining != dialog.get_value("pending_qty")) {
|
||||
const remaining =
|
||||
dialog.get_value("for_quantity") -
|
||||
dialog.get_value("completed_qty") -
|
||||
dialog.get_value("process_loss_qty");
|
||||
|
||||
if (remaining < 0) {
|
||||
const max_completed_qty =
|
||||
flt(dialog.get_value("for_quantity")) - flt(dialog.get_value("process_loss_qty"));
|
||||
dialog.set_value("completed_qty", max_completed_qty);
|
||||
frappe.throw(
|
||||
__("Completed Quantity cannot be greater than {0}", [max_completed_qty])
|
||||
);
|
||||
}
|
||||
|
||||
if (remaining != dialog.get_value("pending_qty")) {
|
||||
dialog.set_value("pending_qty", remaining);
|
||||
}
|
||||
},
|
||||
@@ -276,7 +291,18 @@ frappe.ui.form.on("Job Card", {
|
||||
dialog.get_value("for_quantity") -
|
||||
dialog.get_value("completed_qty") -
|
||||
dialog.get_value("pending_qty");
|
||||
if (process_loss_qty >= 0 && process_loss_qty != dialog.get_value("process_loss_qty")) {
|
||||
|
||||
if (process_loss_qty < 0) {
|
||||
dialog.set_value("pending_qty", 0);
|
||||
frappe.throw(
|
||||
__("Pending Quantity cannot be greater than {0}", [
|
||||
flt(dialog.get_value("for_quantity")) -
|
||||
flt(dialog.get_value("completed_qty")),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
if (process_loss_qty != dialog.get_value("process_loss_qty")) {
|
||||
dialog.set_value("process_loss_qty", process_loss_qty);
|
||||
}
|
||||
},
|
||||
@@ -291,7 +317,18 @@ frappe.ui.form.on("Job Card", {
|
||||
dialog.get_value("for_quantity") -
|
||||
dialog.get_value("completed_qty") -
|
||||
dialog.get_value("process_loss_qty");
|
||||
if (remaining >= 0 && remaining != dialog.get_value("pending_qty")) {
|
||||
|
||||
if (remaining < 0) {
|
||||
dialog.set_value("process_loss_qty", 0);
|
||||
frappe.throw(
|
||||
__("Process Loss Quantity cannot be greater than {0}", [
|
||||
flt(dialog.get_value("for_quantity")) -
|
||||
flt(dialog.get_value("completed_qty")),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
if (remaining != dialog.get_value("pending_qty")) {
|
||||
dialog.set_value("pending_qty", remaining);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -944,19 +944,21 @@ class JobCard(Document):
|
||||
return
|
||||
|
||||
precision = self.precision("total_completed_qty")
|
||||
total_completed_qty = flt(
|
||||
accounted_qty = flt(
|
||||
flt(self.total_completed_qty, precision)
|
||||
+ flt(self.process_loss_qty, precision)
|
||||
+ flt(self.pending_qty, precision)
|
||||
)
|
||||
|
||||
if self.for_quantity and flt(total_completed_qty, precision) != flt(self.for_quantity, precision):
|
||||
if self.for_quantity and flt(accounted_qty, precision) != flt(self.for_quantity, precision):
|
||||
frappe.throw(
|
||||
_("The {0} ({1}) must be equal to {2} ({3})").format(
|
||||
bold(_("Total Completed Qty")),
|
||||
bold(flt(total_completed_qty, precision)),
|
||||
bold(_("Qty to Manufacture")),
|
||||
bold(self.for_quantity),
|
||||
_(
|
||||
"Total Completed Qty ({0}), Process Loss Qty ({1}) and Pending Qty ({2}) must add up to the Qty to Manufacture ({3})."
|
||||
).format(
|
||||
bold(flt(self.total_completed_qty, precision)),
|
||||
bold(flt(self.process_loss_qty, precision)),
|
||||
bold(flt(self.pending_qty, precision)),
|
||||
bold(flt(self.for_quantity, precision)),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1310,11 +1312,17 @@ class JobCard(Document):
|
||||
if self.workstation:
|
||||
self.update_workstation_status()
|
||||
|
||||
def get_qty_to_produce(self):
|
||||
"""Qty this job card is expected to produce, the pending qty is left to another job card."""
|
||||
return flt(self.for_quantity) - flt(self.pending_qty)
|
||||
|
||||
def set_finished_good_status(self):
|
||||
# Only reached for a submitted job card (docstatus == 1) with a finished good, see set_status().
|
||||
if (self.manufactured_qty + self.process_loss_qty) >= self.for_quantity:
|
||||
qty_to_produce = self.get_qty_to_produce()
|
||||
|
||||
if (self.manufactured_qty + self.process_loss_qty) >= qty_to_produce:
|
||||
self.status = "Completed"
|
||||
elif (self.total_completed_qty + self.process_loss_qty) >= self.for_quantity:
|
||||
elif (self.total_completed_qty + self.process_loss_qty) >= qty_to_produce:
|
||||
# Production is done and the card is submitted, but the finished goods have not been
|
||||
# booked into stock yet (Manufacture Stock Entry pending) — distinct from active WIP.
|
||||
self.status = "To Manufacture"
|
||||
@@ -1344,7 +1352,7 @@ class JobCard(Document):
|
||||
self.status = "Work In Progress"
|
||||
|
||||
if self.docstatus == 1 and (
|
||||
self.for_quantity <= (self.total_completed_qty + self.process_loss_qty) or not self.items
|
||||
self.get_qty_to_produce() <= (self.total_completed_qty + self.process_loss_qty) or not self.items
|
||||
):
|
||||
self.status = "Completed"
|
||||
|
||||
@@ -1418,15 +1426,46 @@ class JobCard(Document):
|
||||
|
||||
current_operation_qty = self.get_current_operation_completed_qty()
|
||||
|
||||
for row in self.get_previous_operations():
|
||||
if self.track_semi_finished_goods:
|
||||
self.validate_previous_operation_manufactured_qty(row, current_operation_qty)
|
||||
else:
|
||||
self.validate_previous_operation(row, current_operation_qty)
|
||||
|
||||
def get_previous_operations(self):
|
||||
previous_operations = frappe.get_all(
|
||||
"Work Order Operation",
|
||||
fields=["operation", "status", "completed_qty", "sequence_id"],
|
||||
fields=["name", "operation", "status", "completed_qty", "sequence_id"],
|
||||
filters={"docstatus": 1, "parent": self.work_order, "sequence_id": ("<", self.sequence_id)},
|
||||
order_by="sequence_id, idx",
|
||||
)
|
||||
|
||||
for row in previous_operations:
|
||||
self.validate_previous_operation(row, current_operation_qty)
|
||||
if self.track_semi_finished_goods and previous_operations:
|
||||
manufactured_qty = self.get_manufactured_qty_per_operation(
|
||||
[row.name for row in previous_operations]
|
||||
)
|
||||
|
||||
for row in previous_operations:
|
||||
row.manufactured_qty = flt(manufactured_qty.get(row.name))
|
||||
|
||||
return previous_operations
|
||||
|
||||
def get_manufactured_qty_per_operation(self, operation_ids):
|
||||
job_card = frappe.qb.DocType("Job Card")
|
||||
|
||||
data = (
|
||||
frappe.qb.from_(job_card)
|
||||
.select(job_card.operation_id, Sum(job_card.manufactured_qty))
|
||||
.where(
|
||||
(job_card.work_order == self.work_order)
|
||||
& (job_card.docstatus == 1)
|
||||
& (IfNull(job_card.is_corrective_job_card, 0) == 0)
|
||||
& (job_card.operation_id.isin(operation_ids))
|
||||
)
|
||||
.groupby(job_card.operation_id)
|
||||
).run()
|
||||
|
||||
return dict(data)
|
||||
|
||||
def get_current_operation_completed_qty(self):
|
||||
current_operation_qty = 0.0
|
||||
@@ -1462,6 +1501,35 @@ class JobCard(Document):
|
||||
)
|
||||
)
|
||||
|
||||
def validate_previous_operation_manufactured_qty(self, row, current_operation_qty):
|
||||
manufactured_qty = flt(row.manufactured_qty)
|
||||
|
||||
if not manufactured_qty:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Job Card {0}: As per the sequence of the operations in the work order {1}, submit the manufacturing entry for the operation {2} before the operation {3}."
|
||||
).format(
|
||||
bold(self.name),
|
||||
bold(get_link_to_form("Work Order", self.work_order)),
|
||||
bold(row.operation),
|
||||
bold(self.operation),
|
||||
),
|
||||
OperationSequenceError,
|
||||
)
|
||||
|
||||
if manufactured_qty < current_operation_qty:
|
||||
frappe.throw(
|
||||
_(
|
||||
"The completed quantity {0} of an operation {1} cannot be greater than the manufactured quantity {2} of a previous operation {3}. Submit the manufacturing entry for the operation {3} first."
|
||||
).format(
|
||||
bold(current_operation_qty),
|
||||
bold(self.operation),
|
||||
bold(manufactured_qty),
|
||||
bold(row.operation),
|
||||
),
|
||||
OperationSequenceError,
|
||||
)
|
||||
|
||||
def validate_work_order(self):
|
||||
if self.is_work_order_closed():
|
||||
frappe.throw(_("You cannot make any changes to Job Card since Work Order is closed."))
|
||||
@@ -1598,6 +1666,7 @@ class JobCard(Document):
|
||||
kwargs = frappe._dict(kwargs)
|
||||
|
||||
self.validate_complete_job_card_qty(kwargs)
|
||||
self.set_for_quantity(kwargs)
|
||||
|
||||
self.pending_qty = flt(kwargs.pending_qty)
|
||||
self.process_loss_qty = flt(kwargs.process_loss_qty)
|
||||
@@ -1607,6 +1676,14 @@ class JobCard(Document):
|
||||
if kwargs.auto_submit:
|
||||
self.auto_submit_job_card(kwargs.auto_submit)
|
||||
|
||||
def set_for_quantity(self, kwargs):
|
||||
"""Qty to Manufacture of the completion dialog covers the current cycle only,
|
||||
so the qty completed by the earlier cycles of this job card is kept."""
|
||||
if not flt(kwargs.for_quantity):
|
||||
return
|
||||
|
||||
self.for_quantity = flt(self.total_completed_qty) + flt(kwargs.for_quantity)
|
||||
|
||||
def validate_docstatus(self):
|
||||
if self.docstatus == 2:
|
||||
frappe.throw(_("Cancelled Job Card cannot be processed."))
|
||||
@@ -1624,6 +1701,29 @@ class JobCard(Document):
|
||||
if flt(kwargs.pending_qty) and flt(kwargs.pending_qty) > self.for_quantity:
|
||||
frappe.throw(_("Pending quantity cannot be greater than the for quantity."))
|
||||
|
||||
self.validate_completion_qty_split(kwargs)
|
||||
|
||||
def validate_completion_qty_split(self, kwargs):
|
||||
if not flt(kwargs.for_quantity):
|
||||
return
|
||||
|
||||
precision = self.precision("total_completed_qty")
|
||||
accounted_qty = flt(kwargs.qty) + flt(kwargs.pending_qty) + flt(kwargs.process_loss_qty)
|
||||
|
||||
if flt(accounted_qty, precision) == flt(kwargs.for_quantity, precision):
|
||||
return
|
||||
|
||||
frappe.throw(
|
||||
_(
|
||||
"Completed Quantity ({0}), Pending Quantity ({1}) and Process Loss Quantity ({2}) must add up to the Qty to Manufacture ({3})."
|
||||
).format(
|
||||
bold(flt(kwargs.qty, precision)),
|
||||
bold(flt(kwargs.pending_qty, precision)),
|
||||
bold(flt(kwargs.process_loss_qty, precision)),
|
||||
bold(flt(kwargs.for_quantity, precision)),
|
||||
)
|
||||
)
|
||||
|
||||
def add_completion_time_logs(self, kwargs):
|
||||
if kwargs.end_time:
|
||||
self.add_time_logs(
|
||||
@@ -1683,7 +1783,7 @@ class JobCard(Document):
|
||||
|
||||
return ManufactureEntry(
|
||||
{
|
||||
"for_quantity": self.for_quantity - self.manufactured_qty,
|
||||
"for_quantity": self.get_qty_to_produce() - self.manufactured_qty,
|
||||
"process_loss_qty": max(self.process_loss_qty - self.get_consumed_process_loss(), 0),
|
||||
"job_card": self.name,
|
||||
"skip_material_transfer": self.skip_material_transfer,
|
||||
|
||||
@@ -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 (
|
||||
@@ -911,6 +912,74 @@ class TestJobCard(ERPNextTestSuite):
|
||||
self.assertEqual(wo_doc.process_loss_qty, 2)
|
||||
self.assertEqual(wo_doc.status, "Completed")
|
||||
|
||||
def get_first_job_card(self, work_order):
|
||||
return frappe.get_doc(
|
||||
"Job Card",
|
||||
frappe.get_all(
|
||||
"Job Card",
|
||||
filters={"work_order": work_order},
|
||||
order_by="sequence_id, creation",
|
||||
limit=1,
|
||||
pluck="name",
|
||||
)[0],
|
||||
)
|
||||
|
||||
def test_completion_qty_reduces_for_quantity_without_process_loss(self):
|
||||
work_order = make_wo_order_test_record(item="_Test FG Item 2", qty=5)
|
||||
|
||||
job_card = self.get_first_job_card(work_order.name)
|
||||
job_card.append("time_logs", {"from_time": "2024-03-01 08:00:00"})
|
||||
job_card.save()
|
||||
|
||||
job_card.complete_job_card(
|
||||
qty=3,
|
||||
for_quantity=3,
|
||||
pending_qty=0,
|
||||
process_loss_qty=0,
|
||||
end_time="2024-03-01 09:00:00",
|
||||
)
|
||||
|
||||
job_card.reload()
|
||||
self.assertEqual(flt(job_card.for_quantity), 3)
|
||||
self.assertEqual(flt(job_card.total_completed_qty), 3)
|
||||
self.assertEqual(flt(job_card.process_loss_qty), 0)
|
||||
|
||||
def test_completion_qty_keeps_for_quantity_across_cycles(self):
|
||||
work_order = make_wo_order_test_record(item="_Test FG Item 2", qty=5)
|
||||
|
||||
job_card = self.get_first_job_card(work_order.name)
|
||||
job_card.append("time_logs", {"from_time": "2024-03-02 08:00:00"})
|
||||
job_card.save()
|
||||
|
||||
job_card.complete_job_card(
|
||||
qty=3,
|
||||
for_quantity=5,
|
||||
pending_qty=2,
|
||||
process_loss_qty=0,
|
||||
end_time="2024-03-02 09:00:00",
|
||||
)
|
||||
|
||||
job_card.reload()
|
||||
self.assertEqual(flt(job_card.for_quantity), 5)
|
||||
self.assertEqual(flt(job_card.pending_qty), 2)
|
||||
self.assertEqual(flt(job_card.process_loss_qty), 0)
|
||||
|
||||
job_card.append("time_logs", {"from_time": "2024-03-02 10:00:00"})
|
||||
job_card.save()
|
||||
|
||||
job_card.complete_job_card(
|
||||
qty=2,
|
||||
for_quantity=2,
|
||||
pending_qty=0,
|
||||
process_loss_qty=0,
|
||||
end_time="2024-03-02 11:00:00",
|
||||
)
|
||||
|
||||
job_card.reload()
|
||||
self.assertEqual(flt(job_card.for_quantity), 5)
|
||||
self.assertEqual(flt(job_card.total_completed_qty), 5)
|
||||
self.assertEqual(flt(job_card.process_loss_qty), 0)
|
||||
|
||||
def test_op_cost_calculation(self):
|
||||
from erpnext.manufacturing.doctype.routing.test_routing import (
|
||||
create_routing,
|
||||
@@ -1289,6 +1358,225 @@ class TestJobCard(ERPNextTestSuite):
|
||||
8,
|
||||
)
|
||||
|
||||
def test_semi_fg_pending_qty_is_left_to_another_job_card(self):
|
||||
from erpnext.manufacturing.doctype.operation.test_operation import make_operation
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
|
||||
warehouse = "Stores - _TC"
|
||||
rm = make_item("Pending Qty RM 1", {"is_stock_item": 1}).name
|
||||
fg = make_item("Pending Qty FG 1", {"is_stock_item": 1}).name
|
||||
|
||||
fg_bom = frappe.new_doc(
|
||||
"BOM",
|
||||
company="_Test Company",
|
||||
item=fg,
|
||||
quantity=1,
|
||||
with_operations=1,
|
||||
track_semi_finished_goods=1,
|
||||
)
|
||||
fg_bom.append("items", {"item_code": rm, "qty": 1, "operation_row_id": 1})
|
||||
|
||||
operation = {
|
||||
"operation": "Pending Qty Op A",
|
||||
"workstation": "_Test Workstation A",
|
||||
"finished_good": fg,
|
||||
"finished_good_qty": 1,
|
||||
"is_final_finished_good": 1,
|
||||
"sequence_id": 1,
|
||||
"time_in_mins": 60,
|
||||
"source_warehouse": warehouse,
|
||||
"fg_warehouse": warehouse,
|
||||
"skip_material_transfer": 1,
|
||||
}
|
||||
|
||||
make_workstation(operation)
|
||||
make_operation(operation)
|
||||
fg_bom.append("operations", operation)
|
||||
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,
|
||||
)
|
||||
work_order.operations[0].time_in_mins = 60
|
||||
work_order.save()
|
||||
work_order.submit()
|
||||
|
||||
make_stock_entry(item_code=rm, target=warehouse, qty=100, basic_rate=100)
|
||||
|
||||
job_card = self.get_first_job_card(work_order.name)
|
||||
job_card.append("time_logs", {"from_time": "2024-04-01 08:00:00"})
|
||||
job_card.save()
|
||||
|
||||
job_card.complete_job_card(
|
||||
qty=3,
|
||||
for_quantity=5,
|
||||
pending_qty=2,
|
||||
process_loss_qty=0,
|
||||
end_time="2024-04-01 09:00:00",
|
||||
)
|
||||
|
||||
job_card.reload()
|
||||
self.assertEqual(flt(job_card.for_quantity), 5)
|
||||
self.assertEqual(flt(job_card.pending_qty), 2)
|
||||
self.assertEqual(flt(job_card.process_loss_qty), 0)
|
||||
|
||||
job_card.submit()
|
||||
self.assertEqual(job_card.status, "To Manufacture")
|
||||
|
||||
manufacturing_entry = frappe.get_doc(job_card.make_stock_entry_for_semi_fg_item())
|
||||
finished_item = next(row for row in manufacturing_entry.items if row.is_finished_item)
|
||||
self.assertEqual(flt(finished_item.qty), 3)
|
||||
manufacturing_entry.submit()
|
||||
|
||||
job_card.reload()
|
||||
self.assertEqual(flt(job_card.manufactured_qty), 3)
|
||||
self.assertEqual(job_card.status, "Completed")
|
||||
|
||||
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)."""
|
||||
@@ -1940,6 +2228,21 @@ class TestJobCardLogic(ERPNextTestSuite):
|
||||
frappe.ValidationError, jc.validate_complete_job_card_qty, frappe._dict(pending_qty=10)
|
||||
)
|
||||
|
||||
def test_completion_qty_split_must_add_up(self):
|
||||
jc = frappe.new_doc("Job Card")
|
||||
jc.for_quantity = 5
|
||||
|
||||
# 3 completed + 2 pending + 0 lost == 5 to manufacture -> passes
|
||||
jc.validate_complete_job_card_qty(
|
||||
frappe._dict(for_quantity=5, qty=3, pending_qty=2, process_loss_qty=0)
|
||||
)
|
||||
|
||||
self.assertRaises(
|
||||
frappe.ValidationError,
|
||||
jc.validate_complete_job_card_qty,
|
||||
frappe._dict(for_quantity=3, qty=3, pending_qty=2, process_loss_qty=0),
|
||||
)
|
||||
|
||||
def test_completed_qty_must_reconcile_with_for_quantity(self):
|
||||
jc = frappe.new_doc("Job Card")
|
||||
jc.for_quantity = 10
|
||||
|
||||
@@ -796,6 +796,7 @@ class ShopFloor {
|
||||
change() {
|
||||
const d = me.session_dialog;
|
||||
d.set_value("completed_qty", d.get_value("for_quantity"));
|
||||
d.set_value("pending_qty", 0);
|
||||
d.set_value("process_loss_qty", 0);
|
||||
},
|
||||
},
|
||||
@@ -807,8 +808,21 @@ class ShopFloor {
|
||||
default: pending,
|
||||
change() {
|
||||
const d = me.session_dialog;
|
||||
const remaining = flt(d.get_value("for_quantity")) - flt(d.get_value("completed_qty"));
|
||||
if (remaining > 0 && remaining !== flt(d.get_value("pending_qty"))) {
|
||||
const remaining =
|
||||
flt(d.get_value("for_quantity")) -
|
||||
flt(d.get_value("completed_qty")) -
|
||||
flt(d.get_value("process_loss_qty"));
|
||||
|
||||
if (remaining < 0) {
|
||||
const max_completed_qty =
|
||||
flt(d.get_value("for_quantity")) - flt(d.get_value("process_loss_qty"));
|
||||
d.set_value("completed_qty", max_completed_qty);
|
||||
frappe.throw(
|
||||
__("Completed Quantity cannot be greater than {0}", [max_completed_qty])
|
||||
);
|
||||
}
|
||||
|
||||
if (remaining !== flt(d.get_value("pending_qty"))) {
|
||||
d.set_value("pending_qty", remaining);
|
||||
}
|
||||
},
|
||||
@@ -824,7 +838,17 @@ class ShopFloor {
|
||||
flt(d.get_value("for_quantity")) -
|
||||
flt(d.get_value("completed_qty")) -
|
||||
flt(d.get_value("pending_qty"));
|
||||
if (pl >= 0 && pl !== flt(d.get_value("process_loss_qty"))) {
|
||||
|
||||
if (pl < 0) {
|
||||
d.set_value("pending_qty", 0);
|
||||
frappe.throw(
|
||||
__("Pending Quantity cannot be greater than {0}", [
|
||||
flt(d.get_value("for_quantity")) - flt(d.get_value("completed_qty")),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
if (pl !== flt(d.get_value("process_loss_qty"))) {
|
||||
d.set_value("process_loss_qty", pl);
|
||||
}
|
||||
},
|
||||
@@ -840,7 +864,17 @@ class ShopFloor {
|
||||
flt(d.get_value("for_quantity")) -
|
||||
flt(d.get_value("completed_qty")) -
|
||||
flt(d.get_value("process_loss_qty"));
|
||||
if (remaining >= 0 && remaining !== flt(d.get_value("pending_qty"))) {
|
||||
|
||||
if (remaining < 0) {
|
||||
d.set_value("process_loss_qty", 0);
|
||||
frappe.throw(
|
||||
__("Process Loss Quantity cannot be greater than {0}", [
|
||||
flt(d.get_value("for_quantity")) - flt(d.get_value("completed_qty")),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
if (remaining !== flt(d.get_value("pending_qty"))) {
|
||||
d.set_value("pending_qty", remaining);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user