Skip to content

Commit

Permalink
Merge pull request #2749 from frappe/mergify/bp/version-14-hotfix/pr-…
Browse files Browse the repository at this point in the history
…2739

fix: Only show permitted attendance records in calendar view (backport #2739)
  • Loading branch information
asmitahase authored Feb 4, 2025
2 parents b884147 + fe9049f commit eeef692
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
5 changes: 3 additions & 2 deletions hrms/hr/doctype/attendance/attendance.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
"label": "Attendance Date",
"oldfieldname": "attendance_date",
"oldfieldtype": "Date",
"reqd": 1
"reqd": 1,
"search_index": 1
},
{
"fetch_from": "employee.company",
Expand Down Expand Up @@ -207,7 +208,7 @@
"idx": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-04-05 20:55:02.905452",
"modified": "2025-01-31 11:45:54.846562",
"modified_by": "Administrator",
"module": "HR",
"name": "Attendance",
Expand Down
58 changes: 27 additions & 31 deletions hrms/hr/doctype/attendance/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,42 +228,38 @@ def unlink_attendance_from_checkins(self):

@frappe.whitelist()
def get_events(start, end, filters=None):
from frappe.desk.reportview import get_filters_cond

events = []

employee = frappe.db.get_value("Employee", {"user_id": frappe.session.user})

if not employee:
return events

conditions = get_filters_cond("Attendance", filters, [])
add_attendance(events, start, end, conditions=conditions)
add_holidays(events, start, end, employee)
return events

return []
if isinstance(filters, str):
import json

def add_attendance(events, start, end, conditions=None):
query = """select name, attendance_date, status, employee_name
from `tabAttendance` where
attendance_date between %(from_date)s and %(to_date)s
and docstatus < 2"""
filters = json.loads(filters)
if not filters:
filters = []
filters.append(["attendance_date", "between", [get_datetime(start).date(), get_datetime(end).date()]])
attendance_records = add_attendance(filters)
add_holidays(attendance_records, start, end, employee)
return attendance_records

if conditions:
query += conditions

for d in frappe.db.sql(query, {"from_date": start, "to_date": end}, as_dict=True):
e = {
"name": d.name,
"doctype": "Attendance",
"start": d.attendance_date,
"end": d.attendance_date,
"title": f"{d.employee_name}: {cstr(d.status)}",
"status": d.status,
"docstatus": d.docstatus,
}
if e not in events:
events.append(e)
def add_attendance(filters):
attendance = frappe.get_list(
"Attendance",
fields=[
"name",
"'Attendance' as doctype",
"attendance_date as start",
"attendance_date as end",
"employee_name",
"status",
"docstatus",
],
filters=filters,
)
for record in attendance:
record["title"] = f"{record.employee_name} : {record.status}"
return attendance


def add_holidays(events, start, end, employee=None):
Expand Down

0 comments on commit eeef692

Please sign in to comment.