mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-11 05:31:48 +00:00
fix: validate supplied operation_id belongs to work order operation
This commit is contained in:
@@ -1340,7 +1340,10 @@ class JobCard(Document):
|
||||
self.wip_warehouse = frappe.get_cached_value("Company", self.company, "default_wip_warehouse")
|
||||
|
||||
def set_operation_id(self):
|
||||
if self.operation_id or not (self.work_order and self.operation):
|
||||
if not (self.work_order and self.operation):
|
||||
return
|
||||
|
||||
if self.operation_id and self.docstatus != 0:
|
||||
return
|
||||
|
||||
operation_rows = frappe.get_all(
|
||||
@@ -1349,7 +1352,14 @@ class JobCard(Document):
|
||||
pluck="name",
|
||||
)
|
||||
|
||||
if len(operation_rows) == 1:
|
||||
if self.operation_id:
|
||||
if operation_rows and self.operation_id not in operation_rows:
|
||||
frappe.throw(
|
||||
_("Operation {0} does not belong to the work order {1}").format(
|
||||
bold(self.operation), get_link_to_form("Work Order", self.work_order)
|
||||
)
|
||||
)
|
||||
elif len(operation_rows) == 1:
|
||||
self.operation_id = operation_rows[0]
|
||||
elif operation_rows and self.docstatus == 0:
|
||||
frappe.throw(
|
||||
|
||||
@@ -175,6 +175,13 @@ class TestJobCard(ERPNextTestSuite):
|
||||
job_card.operation = operation_row.operation
|
||||
self.assertRaises(frappe.ValidationError, job_card.set_operation_id)
|
||||
|
||||
job_card.operation_id = "bogus-row"
|
||||
self.assertRaises(frappe.ValidationError, job_card.set_operation_id)
|
||||
|
||||
job_card.operation_id = work_order.operations[-1].name
|
||||
job_card.set_operation_id()
|
||||
self.assertEqual(job_card.operation_id, work_order.operations[-1].name)
|
||||
|
||||
def test_job_card_with_different_work_station(self):
|
||||
job_cards = frappe.get_all(
|
||||
"Job Card",
|
||||
|
||||
Reference in New Issue
Block a user