Skip to content

Commit d3ad5a6

Browse files
ruchamahabalmergify[bot]
authored andcommitted
fix: simplify shift request overlapping validation
(cherry picked from commit e832b93)
1 parent 398e3f1 commit d3ad5a6

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

hrms/hr/doctype/shift_request/shift_request.py

+7-24
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,16 @@ def get_overlapping_dates(self):
9797
query = (
9898
frappe.qb.from_(shift)
9999
.select(shift.name, shift.shift_type)
100-
.where((shift.employee == self.employee) & (shift.docstatus < 2) & (shift.name != self.name))
100+
.where(
101+
(shift.employee == self.employee)
102+
& (shift.docstatus < 2)
103+
& (shift.name != self.name)
104+
& ((shift.to_date >= self.from_date) | (shift.to_date.isnull()))
105+
)
101106
)
102107

103108
if self.to_date:
104-
query = query.where(
105-
Criterion.any(
106-
[
107-
Criterion.any(
108-
[
109-
shift.to_date.isnull(),
110-
((self.from_date >= shift.from_date) & (self.from_date <= shift.to_date)),
111-
]
112-
),
113-
Criterion.any(
114-
[
115-
((self.to_date >= shift.from_date) & (self.to_date <= shift.to_date)),
116-
shift.from_date.between(self.from_date, self.to_date),
117-
]
118-
),
119-
]
120-
)
121-
)
122-
else:
123-
query = query.where(
124-
shift.to_date.isnull()
125-
| ((self.from_date >= shift.from_date) & (self.from_date <= shift.to_date))
126-
)
109+
query = query.where(shift.from_date <= self.to_date)
127110

128111
return query.run(as_dict=True)
129112

0 commit comments

Comments
 (0)