mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-04 18:23:05 +00:00
fix: permissions in workstation file
(cherry picked from commitcf127e8900) # Conflicts: # erpnext/manufacturing/doctype/workstation/workstation.py (cherry picked from commit0fea93388d) # Conflicts: # erpnext/manufacturing/doctype/workstation/workstation.py
This commit is contained in:
committed by
Mergify
parent
74da3b8775
commit
808ca06801
@@ -65,7 +65,13 @@ class Workstation(Document):
|
||||
# end: auto-generated types
|
||||
|
||||
def before_save(self):
|
||||
<<<<<<< HEAD
|
||||
self.set_data_based_on_workstation_type()
|
||||
=======
|
||||
if self.has_value_changed("workstation_type"):
|
||||
self._set_data_based_on_workstation_type()
|
||||
|
||||
>>>>>>> 0fea93388d (fix: permissions in workstation file)
|
||||
self.set_hour_rate()
|
||||
self.set_total_working_hours()
|
||||
|
||||
@@ -92,6 +98,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:
|
||||
fields = [
|
||||
"hour_rate_labour",
|
||||
@@ -168,6 +178,8 @@ class Workstation(Document):
|
||||
@frappe.whitelist()
|
||||
def start_job(self, job_card, from_time, employee):
|
||||
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)
|
||||
|
||||
@@ -176,6 +188,8 @@ class Workstation(Document):
|
||||
@frappe.whitelist()
|
||||
def complete_job(self, job_card, qty, to_time):
|
||||
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
|
||||
@@ -254,11 +268,24 @@ def get_status_color(status):
|
||||
return color_map.get(status, "var(--bg-blue)")
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
def get_raw_materials(job_cards):
|
||||
raw_materials = {}
|
||||
|
||||
data = frappe.get_all(
|
||||
"Job Card Item",
|
||||
=======
|
||||
@frappe.whitelist()
|
||||
<<<<<<< HEAD
|
||||
def get_raw_materials(job_card):
|
||||
=======
|
||||
def get_raw_materials(job_card: str):
|
||||
frappe.has_permission("Job Card", "read", doc=job_card, throw=True)
|
||||
|
||||
>>>>>>> cf127e8900 (fix: permissions in workstation file)
|
||||
raw_materials = frappe.get_all(
|
||||
"Job Card",
|
||||
>>>>>>> 0fea93388d (fix: permissions in workstation file)
|
||||
fields=[
|
||||
"parent",
|
||||
"item_code",
|
||||
@@ -364,6 +391,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")
|
||||
|
||||
@@ -409,3 +438,79 @@ def get_workstations(**kwargs):
|
||||
d.status_image = d.off_status_image
|
||||
|
||||
return data
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
|
||||
def get_color_map():
|
||||
return {
|
||||
"Production": "green",
|
||||
"Off": "gray",
|
||||
"Idle": "gray",
|
||||
"Problem": "red",
|
||||
"Maintenance": "yellow",
|
||||
"Setup": "blue",
|
||||
}
|
||||
|
||||
|
||||
ALLOWED_JOB_CARD_METHODS = frozenset(
|
||||
{
|
||||
"start_timer",
|
||||
"pause_job",
|
||||
"resume_job",
|
||||
"complete_job_card",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_job_card(job_card: str, method: str, **kwargs):
|
||||
if method not in ALLOWED_JOB_CARD_METHODS:
|
||||
frappe.throw(
|
||||
_("Method {0} is not allowed to be run on a Job Card.").format(bold(method)),
|
||||
frappe.PermissionError,
|
||||
title=_("Not Allowed"),
|
||||
)
|
||||
|
||||
doc = frappe.get_doc("Job Card", job_card)
|
||||
doc.check_permission("write")
|
||||
|
||||
if isinstance(kwargs, dict):
|
||||
kwargs = frappe._dict(kwargs)
|
||||
|
||||
if kwargs.get("employees"):
|
||||
kwargs.employees = frappe.parse_json(kwargs.employees)
|
||||
|
||||
if kwargs.qty and isinstance(kwargs.qty, str):
|
||||
kwargs.qty = flt(kwargs.qty)
|
||||
|
||||
doc.run_method(method, **kwargs)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
<<<<<<< HEAD
|
||||
def validate_job_card(job_card, status):
|
||||
=======
|
||||
def validate_job_card(job_card: str, status: str):
|
||||
frappe.has_permission("Job Card", "read", doc=job_card, throw=True)
|
||||
|
||||
>>>>>>> cf127e8900 (fix: permissions in workstation file)
|
||||
job_card_details = frappe.db.get_value("Job Card", job_card, ["status", "for_quantity"], as_dict=1)
|
||||
|
||||
current_status = job_card_details.status
|
||||
if current_status != status:
|
||||
if status == "Open":
|
||||
frappe.throw(
|
||||
_("The job card {0} is in {1} state and you cannot start it again.").format(
|
||||
job_card, current_status
|
||||
)
|
||||
)
|
||||
else:
|
||||
frappe.throw(
|
||||
_("The job card {0} is in {1} state and you cannot complete.").format(
|
||||
job_card, current_status
|
||||
)
|
||||
)
|
||||
|
||||
return job_card_details.for_quantity
|
||||
>>>>>>> 0fea93388d (fix: permissions in workstation file)
|
||||
|
||||
Reference in New Issue
Block a user