fix : correct logic for overlap error (#38967) fixing overlap error logic with taking care of sequential time job cards in overlap job card list (cherry picked from commit fe77b9d633dcd168bef6f7c106ec1bd6d1a6591c) Co-authored-by: VihangT <151990347+VihangT@users.noreply.github.com>
This commit is contained in:
parent
76c6b501f9
commit
3caabf23a5
@ -273,35 +273,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.
|
||||||
|
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 True
|
||||||
|
|
||||||
return overlap
|
return overlap
|
||||||
|
|
||||||
def get_time_logs(self, args, doctype, check_next_available_slot=False):
|
def get_time_logs(self, args, doctype, check_next_available_slot=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user