From ca1aeddeee09aaf6d6eee052f33e97b351113e12 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sat, 1 Feb 2025 00:35:12 +0530 Subject: [PATCH] fix: consider process_loss_qty in work order --- .../manufacturing/doctype/job_card/job_card.py | 4 +++- .../doctype/job_card/test_job_card.py | 1 + .../doctype/work_order/work_order.js | 15 ++++++++++++++- .../doctype/work_order/work_order.py | 4 +++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index 82f7df1e000..51053d4c8c9 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -1038,7 +1038,9 @@ class JobCard(Document): if self.time_logs: self.status = "Work In Progress" - if self.docstatus == 1 and (self.for_quantity <= self.total_completed_qty or not self.items): + if self.docstatus == 1 and ( + self.for_quantity <= (self.total_completed_qty + self.process_loss_qty) or not self.items + ): self.status = "Completed" if self.is_paused: diff --git a/erpnext/manufacturing/doctype/job_card/test_job_card.py b/erpnext/manufacturing/doctype/job_card/test_job_card.py index 1c85681f5b1..251235e772f 100644 --- a/erpnext/manufacturing/doctype/job_card/test_job_card.py +++ b/erpnext/manufacturing/doctype/job_card/test_job_card.py @@ -532,6 +532,7 @@ class TestJobCard(IntegrationTestCase): self.assertEqual(jc.status, status) jc = frappe.new_doc("Job Card") + jc.process_loss_qty = 0 jc.for_quantity = 2 jc.transferred_qty = 1 jc.total_completed_qty = 0 diff --git a/erpnext/manufacturing/doctype/work_order/work_order.js b/erpnext/manufacturing/doctype/work_order/work_order.js index b54c33f037a..178134e1792 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -427,7 +427,10 @@ frappe.ui.form.on("Work Order", { message = title; // pending qty if (!frm.doc.skip_transfer) { - var pending_complete = frm.doc.material_transferred_for_manufacturing - frm.doc.produced_qty; + var pending_complete = + frm.doc.material_transferred_for_manufacturing - + frm.doc.produced_qty - + frm.doc.process_loss_qty; if (pending_complete) { var width = (pending_complete / frm.doc.qty) * 100 - added_min; title = __("{0} items in progress", [pending_complete]); @@ -439,6 +442,16 @@ frappe.ui.form.on("Work Order", { message = message + ". " + title; } } + if (frm.doc.process_loss_qty) { + var process_loss_width = (frm.doc.process_loss_qty / frm.doc.qty) * 100; + title = __("{0} items lost during process.", [frm.doc.process_loss_qty]); + bars.push({ + title: title, + width: process_loss_width + "%", + progress_class: "progress-bar-danger", + }); + message = message + ". " + title; + } frm.dashboard.add_progress(__("Status"), bars, message); }, diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index 0630a265eb3..06c3708e9d6 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -1906,7 +1906,9 @@ def close_work_order(work_order, status): work_order = frappe.get_doc("Work Order", work_order) if work_order.get("operations"): job_cards = frappe.get_list( - "Job Card", filters={"work_order": work_order.name, "status": "Work In Progress"}, pluck="name" + "Job Card", + filters={"work_order": work_order.name, "status": "Work In Progress", "docstatus": 1}, + pluck="name", ) if job_cards: -- GitLab