fix: better overlap logic for job card (backport #38432) (#38521)

* fix: better overlap logic for job card (#38432)

(cherry picked from commit 74eab91042)

# Conflicts:
#	erpnext/manufacturing/doctype/job_card/job_card.py

* chore: fix conflicts

* chore: fixed existing_time_logs not defined

---------

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2023-12-03 15:15:30 +05:30
committed by GitHub
parent b88c7d63de
commit 6db63c971e

View File

@@ -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)