mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-15 15:38:39 +00:00
fix: resolve or require operation_id server-side
This commit is contained in:
@@ -163,6 +163,7 @@ class JobCard(Document):
|
||||
self.validate_time_logs()
|
||||
self.validate_on_hold()
|
||||
self.set_status()
|
||||
self.set_operation_id()
|
||||
self.validate_sequence_id()
|
||||
self.set_sub_operations()
|
||||
self.update_sub_operation_status()
|
||||
@@ -1338,6 +1339,25 @@ class JobCard(Document):
|
||||
if not self.wip_warehouse:
|
||||
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):
|
||||
return
|
||||
|
||||
operation_rows = frappe.get_all(
|
||||
"Work Order Operation",
|
||||
filters={"parent": self.work_order, "operation": self.operation},
|
||||
pluck="name",
|
||||
)
|
||||
|
||||
if len(operation_rows) == 1:
|
||||
self.operation_id = operation_rows[0]
|
||||
elif operation_rows and self.docstatus == 0:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Operation {0} is added multiple times in the work order {1}. Please select the operation row."
|
||||
).format(bold(self.operation), get_link_to_form("Work Order", self.work_order))
|
||||
)
|
||||
|
||||
@frappe.whitelist()
|
||||
def pause_job(self, **kwargs):
|
||||
frappe.has_permission("Job Card", "write", doc=self, throw=True)
|
||||
|
||||
@@ -148,6 +148,33 @@ class TestJobCard(ERPNextTestSuite):
|
||||
)
|
||||
self.assertRaises(frappe.ValidationError, job_card_doc.submit)
|
||||
|
||||
def test_set_operation_id(self):
|
||||
work_order = make_wo_order_test_record(item="_Test FG Item 2", qty=2, do_not_submit=1)
|
||||
operation_row = work_order.operations[0]
|
||||
|
||||
job_card = frappe.new_doc("Job Card")
|
||||
job_card.work_order = work_order.name
|
||||
job_card.operation = operation_row.operation
|
||||
job_card.set_operation_id()
|
||||
self.assertEqual(job_card.operation_id, operation_row.name)
|
||||
|
||||
work_order.append(
|
||||
"operations",
|
||||
{
|
||||
"operation": operation_row.operation,
|
||||
"workstation": operation_row.workstation,
|
||||
"time_in_mins": operation_row.time_in_mins,
|
||||
"hour_rate": operation_row.hour_rate,
|
||||
"sequence_id": work_order.operations[-1].sequence_id,
|
||||
},
|
||||
)
|
||||
work_order.save()
|
||||
|
||||
job_card = frappe.new_doc("Job Card")
|
||||
job_card.work_order = work_order.name
|
||||
job_card.operation = operation_row.operation
|
||||
self.assertRaises(frappe.ValidationError, job_card.set_operation_id)
|
||||
|
||||
def test_job_card_with_different_work_station(self):
|
||||
job_cards = frappe.get_all(
|
||||
"Job Card",
|
||||
|
||||
Reference in New Issue
Block a user