Merge pull request #35148 from rohitwaghchaure/fixed-extra-job-card-quantity-issue
fix: over production percentage not considered in validation
diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py
index f899516..877362d 100644
--- a/erpnext/manufacturing/doctype/job_card/job_card.py
+++ b/erpnext/manufacturing/doctype/job_card/job_card.py
@@ -87,6 +87,12 @@
frappe.db.get_value("Work Order Operation", self.operation_id, "completed_qty")
)
+ over_production_percentage = flt(
+ frappe.db.get_single_value("Manufacturing Settings", "overproduction_percentage_for_work_order")
+ )
+
+ wo_qty = wo_qty + (wo_qty * over_production_percentage / 100)
+
job_card_qty = frappe.get_all(
"Job Card",
fields=["sum(for_quantity)"],
@@ -101,8 +107,17 @@
job_card_qty = flt(job_card_qty[0][0]) if job_card_qty else 0
if job_card_qty and ((job_card_qty - completed_qty) > wo_qty):
- msg = f"""Job Card quantity cannot be greater than
- Work Order quantity for the operation {self.operation}"""
+ form_link = get_link_to_form("Manufacturing Settings", "Manufacturing Settings")
+
+ msg = f"""
+ Qty To Manufacture in the job card
+ cannot be greater than Qty To Manufacture in the
+ work order for the operation {bold(self.operation)}.
+ <br><br><b>Solution: </b> Either you can reduce the
+ Qty To Manufacture in the job card or set the
+ 'Overproduction Percentage For Work Order'
+ in the {form_link}."""
+
frappe.throw(_(msg), title=_("Extra Job Card Quantity"))
def set_sub_operations(self):
diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py
index 540b7dc..bb53c8c 100644
--- a/erpnext/manufacturing/doctype/work_order/test_work_order.py
+++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py
@@ -1649,6 +1649,14 @@
job_card2 = frappe.copy_doc(job_card_doc)
self.assertRaises(frappe.ValidationError, job_card2.save)
+ frappe.db.set_single_value(
+ "Manufacturing Settings", "overproduction_percentage_for_work_order", 100
+ )
+
+ job_card2 = frappe.copy_doc(job_card_doc)
+ job_card2.time_logs = []
+ job_card2.save()
+
def prepare_data_for_workstation_type_check():
from erpnext.manufacturing.doctype.operation.test_operation import make_operation