Skip to content

Commit

Permalink
fix: rewrite attendance query in qb
Browse files Browse the repository at this point in the history
(cherry picked from commit ba6168b)
  • Loading branch information
ruchamahabal authored and mergify[bot] committed Dec 23, 2023
1 parent b2af5a4 commit 97372d0
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions hrms/hr/doctype/attendance/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,24 @@ def validate_employee_status(self):
frappe.throw(_("Cannot mark attendance for an Inactive employee {0}").format(self.employee))

def check_leave_record(self):
leave_record = frappe.db.sql(
"""
select leave_type, half_day, half_day_date, name
from `tabLeave Application`
where employee = %s
and %s between from_date and to_date
and status = 'Approved'
and docstatus = 1
""",
(self.employee, self.attendance_date),
as_dict=True,
)
LeaveApplication = frappe.qb.DocType("Leave Application")
leave_record = (
frappe.qb.from_(LeaveApplication)
.select(
LeaveApplication.leave_type,
LeaveApplication.half_day,
LeaveApplication.half_day_date,
LeaveApplication.name,
)
.where(
(LeaveApplication.employee == self.employee)
& (self.attendance_date >= LeaveApplication.from_date)
& (self.attendance_date <= LeaveApplication.to_date)
& (LeaveApplication.status == "Approved")
& (LeaveApplication.docstatus == 1)
)
).run(as_dict=True)

if leave_record:
for d in leave_record:
self.leave_type = d.leave_type
Expand Down

0 comments on commit 97372d0

Please sign in to comment.