From a84d0af81e1dbba309a76471cd98e91bf6441d22 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 3 May 2023 23:22:59 +0530 Subject: [PATCH] fix: over production percentage not considered in validation --- .../doctype/job_card/job_card.py | 19 +++++++++++++++++-- .../doctype/work_order/test_work_order.py | 8 ++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index f89951619e..877362dcba 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -87,6 +87,12 @@ class JobCard(Document): 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 @@ class JobCard(Document): 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)}. +

Solution: 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 540b7dc9ea..bb53c8c225 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 @@ class TestWorkOrder(FrappeTestCase): 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