Skip to content

Commit

Permalink
chore: fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored Nov 26, 2023
1 parent b187b97 commit 07ef78a
Showing 1 changed file with 33 additions and 55 deletions.
88 changes: 33 additions & 55 deletions erpnext/manufacturing/doctype/job_card/job_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,56 +166,6 @@ def validate_time_logs(self):
def get_overlap_for(self, args, check_next_available_slot=False):
production_capacity = 1

<<<<<<< HEAD
=======
if args.get("employee"):
# override capacity for employee
production_capacity = 1

overlap_count = self.get_overlap_count(time_logs)
if time_logs and production_capacity > overlap_count:
return {}

if self.workstation_type and time_logs:
if workstation_time := self.get_workstation_based_on_available_slot(time_logs):
self.workstation = workstation_time.get("workstation")
return workstation_time

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):
>>>>>>> d8245cef72 (fix: job card overlap validation (#38345))
jc = frappe.qb.DocType("Job Card")
jctl = frappe.qb.DocType("Job Card Time Log")

Expand All @@ -231,9 +181,6 @@ def get_time_logs(self, args, doctype, check_next_available_slot=False):
query = (
frappe.qb.from_(jctl)
.from_(jc)
<<<<<<< HEAD
.select(jc.name.as_("name"), jctl.to_time, jc.workstation, jc.workstation_type)
=======
.select(
jc.name.as_("name"),
jctl.name.as_("row_name"),
Expand All @@ -242,7 +189,6 @@ def get_time_logs(self, args, doctype, check_next_available_slot=False):
jc.workstation,
jc.workstation_type,
)
>>>>>>> d8245cef72 (fix: job card overlap validation (#38345))
.where(
(jctl.parent == jc.name)
& (Criterion.any(time_conditions))
Expand All @@ -269,7 +215,8 @@ def get_time_logs(self, args, doctype, check_next_available_slot=False):

existing = query.run(as_dict=True)

if existing and production_capacity > len(existing):
overlap_count = self.get_overlap_count(existing)
if existing and production_capacity > overlap_count:
return

if self.workstation_type:
Expand All @@ -279,6 +226,37 @@ def get_time_logs(self, args, doctype, check_next_available_slot=False):

return existing[0] if existing else None

@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_workstation_based_on_available_slot(self, existing) -> Optional[str]:
workstations = get_workstations(self.workstation_type)
if workstations:
Expand Down

0 comments on commit 07ef78a

Please sign in to comment.