From 22eaa141790814d28baecb7f54758cdaa07d3eb9 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Tue, 18 Feb 2025 14:22:39 +0530 Subject: [PATCH] fix: check if employee is currently working on another workstation (cherry picked from commit 8234e659c8e20ee60a96b63f1f50eafdac974420) --- .../manufacturing/doctype/job_card/job_card.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index 1b4840d14b5..c82038af342 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -216,7 +216,7 @@ class JobCard(Document): open_job_cards = [] 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) if data: @@ -257,9 +257,12 @@ class JobCard(Document): frappe.get_cached_value("Workstation", self.workstation, "production_capacity") or 1 ) - if args.get("employee"): - # override capacity for employee - production_capacity = 1 + if self.get_open_job_cards(args.get("employee")): + frappe.throw( + _( + "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): return {} @@ -366,7 +369,7 @@ class JobCard(Document): 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") jctl = frappe.qb.DocType("Job Card Time Log") @@ -377,13 +380,15 @@ class JobCard(Document): .select(jc.name) .where( (jctl.parent == jc.name) - & (jc.workstation == self.workstation) & (jctl.employee == employee) & (jc.docstatus < 1) & (jc.name != self.name) ) ) + if workstation: + query = query.where(jc.workstation == workstation) + jobs = query.run(as_dict=True) return [job.get("name") for job in jobs] if jobs else []