From 2af19f41878406895d52bdc4fa203076c0686b03 Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Tue, 12 Mar 2024 13:06:44 +0530 Subject: [PATCH] fix: show attendance w.r.t years instead of academic year --- .../student_monthly_attendance_sheet.js | 17 ++++++++++++-- .../student_monthly_attendance_sheet.py | 22 +++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/education/education/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.js b/education/education/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.js index 3ce26de6..ec33bb57 100644 --- a/education/education/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.js +++ b/education/education/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.js @@ -15,8 +15,8 @@ frappe.query_reports["Student Monthly Attendance Sheet"] = { { "fieldname": "year", "label": __("Year"), - "fieldtype": "Link", - "options":"Academic Year", + "fieldtype": "Select", + "options":"", "reqd": 1 }, { @@ -27,4 +27,17 @@ frappe.query_reports["Student Monthly Attendance Sheet"] = { "reqd": 1 } ], + onload: function() { + return frappe.call({ + // method: "hrms.hr.report.monthly_attendance_sheet.monthly_attendance_sheet.get_attendance_years", + method: "education.education.report.student_monthly_attendance_sheet.student_monthly_attendance_sheet.get_year_list", + callback: function(r) { + let year_filter = frappe.query_report.get_filter('year'); + year_filter.df.options = r.message; + year_filter.df.default = r.message.join("\n"); + year_filter.refresh(); + year_filter.set_input(year_filter.df.default); + } + }); + }, } diff --git a/education/education/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py b/education/education/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py index acbeea13..37e77e1d 100644 --- a/education/education/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py +++ b/education/education/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py @@ -17,15 +17,8 @@ def execute(filters=None): if not filters: filters = {} - filter_year = str( - frappe.db.get_value( - "Academic Year", {"name": filters["year"]}, fieldname="year_start_date" - ).year - ) - - from_date = get_first_day(filters["month"] + "-" + filter_year) - to_date = get_last_day(filters["month"] + "-" + filter_year) - + from_date = get_first_day(filters["month"] + "-" + filters["year"]) + to_date = get_last_day(filters["month"] + "-" + filters["year"]) total_days_in_month = date_diff(to_date, from_date) + 1 columns = get_columns(total_days_in_month) students = get_student_group_students(filters.get("student_group"), 1) @@ -159,3 +152,14 @@ def mark_holidays(att_map, from_date, to_date, students_list): att_map.setdefault(student, frappe._dict()).setdefault(dt, "Holiday") return att_map + + +@frappe.whitelist() +def get_year_list(): + all_academic_years = frappe.db.get_list("Academic Year", pluck="year_start_date") + + year_list = [date.year for date in all_academic_years] + year_list = list(set(year_list)) + year_list.sort() + + return year_list