mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-15 16:28:20 +00:00
* 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:
@@ -213,29 +213,27 @@ class JobCard(Document):
|
|||||||
production_capacity = 1
|
production_capacity = 1
|
||||||
query = query.where(jctl.employee == args.get("employee"))
|
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 not self.has_overlap(production_capacity, existing_time_logs):
|
||||||
if existing and production_capacity > overlap_count:
|
return {}
|
||||||
return
|
|
||||||
|
|
||||||
if self.workstation_type:
|
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
|
self.workstation = workstation
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return existing[0] if existing else None
|
return existing_time_logs[0] if existing_time_logs else None
|
||||||
|
|
||||||
@staticmethod
|
def has_overlap(self, production_capacity, time_logs):
|
||||||
def get_overlap_count(time_logs):
|
overlap = False
|
||||||
count = 1
|
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
|
# Check overlap exists or not between the overlapping time logs with the current Job Card
|
||||||
for idx, row in enumerate(time_logs):
|
for row in time_logs:
|
||||||
next_idx = idx
|
count = 1
|
||||||
if idx + 1 < len(time_logs):
|
for next_row in time_logs:
|
||||||
next_idx = idx + 1
|
|
||||||
next_row = time_logs[next_idx]
|
|
||||||
if row.name == next_row.name:
|
if row.name == next_row.name:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -255,7 +253,10 @@ class JobCard(Document):
|
|||||||
):
|
):
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
return count
|
if count > production_capacity:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return overlap
|
||||||
|
|
||||||
def get_workstation_based_on_available_slot(self, existing) -> Optional[str]:
|
def get_workstation_based_on_available_slot(self, existing) -> Optional[str]:
|
||||||
workstations = get_workstations(self.workstation_type)
|
workstations = get_workstations(self.workstation_type)
|
||||||
|
|||||||
Reference in New Issue
Block a user