Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: job card overlap validation #38345

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions erpnext/manufacturing/doctype/job_card/job_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def get_overlap_for(self, args, check_next_available_slot=False):
# override capacity for employee
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 {}

if self.workstation_type and time_logs:
Expand All @@ -195,6 +196,37 @@ def get_overlap_for(self, args, check_next_available_slot=False):

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):
jc = frappe.qb.DocType("Job Card")
jctl = frappe.qb.DocType(doctype)
Expand All @@ -211,7 +243,14 @@ def get_time_logs(self, args, doctype, check_next_available_slot=False):
query = (
frappe.qb.from_(jctl)
.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(
(jctl.parent == jc.name)
& (Criterion.any(time_conditions))
Expand Down
Loading