fix : correct logic for overlap error (#38798)

* fix : correct logic for overlap error

* fix : 

Updated as per lintels

* fix : 

changes as per linters

* fix : correct logic for overlap error

fixing overlap error logic with taking care of sequential time job cards in overlap job card list

Added Provision if time_logs list is empty
This commit is contained in:
VihangT
2023-12-27 16:11:14 +05:30
committed by GitHub
parent 400c78c600
commit 92d61eb19e

View File

@@ -227,35 +227,39 @@ class JobCard(Document):
def has_overlap(self, production_capacity, time_logs): def has_overlap(self, production_capacity, time_logs):
overlap = False overlap = False
if production_capacity == 1 and len(time_logs) > 0: if production_capacity == 1 and len(time_logs) >= 1:
return True return True
if not len(time_logs):
return False
# Check overlap exists or not between the overlapping time logs with the current Job Card # sorting overlapping job cards as per from_time
for row in time_logs: time_logs = sorted(time_logs, key=lambda x: x.get("from_time"))
count = 1 # alloted_capacity has key number starting from 1. Key number will increment by 1 if non sequential job card found
for next_row in time_logs: # if key number reaches/crosses to production_capacity means capacity is full and overlap error generated
if row.name == next_row.name: # this will store last to_time of sequential job cards
continue alloted_capacity = {1: time_logs[0]["to_time"]}
# flag for sequential Job card found
if ( sequential_job_card_found = False
( for i in range(1, len(time_logs)):
get_datetime(next_row.from_time) >= get_datetime(row.from_time) # scanning for all Existing keys
and get_datetime(next_row.from_time) <= get_datetime(row.to_time) for key in alloted_capacity.keys():
) # if current Job Card from time is greater than last to_time in that key means these job card are sequential
or ( if alloted_capacity[key] <= time_logs[i]["from_time"]:
get_datetime(next_row.to_time) >= get_datetime(row.from_time) # So update key's value with last to_time
and get_datetime(next_row.to_time) <= get_datetime(row.to_time) alloted_capacity[key] = time_logs[i]["to_time"]
) # flag is true as we get sequential Job Card for that key
or ( sequential_job_card_found = True
get_datetime(next_row.from_time) <= get_datetime(row.from_time) # Immediately break so that job card to time is not added with any other key except this
and get_datetime(next_row.to_time) >= get_datetime(row.to_time) break
) # if sequential job card not found above means it is overlapping so increment key number to alloted_capacity
): if not sequential_job_card_found:
count += 1 # increment key number
key = key + 1
if count > production_capacity: # for that key last to time is assigned.
return True alloted_capacity[key] = time_logs[i]["to_time"]
if len(alloted_capacity) >= production_capacity:
# if number of keys greater or equal to production caoacity means full capacity is utilized and we should throw overlap error
return True
return overlap return overlap
def get_workstation_based_on_available_slot(self, existing) -> Optional[str]: def get_workstation_based_on_available_slot(self, existing) -> Optional[str]: