From 6db63c971eb88ad68b916c1947e81806c0440638 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sun, 3 Dec 2023 15:15:30 +0530 Subject: [PATCH] fix: better overlap logic for job card (backport #38432) (#38521) * fix: better overlap logic for job card (#38432) (cherry picked from commit 74eab910427ca4af94119b0c099e7743be770006) # Conflicts: # erpnext/manufacturing/doctype/job_card/job_card.py * chore: fix conflicts * chore: fixed existing_time_logs not defined --------- Co-authored-by: rohitwaghchaure --- .../doctype/job_card/job_card.py | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) 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)