diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index a5779fb299c..455aa7e5766 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -213,29 +213,27 @@ class JobCard(Document): production_capacity = 1 query = query.where(jctl.employee == args.get("employee")) - existing = query.run(as_dict=True) + existing_time_logs = query.run(as_dict=True) - overlap_count = self.get_overlap_count(existing) - if existing and production_capacity > overlap_count: - return + if not self.has_overlap(production_capacity, existing_time_logs): + return {} if self.workstation_type: - if workstation := self.get_workstation_based_on_available_slot(existing): + if workstation := self.get_workstation_based_on_available_slot(existing_time_logs): self.workstation = workstation return None - return existing[0] if existing else None + return existing_time_logs[0] if existing_time_logs else None - @staticmethod - def get_overlap_count(time_logs): - count = 1 + def has_overlap(self, production_capacity, time_logs): + overlap = False + if production_capacity == 1 and len(time_logs) > 0: + return True # Check overlap exists or not between the overlapping time logs with the current Job Card - for idx, row in enumerate(time_logs): - next_idx = idx - if idx + 1 < len(time_logs): - next_idx = idx + 1 - next_row = time_logs[next_idx] + for row in time_logs: + count = 1 + for next_row in time_logs: if row.name == next_row.name: continue @@ -255,7 +253,10 @@ class JobCard(Document): ): count += 1 - return count + if count > production_capacity: + return True + + return overlap def get_workstation_based_on_available_slot(self, existing) -> Optional[str]: workstations = get_workstations(self.workstation_type)