fix(stock): allow zero completed quantity and handle process loss in job cards (#59104)

(cherry picked from commit 1d8ce1ee8c)
This commit is contained in:
Afsal Syed
2026-09-16 20:14:32 +05:30
committed by Afsal Syed
parent 0130d287f6
commit 1e862b232c
3 changed files with 19 additions and 1 deletions

View File

@@ -355,6 +355,10 @@ frappe.ui.form.on("Job Card", {
default: frm.doc.for_quantity - frm.doc.total_completed_qty,
},
(data) => {
if (data.qty < 0) {
frappe.throw(__("Completed Quantity cannot be negative"));
}
frm.events.complete_job(frm, "Complete", data.qty);
},
__("Enter Value")

View File

@@ -755,9 +755,10 @@ class JobCard(Document):
def set_process_loss(self):
precision = self.precision("total_completed_qty")
should_set_process_loss = self.total_completed_qty or self.process_loss_qty
self.process_loss_qty = 0.0
if self.total_completed_qty and self.for_quantity > self.total_completed_qty:
if should_set_process_loss and self.for_quantity > self.total_completed_qty:
self.process_loss_qty = flt(self.for_quantity, precision) - flt(
self.total_completed_qty, precision
)

View File

@@ -1157,6 +1157,19 @@ class TestJobCard(FrappeTestCase):
assert_operating_costs(s4, 3, [s, s3])
def test_set_process_loss(self):
nothing_done = frappe.new_doc("Job Card")
nothing_done.for_quantity = 10
nothing_done.total_completed_qty = 0
nothing_done.set_process_loss()
self.assertEqual(nothing_done.process_loss_qty, 0)
all_process_loss = frappe.new_doc("Job Card")
all_process_loss.for_quantity = 10
all_process_loss.process_loss_qty = 10
all_process_loss.set_process_loss()
self.assertEqual(all_process_loss.process_loss_qty, 10)
def create_bom_with_multiple_operations():
"Create a BOM with multiple operations and Material Transfer against Job Card"