Skip to content

Commit

Permalink
Merge pull request #256 from RitvikSardana/develop-ritvik-leave-status
Browse files Browse the repository at this point in the history
feat: Add 'Leave' status in Student Attendance DocType
  • Loading branch information
RitvikSardana authored May 23, 2024
2 parents 3a7f506 + fd758c3 commit 8ce379e
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 329 deletions.
2 changes: 1 addition & 1 deletion education/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "15.3.0"
__version__ = "15.3.1"
41 changes: 27 additions & 14 deletions education/education/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from frappe.email.doctype.email_group.email_group import add_subscribers
from frappe.model.mapper import get_mapped_doc
from frappe.utils import cstr, flt, getdate
from frappe.utils.dateutils import get_dates_from_timegrain


def get_course(program):
Expand Down Expand Up @@ -135,7 +136,7 @@ def make_attendance_records(
:param student: Student.
:param student_name: Student Name.
:param course_schedule: Course Schedule.
:param status: Status (Present/Absent)
:param status: Status (Present/Absent/Leave).
"""
student_attendance = frappe.get_doc(
{
Expand Down Expand Up @@ -620,10 +621,8 @@ def apply_leave_based_on_course_schedule(leave_data, program_name):
},
order_by="schedule_date asc",
)

if frappe.db.exists("Student Attendance", {"course_schedule": "EDU-CSH-2024-00003"}):
pass

if not course_schedule_in_leave_period:
frappe.throw(_("No classes found in the leave period"))
for course_schedule in course_schedule_in_leave_period:
# check if attendance record does not exist for the student on the course schedule
if not frappe.db.exists(
Expand All @@ -633,7 +632,7 @@ def apply_leave_based_on_course_schedule(leave_data, program_name):
make_attendance_records(
leave_data.get("student"),
leave_data.get("student_name"),
"Absent",
"Leave",
course_schedule.get("name"),
None,
course_schedule.get("schedule_date"),
Expand All @@ -642,15 +641,19 @@ def apply_leave_based_on_course_schedule(leave_data, program_name):

def apply_leave_based_on_student_group(leave_data, program_name):
student_groups = get_student_groups(leave_data.get("student"), program_name)
leave_dates = get_dates_from_timegrain(
leave_data.get("from_date"), leave_data.get("to_date")
)
for student_group in student_groups:
make_attendance_records(
leave_data.get("student"),
leave_data.get("student_name"),
"Absent",
None,
student_group.get("label"),
leave_data.get("from_date"),
)
for leave_date in leave_dates:
make_attendance_records(
leave_data.get("student"),
leave_data.get("student_name"),
"Leave",
None,
student_group.get("label"),
leave_date,
)


@frappe.whitelist()
Expand Down Expand Up @@ -746,3 +749,13 @@ def get_school_abbr_logo():
)
logo = frappe.db.get_single_value("Education Settings", "school_college_logo")
return {"name": abbr, "logo": logo}


@frappe.whitelist()
def get_student_attendance(student, student_group):
print(student, student_group, "student,student_group")
return frappe.db.get_list(
"Student Attendance",
filters={"student": student, "student_group": student_group, "docstatus": 1},
fields=["date", "status", "name"],
)
6 changes: 4 additions & 2 deletions education/education/doctype/fee_schedule/test_fee_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def test_fee_schedule(self):
self.assertEqual(fee_schedule.grand_total, total_students * fee_schedule.total_amount)

def test_sales_invoice_creation_flow(self):
fee_schedule = create_fee_schedule(submit=1, due_date="2024-05-01")
due_date = frappe.utils.add_days(frappe.utils.nowdate(), 2)
fee_schedule = create_fee_schedule(submit=1, due_date=due_date)
# sales_invoice_posting_date_fee_schedule set it as 1
self.assertEqual(fee_schedule.status, "Invoice Pending")
self.assertNotEqual(fee_schedule.status, "Order Pending")
Expand All @@ -74,7 +75,8 @@ def test_sales_invoice_creation_flow(self):
def test_sales_order_creation_flow(self):
# create_so from education settings set to 1
frappe.db.set_value("Education Settings", "Education Settings", "create_so", 1)
fee_schedule = create_fee_schedule(submit=1, due_date="2024-05-01")
due_date = frappe.utils.add_days(frappe.utils.nowdate(), 2)
fee_schedule = create_fee_schedule(submit=1, due_date=due_date)

self.assertEqual(fee_schedule.status, "Order Pending")
self.assertNotEqual(fee_schedule.status, "Invoice Pending")
Expand Down
35 changes: 0 additions & 35 deletions education/education/doctype/student/test_records.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@
"options": "Student Group"
},
{
"allow_on_submit": 1,
"default": "Present",
"fieldname": "status",
"fieldtype": "Select",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Status",
"options": "Present\nAbsent",
"options": "Present\nAbsent\nLeave",
"reqd": 1
},
{
Expand Down Expand Up @@ -114,7 +115,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-12-21 19:57:03.021191",
"modified": "2024-05-23 17:14:36.280419",
"modified_by": "Administrator",
"module": "Education",
"name": "Student Attendance",
Expand Down Expand Up @@ -150,6 +151,19 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"states": [
{
"color": "Green",
"title": "Present"
},
{
"color": "Orange",
"title": "Leave"
},
{
"color": "Red",
"title": "Absent"
}
],
"title_field": "student_name"
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def update_attendance(self):
{"student": self.student, "date": date, "docstatus": ("!=", 2)},
)

status = "Present" if self.mark_as_present else "Absent"
status = "Present" if self.mark_as_present else "Leave"
if attendance:
# update existing attendance record
values = dict()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_attendance_record_creation(self):
leave_application = create_leave_application()
attendance_record = frappe.db.exists(
"Student Attendance",
{"leave_application": leave_application.name, "status": "Absent"},
{"leave_application": leave_application.name, "status": "Leave"},
)
self.assertTrue(attendance_record)

Expand All @@ -58,7 +58,7 @@ def test_attendance_record_updated(self):
attendance = create_student_attendance()
create_leave_application()
self.assertEqual(
frappe.db.get_value("Student Attendance", attendance.name, "status"), "Absent"
frappe.db.get_value("Student Attendance", attendance.name, "status"), "Leave"
)

def test_attendance_record_cancellation(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from frappe import _, msgprint
from frappe.utils import formatdate

from education.education.doctype.student_attendance.student_attendance import \
get_holiday_list
from education.education.doctype.student_attendance.student_attendance import (
get_holiday_list,
)


def execute(filters=None):
Expand All @@ -32,9 +33,9 @@ def execute(filters=None):

data = []
for student_group in active_student_group:
row = [student_group.name]
present_students = 0
absent_students = 0
leave_students = 0
student_group_strength = get_student_group_strength(student_group.name)
student_attendance = get_student_attendance(student_group.name, filters.get("date"))
if student_attendance:
Expand All @@ -43,21 +44,57 @@ def execute(filters=None):
present_students = attendance.count
elif attendance.status == "Absent":
absent_students = attendance.count
elif attendance.status == "Leave":
leave_students = attendance.count

unmarked_students = student_group_strength - (present_students + absent_students)
row += [student_group_strength, present_students, absent_students, unmarked_students]
unmarked_students = student_group_strength - (
present_students + absent_students + leave_students
)
row = {
"student_group": student_group.name,
"student_group_strength": student_group_strength,
"present_students": present_students,
"absent_students": absent_students,
"leave_students": leave_students,
"unmarked_students": unmarked_students,
}
data.append(row)

return columns, data


def get_columns(filters):
columns = [
_("Student Group") + ":Link/Student Group:250",
_("Student Group Strength") + "::170",
_("Present") + "::90",
_("Absent") + "::90",
_("Not Marked") + "::90",
{
"label": _("Student Group"),
"fieldname": "student_group",
"fieldtype": "Link",
"options": "Student Group",
"width": 250,
},
{
"label": _("Student Group Strength"),
"fieldname": "student_group_strength",
"fieldtype": "Int",
"width": 200,
},
{
"label": _("Present"),
"fieldname": "present_students",
"fieldtype": "Int",
"width": 90,
},
{
"label": _("Leave"),
"fieldname": "leave_students",
"fieldtype": "Int",
"width": 90,
},
{
"label": _("Absent"),
"fieldname": "absent_students",
"fieldtype": "Int",
"width": 90,
},
]
return columns

Expand Down
Loading

0 comments on commit 8ce379e

Please sign in to comment.