diff --git a/erpnext/manufacturing/doctype/workstation/workstation.py b/erpnext/manufacturing/doctype/workstation/workstation.py index a6c320b7606..dba4fb8b1ef 100644 --- a/erpnext/manufacturing/doctype/workstation/workstation.py +++ b/erpnext/manufacturing/doctype/workstation/workstation.py @@ -84,7 +84,7 @@ class Workstation(Document): def before_save(self): if self.has_value_changed("workstation_type"): - self.set_data_based_on_workstation_type() + self._set_data_based_on_workstation_type() self.set_hour_rate() self.set_total_working_hours() @@ -115,6 +115,10 @@ class Workstation(Document): @frappe.whitelist() def set_data_based_on_workstation_type(self): + self.check_permission("write") + self._set_data_based_on_workstation_type() + + def _set_data_based_on_workstation_type(self): if self.workstation_type: data = frappe.get_all( "Workstation Cost", @@ -212,6 +216,8 @@ class Workstation(Document): @frappe.whitelist() def start_job(self, job_card: str, from_time: DateTimeLikeObject, employee: str): doc = frappe.get_doc("Job Card", job_card) + doc.check_permission("write") + doc.append("time_logs", {"from_time": from_time, "employee": employee}) doc.save(ignore_permissions=True) @@ -220,6 +226,8 @@ class Workstation(Document): @frappe.whitelist() def complete_job(self, job_card: str, qty: float, to_time: DateTimeLikeObject): doc = frappe.get_doc("Job Card", job_card) + doc.check_permission("submit") + for row in doc.time_logs: if not row.to_time: row.to_time = to_time @@ -318,6 +326,8 @@ def get_status_color(status): @frappe.whitelist() def get_raw_materials(job_card: str): + frappe.has_permission("Job Card", "read", doc=job_card, throw=True) + raw_materials = frappe.get_all( "Job Card", fields=[ @@ -461,6 +471,8 @@ def check_workstation_for_holiday(workstation, from_datetime, to_datetime): @frappe.whitelist() def get_workstations(**kwargs): + frappe.has_permission("Workstation", "read", throw=True) + kwargs = frappe._dict(kwargs) _workstation = frappe.qb.DocType("Workstation") @@ -536,13 +548,8 @@ def update_job_card(job_card: str, method: str, **kwargs): title=_("Not Allowed"), ) - frappe.has_permission("Job Card", "read", throw=True) - doc = frappe.get_doc("Job Card", job_card) - - # These methods mutate the Job Card, but frappe.get_doc does not enforce permissions — - # require write access before running anything. - frappe.has_permission("Job Card", "write", doc=doc, throw=True) + doc.check_permission("write") if isinstance(kwargs, dict): kwargs = frappe._dict(kwargs) @@ -558,6 +565,8 @@ def update_job_card(job_card: str, method: str, **kwargs): @frappe.whitelist() def validate_job_card(job_card: str, status: str): + frappe.has_permission("Job Card", "read", doc=job_card, throw=True) + job_card_details = frappe.db.get_value("Job Card", job_card, ["status", "for_quantity"], as_dict=1) current_status = job_card_details.status