From 07ef78ab47a7cd0da6b6aa92d87c01c25058c663 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Sun, 26 Nov 2023 16:33:40 +0530 Subject: [PATCH] chore: fix conflicts --- .../doctype/job_card/job_card.py | 88 +++++++------------ 1 file changed, 33 insertions(+), 55 deletions(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index d81bc2ec0558..8b5e843c210a 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -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") @@ -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"), @@ -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)) @@ -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: @@ -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: