mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-21 11:15:10 +00:00
fix: check if employee is currently working on another workstation
(cherry picked from commit 8234e659c8)
This commit is contained in:
@@ -216,7 +216,7 @@ class JobCard(Document):
|
|||||||
|
|
||||||
open_job_cards = []
|
open_job_cards = []
|
||||||
if d.get("employee"):
|
if d.get("employee"):
|
||||||
open_job_cards = self.get_open_job_cards(d.get("employee"))
|
open_job_cards = self.get_open_job_cards(d.get("employee"), workstation=self.workstation)
|
||||||
|
|
||||||
data = self.get_overlap_for(d, open_job_cards=open_job_cards)
|
data = self.get_overlap_for(d, open_job_cards=open_job_cards)
|
||||||
if data:
|
if data:
|
||||||
@@ -257,9 +257,12 @@ class JobCard(Document):
|
|||||||
frappe.get_cached_value("Workstation", self.workstation, "production_capacity") or 1
|
frappe.get_cached_value("Workstation", self.workstation, "production_capacity") or 1
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.get("employee"):
|
if self.get_open_job_cards(args.get("employee")):
|
||||||
# override capacity for employee
|
frappe.throw(
|
||||||
production_capacity = 1
|
_(
|
||||||
|
"Employee {0} is currently working on another workstation. Please assign another employee."
|
||||||
|
).format(args.get("employee"))
|
||||||
|
)
|
||||||
|
|
||||||
if not self.has_overlap(production_capacity, time_logs):
|
if not self.has_overlap(production_capacity, time_logs):
|
||||||
return {}
|
return {}
|
||||||
@@ -366,7 +369,7 @@ class JobCard(Document):
|
|||||||
|
|
||||||
return time_logs
|
return time_logs
|
||||||
|
|
||||||
def get_open_job_cards(self, employee):
|
def get_open_job_cards(self, employee, workstation=None):
|
||||||
jc = frappe.qb.DocType("Job Card")
|
jc = frappe.qb.DocType("Job Card")
|
||||||
jctl = frappe.qb.DocType("Job Card Time Log")
|
jctl = frappe.qb.DocType("Job Card Time Log")
|
||||||
|
|
||||||
@@ -377,13 +380,15 @@ class JobCard(Document):
|
|||||||
.select(jc.name)
|
.select(jc.name)
|
||||||
.where(
|
.where(
|
||||||
(jctl.parent == jc.name)
|
(jctl.parent == jc.name)
|
||||||
& (jc.workstation == self.workstation)
|
|
||||||
& (jctl.employee == employee)
|
& (jctl.employee == employee)
|
||||||
& (jc.docstatus < 1)
|
& (jc.docstatus < 1)
|
||||||
& (jc.name != self.name)
|
& (jc.name != self.name)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if workstation:
|
||||||
|
query = query.where(jc.workstation == workstation)
|
||||||
|
|
||||||
jobs = query.run(as_dict=True)
|
jobs = query.run(as_dict=True)
|
||||||
return [job.get("name") for job in jobs] if jobs else []
|
return [job.get("name") for job in jobs] if jobs else []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user