fix: job card overlap validation (#38345) (cherry picked from commit d8245cef723575eaf52c2e39d25a6f9c83ce9ba0) Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
parent
e0f9c64290
commit
d6fe7eb10c
@ -185,7 +185,8 @@ class JobCard(Document):
|
|||||||
# override capacity for employee
|
# override capacity for employee
|
||||||
production_capacity = 1
|
production_capacity = 1
|
||||||
|
|
||||||
if time_logs and production_capacity > len(time_logs):
|
overlap_count = self.get_overlap_count(time_logs)
|
||||||
|
if time_logs and production_capacity > overlap_count:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
if self.workstation_type and time_logs:
|
if self.workstation_type and time_logs:
|
||||||
@ -195,6 +196,37 @@ class JobCard(Document):
|
|||||||
|
|
||||||
return time_logs[-1]
|
return time_logs[-1]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_overlap_count(time_logs):
|
||||||
|
count = 1
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
if row.name == next_row.name:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
get_datetime(next_row.from_time) >= get_datetime(row.from_time)
|
||||||
|
and get_datetime(next_row.from_time) <= get_datetime(row.to_time)
|
||||||
|
)
|
||||||
|
or (
|
||||||
|
get_datetime(next_row.to_time) >= get_datetime(row.from_time)
|
||||||
|
and get_datetime(next_row.to_time) <= get_datetime(row.to_time)
|
||||||
|
)
|
||||||
|
or (
|
||||||
|
get_datetime(next_row.from_time) <= get_datetime(row.from_time)
|
||||||
|
and get_datetime(next_row.to_time) >= get_datetime(row.to_time)
|
||||||
|
)
|
||||||
|
):
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
def get_time_logs(self, args, doctype, check_next_available_slot=False):
|
def get_time_logs(self, args, doctype, check_next_available_slot=False):
|
||||||
jc = frappe.qb.DocType("Job Card")
|
jc = frappe.qb.DocType("Job Card")
|
||||||
jctl = frappe.qb.DocType(doctype)
|
jctl = frappe.qb.DocType(doctype)
|
||||||
@ -211,7 +243,14 @@ class JobCard(Document):
|
|||||||
query = (
|
query = (
|
||||||
frappe.qb.from_(jctl)
|
frappe.qb.from_(jctl)
|
||||||
.from_(jc)
|
.from_(jc)
|
||||||
.select(jc.name.as_("name"), jctl.from_time, jctl.to_time, jc.workstation, jc.workstation_type)
|
.select(
|
||||||
|
jc.name.as_("name"),
|
||||||
|
jctl.name.as_("row_name"),
|
||||||
|
jctl.from_time,
|
||||||
|
jctl.to_time,
|
||||||
|
jc.workstation,
|
||||||
|
jc.workstation_type,
|
||||||
|
)
|
||||||
.where(
|
.where(
|
||||||
(jctl.parent == jc.name)
|
(jctl.parent == jc.name)
|
||||||
& (Criterion.any(time_conditions))
|
& (Criterion.any(time_conditions))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user