Skip to content

Commit

Permalink
Merge pull request #35148 from rohitwaghchaure/fixed-extra-job-card-q…
Browse files Browse the repository at this point in the history
…uantity-issue

fix: over production percentage not considered in validation
  • Loading branch information
rohitwaghchaure authored May 3, 2023
2 parents dfee45f + a84d0af commit bea8f48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
19 changes: 17 additions & 2 deletions erpnext/manufacturing/doctype/job_card/job_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ def validate_job_card_qty(self):
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)"],
Expand All @@ -101,8 +107,17 @@ def validate_job_card_qty(self):
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):
Expand Down
8 changes: 8 additions & 0 deletions erpnext/manufacturing/doctype/work_order/test_work_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,14 @@ def test_job_card_extra_qty(self):
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
Expand Down

0 comments on commit bea8f48

Please sign in to comment.