Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies and contributors |
| 2 | # For license information, please see license.txt |
| 3 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 4 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 5 | import json |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 6 | |
| 7 | import frappe |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 8 | from frappe import _ |
Neil Trini Lasrado | fa2023d | 2017-02-13 19:26:16 +0530 | [diff] [blame] | 9 | from frappe.email.doctype.email_group.email_group import add_subscribers |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 10 | from frappe.model.mapper import get_mapped_doc |
| 11 | from frappe.utils import cstr, flt, getdate |
| 12 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 13 | |
Manas Solanki | f60bd60 | 2017-06-01 18:30:35 +0530 | [diff] [blame] | 14 | def get_course(program): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 15 | """Return list of courses for a particular program |
Manas Solanki | f60bd60 | 2017-06-01 18:30:35 +0530 | [diff] [blame] | 16 | :param program: Program |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 17 | """ |
| 18 | courses = frappe.db.sql( |
| 19 | """select course, course_name from `tabProgram Course` where parent=%s""", (program), as_dict=1 |
| 20 | ) |
Manas Solanki | f60bd60 | 2017-06-01 18:30:35 +0530 | [diff] [blame] | 21 | return courses |
| 22 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 23 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 24 | @frappe.whitelist() |
| 25 | def enroll_student(source_name): |
| 26 | """Creates a Student Record and returns a Program Enrollment. |
| 27 | |
| 28 | :param source_name: Student Applicant. |
| 29 | """ |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 30 | frappe.publish_realtime("enroll_student_progress", {"progress": [1, 4]}, user=frappe.session.user) |
| 31 | student = get_mapped_doc( |
| 32 | "Student Applicant", |
| 33 | source_name, |
| 34 | {"Student Applicant": {"doctype": "Student", "field_map": {"name": "student_applicant"}}}, |
| 35 | ignore_permissions=True, |
| 36 | ) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 37 | student.save() |
Rucha Mahabal | 1a2332a | 2021-07-30 18:30:15 +0530 | [diff] [blame] | 38 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 39 | student_applicant = frappe.db.get_value( |
| 40 | "Student Applicant", source_name, ["student_category", "program"], as_dict=True |
| 41 | ) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 42 | program_enrollment = frappe.new_doc("Program Enrollment") |
| 43 | program_enrollment.student = student.name |
Rucha Mahabal | 1a2332a | 2021-07-30 18:30:15 +0530 | [diff] [blame] | 44 | program_enrollment.student_category = student_applicant.student_category |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 45 | program_enrollment.student_name = student.title |
Rucha Mahabal | 1a2332a | 2021-07-30 18:30:15 +0530 | [diff] [blame] | 46 | program_enrollment.program = student_applicant.program |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 47 | frappe.publish_realtime("enroll_student_progress", {"progress": [2, 4]}, user=frappe.session.user) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 48 | return program_enrollment |
| 49 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 50 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 51 | @frappe.whitelist() |
Manas Solanki | 426b8a1 | 2017-05-09 15:32:52 +0530 | [diff] [blame] | 52 | def check_attendance_records_exist(course_schedule=None, student_group=None, date=None): |
| 53 | """Check if Attendance Records are made against the specified Course Schedule or Student Group for given date. |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 54 | |
| 55 | :param course_schedule: Course Schedule. |
Manas Solanki | 426b8a1 | 2017-05-09 15:32:52 +0530 | [diff] [blame] | 56 | :param student_group: Student Group. |
Neil Trini Lasrado | d9bc559 | 2016-11-17 15:35:54 +0530 | [diff] [blame] | 57 | :param date: Date. |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 58 | """ |
Neil Trini Lasrado | d9bc559 | 2016-11-17 15:35:54 +0530 | [diff] [blame] | 59 | if course_schedule: |
| 60 | return frappe.get_list("Student Attendance", filters={"course_schedule": course_schedule}) |
| 61 | else: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 62 | return frappe.get_list( |
| 63 | "Student Attendance", filters={"student_group": student_group, "date": date} |
| 64 | ) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 65 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 66 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 67 | @frappe.whitelist() |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 68 | def mark_attendance( |
| 69 | students_present, students_absent, course_schedule=None, student_group=None, date=None |
| 70 | ): |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 71 | """Creates Multiple Attendance Records. |
| 72 | |
| 73 | :param students_present: Students Present JSON. |
| 74 | :param students_absent: Students Absent JSON. |
| 75 | :param course_schedule: Course Schedule. |
Manas Solanki | 426b8a1 | 2017-05-09 15:32:52 +0530 | [diff] [blame] | 76 | :param student_group: Student Group. |
Neil Trini Lasrado | d9bc559 | 2016-11-17 15:35:54 +0530 | [diff] [blame] | 77 | :param date: Date. |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 78 | """ |
Aditya Hase | 6ccb656 | 2017-08-28 18:17:36 +0530 | [diff] [blame] | 79 | |
Rucha Mahabal | b01334d | 2020-10-23 18:32:33 +0530 | [diff] [blame] | 80 | if student_group: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 81 | academic_year = frappe.db.get_value("Student Group", student_group, "academic_year") |
Rucha Mahabal | b01334d | 2020-10-23 18:32:33 +0530 | [diff] [blame] | 82 | if academic_year: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 83 | year_start_date, year_end_date = frappe.db.get_value( |
| 84 | "Academic Year", academic_year, ["year_start_date", "year_end_date"] |
| 85 | ) |
Rucha Mahabal | b01334d | 2020-10-23 18:32:33 +0530 | [diff] [blame] | 86 | if getdate(date) < getdate(year_start_date) or getdate(date) > getdate(year_end_date): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 87 | frappe.throw( |
| 88 | _("Attendance cannot be marked outside of Academic Year {0}").format(academic_year) |
| 89 | ) |
Rucha Mahabal | b01334d | 2020-10-23 18:32:33 +0530 | [diff] [blame] | 90 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 91 | present = json.loads(students_present) |
| 92 | absent = json.loads(students_absent) |
scmmishra | 5e758ae | 2018-10-29 13:03:45 +0530 | [diff] [blame] | 93 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 94 | for d in present: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 95 | make_attendance_records( |
| 96 | d["student"], d["student_name"], "Present", course_schedule, student_group, date |
| 97 | ) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 98 | |
| 99 | for d in absent: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 100 | make_attendance_records( |
| 101 | d["student"], d["student_name"], "Absent", course_schedule, student_group, date |
| 102 | ) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 103 | |
Neil Trini Lasrado | 6841b31 | 2016-12-01 18:40:27 +0530 | [diff] [blame] | 104 | frappe.db.commit() |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 105 | frappe.msgprint(_("Attendance has been marked successfully.")) |
| 106 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 107 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 108 | def make_attendance_records( |
| 109 | student, student_name, status, course_schedule=None, student_group=None, date=None |
| 110 | ): |
Manas Solanki | f869a67 | 2017-02-21 11:34:30 +0530 | [diff] [blame] | 111 | """Creates/Update Attendance Record. |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 112 | |
| 113 | :param student: Student. |
| 114 | :param student_name: Student Name. |
| 115 | :param course_schedule: Course Schedule. |
| 116 | :param status: Status (Present/Absent) |
| 117 | """ |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 118 | student_attendance = frappe.get_doc( |
| 119 | { |
| 120 | "doctype": "Student Attendance", |
| 121 | "student": student, |
| 122 | "course_schedule": course_schedule, |
| 123 | "student_group": student_group, |
| 124 | "date": date, |
| 125 | } |
| 126 | ) |
Nabin Hait | d0a2b16 | 2018-07-27 10:51:41 +0530 | [diff] [blame] | 127 | if not student_attendance: |
Manas Solanki | f869a67 | 2017-02-21 11:34:30 +0530 | [diff] [blame] | 128 | student_attendance = frappe.new_doc("Student Attendance") |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 129 | student_attendance.student = student |
| 130 | student_attendance.student_name = student_name |
| 131 | student_attendance.course_schedule = course_schedule |
Manas Solanki | 426b8a1 | 2017-05-09 15:32:52 +0530 | [diff] [blame] | 132 | student_attendance.student_group = student_group |
Neil Trini Lasrado | d9bc559 | 2016-11-17 15:35:54 +0530 | [diff] [blame] | 133 | student_attendance.date = date |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 134 | student_attendance.status = status |
Manas Solanki | f869a67 | 2017-02-21 11:34:30 +0530 | [diff] [blame] | 135 | student_attendance.save() |
Rucha Mahabal | 833682b | 2020-07-23 16:40:07 +0530 | [diff] [blame] | 136 | student_attendance.submit() |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 137 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 138 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 139 | @frappe.whitelist() |
Neil Trini Lasrado | fa2023d | 2017-02-13 19:26:16 +0530 | [diff] [blame] | 140 | def get_student_guardians(student): |
| 141 | """Returns List of Guardians of a Student. |
| 142 | |
| 143 | :param student: Student. |
| 144 | """ |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 145 | guardians = frappe.get_all("Student Guardian", fields=["guardian"], filters={"parent": student}) |
Neil Trini Lasrado | fa2023d | 2017-02-13 19:26:16 +0530 | [diff] [blame] | 146 | return guardians |
| 147 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 148 | |
Neil Trini Lasrado | fa2023d | 2017-02-13 19:26:16 +0530 | [diff] [blame] | 149 | @frappe.whitelist() |
Manas Solanki | fc85768 | 2017-07-05 16:35:35 +0530 | [diff] [blame] | 150 | def get_student_group_students(student_group, include_inactive=0): |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 151 | """Returns List of student, student_name in Student Group. |
| 152 | |
| 153 | :param student_group: Student Group. |
| 154 | """ |
Manas Solanki | fc85768 | 2017-07-05 16:35:35 +0530 | [diff] [blame] | 155 | if include_inactive: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 156 | students = frappe.get_all( |
| 157 | "Student Group Student", |
| 158 | fields=["student", "student_name"], |
| 159 | filters={"parent": student_group}, |
| 160 | order_by="group_roll_number", |
| 161 | ) |
Manas Solanki | fc85768 | 2017-07-05 16:35:35 +0530 | [diff] [blame] | 162 | else: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 163 | students = frappe.get_all( |
| 164 | "Student Group Student", |
| 165 | fields=["student", "student_name"], |
| 166 | filters={"parent": student_group, "active": 1}, |
| 167 | order_by="group_roll_number", |
| 168 | ) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 169 | return students |
| 170 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 171 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 172 | @frappe.whitelist() |
| 173 | def get_fee_structure(program, academic_term=None): |
| 174 | """Returns Fee Structure. |
| 175 | |
| 176 | :param program: Program. |
| 177 | :param academic_term: Academic Term. |
| 178 | """ |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 179 | fee_structure = frappe.db.get_values( |
| 180 | "Fee Structure", {"program": program, "academic_term": academic_term}, "name", as_dict=True |
| 181 | ) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 182 | return fee_structure[0].name if fee_structure else None |
| 183 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 184 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 185 | @frappe.whitelist() |
Neil Trini Lasrado | f02a0d4 | 2016-08-05 15:50:52 +0530 | [diff] [blame] | 186 | def get_fee_components(fee_structure): |
| 187 | """Returns Fee Components. |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 188 | |
| 189 | :param fee_structure: Fee Structure. |
| 190 | """ |
| 191 | if fee_structure: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 192 | fs = frappe.get_all( |
| 193 | "Fee Component", |
| 194 | fields=["fees_category", "description", "amount"], |
| 195 | filters={"parent": fee_structure}, |
| 196 | order_by="idx", |
| 197 | ) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 198 | return fs |
| 199 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 200 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 201 | @frappe.whitelist() |
Neil Trini Lasrado | c20adb5 | 2016-09-05 16:55:54 +0530 | [diff] [blame] | 202 | def get_fee_schedule(program, student_category=None): |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 203 | """Returns Fee Schedule. |
| 204 | |
| 205 | :param program: Program. |
Neil Trini Lasrado | c20adb5 | 2016-09-05 16:55:54 +0530 | [diff] [blame] | 206 | :param student_category: Student Category |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 207 | """ |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 208 | fs = frappe.get_all( |
| 209 | "Program Fee", |
| 210 | fields=["academic_term", "fee_structure", "due_date", "amount"], |
| 211 | filters={"parent": program, "student_category": student_category}, |
| 212 | order_by="idx", |
| 213 | ) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 214 | return fs |
| 215 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 216 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 217 | @frappe.whitelist() |
| 218 | def collect_fees(fees, amt): |
| 219 | paid_amount = flt(amt) + flt(frappe.db.get_value("Fees", fees, "paid_amount")) |
| 220 | total_amount = flt(frappe.db.get_value("Fees", fees, "total_amount")) |
| 221 | frappe.db.set_value("Fees", fees, "paid_amount", paid_amount) |
| 222 | frappe.db.set_value("Fees", fees, "outstanding_amount", (total_amount - paid_amount)) |
| 223 | return paid_amount |
| 224 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 225 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 226 | @frappe.whitelist() |
| 227 | def get_course_schedule_events(start, end, filters=None): |
| 228 | """Returns events for Course Schedule Calendar view rendering. |
| 229 | |
| 230 | :param start: Start date-time. |
| 231 | :param end: End date-time. |
| 232 | :param filters: Filters (JSON). |
| 233 | """ |
| 234 | from frappe.desk.calendar import get_event_conditions |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 235 | |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 236 | conditions = get_event_conditions("Course Schedule", filters) |
| 237 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 238 | data = frappe.db.sql( |
| 239 | """select name, course, color, |
Mohammed Yusuf Shaikh | 8b5827e | 2022-01-12 18:49:33 +0530 | [diff] [blame] | 240 | timestamp(schedule_date, from_time) as from_time, |
| 241 | timestamp(schedule_date, to_time) as to_time, |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 242 | room, student_group, 0 as 'allDay' |
| 243 | from `tabCourse Schedule` |
| 244 | where ( schedule_date between %(start)s and %(end)s ) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 245 | {conditions}""".format( |
| 246 | conditions=conditions |
| 247 | ), |
| 248 | {"start": start, "end": end}, |
| 249 | as_dict=True, |
| 250 | update={"allDay": 0}, |
| 251 | ) |
Neil Trini Lasrado | 3f0a581 | 2016-07-19 14:17:33 +0530 | [diff] [blame] | 252 | |
| 253 | return data |
Neil Trini Lasrado | 06ed74d | 2016-12-14 17:49:47 +0530 | [diff] [blame] | 254 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 255 | |
Neil Trini Lasrado | 06ed74d | 2016-12-14 17:49:47 +0530 | [diff] [blame] | 256 | @frappe.whitelist() |
Neil Trini Lasrado | 749516c | 2017-02-01 18:40:30 +0530 | [diff] [blame] | 257 | def get_assessment_criteria(course): |
| 258 | """Returns Assessmemt Criteria and their Weightage from Course Master. |
Neil Trini Lasrado | 06ed74d | 2016-12-14 17:49:47 +0530 | [diff] [blame] | 259 | |
| 260 | :param Course: Course |
| 261 | """ |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 262 | return frappe.get_all( |
| 263 | "Course Assessment Criteria", |
| 264 | fields=["assessment_criteria", "weightage"], |
| 265 | filters={"parent": course}, |
| 266 | order_by="idx", |
| 267 | ) |
Neil Trini Lasrado | 2a9e0f6 | 2017-01-09 18:25:43 +0530 | [diff] [blame] | 268 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 269 | |
Neil Trini Lasrado | 2a9e0f6 | 2017-01-09 18:25:43 +0530 | [diff] [blame] | 270 | @frappe.whitelist() |
Manas Solanki | 426b8a1 | 2017-05-09 15:32:52 +0530 | [diff] [blame] | 271 | def get_assessment_students(assessment_plan, student_group): |
Manas Solanki | 426b8a1 | 2017-05-09 15:32:52 +0530 | [diff] [blame] | 272 | student_list = get_student_group_students(student_group) |
Neil Trini Lasrado | 2a9e0f6 | 2017-01-09 18:25:43 +0530 | [diff] [blame] | 273 | for i, student in enumerate(student_list): |
| 274 | result = get_result(student.student, assessment_plan) |
| 275 | if result: |
| 276 | student_result = {} |
| 277 | for d in result.details: |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 278 | student_result.update({d.assessment_criteria: [cstr(d.score), d.grade]}) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 279 | student_result.update( |
| 280 | {"total_score": [cstr(result.total_score), result.grade], "comment": result.comment} |
| 281 | ) |
| 282 | student.update( |
| 283 | {"assessment_details": student_result, "docstatus": result.docstatus, "name": result.name} |
| 284 | ) |
Neil Trini Lasrado | 2a9e0f6 | 2017-01-09 18:25:43 +0530 | [diff] [blame] | 285 | else: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 286 | student.update({"assessment_details": None}) |
Neil Trini Lasrado | 2a9e0f6 | 2017-01-09 18:25:43 +0530 | [diff] [blame] | 287 | return student_list |
| 288 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 289 | |
Neil Trini Lasrado | 06ed74d | 2016-12-14 17:49:47 +0530 | [diff] [blame] | 290 | @frappe.whitelist() |
Neil Trini Lasrado | a56224c | 2017-01-04 17:00:43 +0530 | [diff] [blame] | 291 | def get_assessment_details(assessment_plan): |
Neil Trini Lasrado | 749516c | 2017-02-01 18:40:30 +0530 | [diff] [blame] | 292 | """Returns Assessment Criteria and Maximum Score from Assessment Plan Master. |
Neil Trini Lasrado | 06ed74d | 2016-12-14 17:49:47 +0530 | [diff] [blame] | 293 | |
Neil Trini Lasrado | a56224c | 2017-01-04 17:00:43 +0530 | [diff] [blame] | 294 | :param Assessment Plan: Assessment Plan |
Neil Trini Lasrado | 06ed74d | 2016-12-14 17:49:47 +0530 | [diff] [blame] | 295 | """ |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 296 | return frappe.get_all( |
| 297 | "Assessment Plan Criteria", |
| 298 | fields=["assessment_criteria", "maximum_score", "docstatus"], |
| 299 | filters={"parent": assessment_plan}, |
| 300 | order_by="idx", |
| 301 | ) |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 302 | |
Neil Trini Lasrado | 06ed74d | 2016-12-14 17:49:47 +0530 | [diff] [blame] | 303 | |
Neil Trini Lasrado | 2a9e0f6 | 2017-01-09 18:25:43 +0530 | [diff] [blame] | 304 | @frappe.whitelist() |
| 305 | def get_result(student, assessment_plan): |
| 306 | """Returns Submitted Result of given student for specified Assessment Plan |
| 307 | |
| 308 | :param Student: Student |
| 309 | :param Assessment Plan: Assessment Plan |
| 310 | """ |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 311 | results = frappe.get_all( |
| 312 | "Assessment Result", |
| 313 | filters={"student": student, "assessment_plan": assessment_plan, "docstatus": ("!=", 2)}, |
| 314 | ) |
Neil Trini Lasrado | 2a9e0f6 | 2017-01-09 18:25:43 +0530 | [diff] [blame] | 315 | if results: |
| 316 | return frappe.get_doc("Assessment Result", results[0]) |
| 317 | else: |
| 318 | return None |
Neil Trini Lasrado | 06ed74d | 2016-12-14 17:49:47 +0530 | [diff] [blame] | 319 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 320 | |
Neil Trini Lasrado | 06ed74d | 2016-12-14 17:49:47 +0530 | [diff] [blame] | 321 | @frappe.whitelist() |
| 322 | def get_grade(grading_scale, percentage): |
| 323 | """Returns Grade based on the Grading Scale and Score. |
| 324 | |
| 325 | :param Grading Scale: Grading Scale |
| 326 | :param Percentage: Score Percentage Percentage |
| 327 | """ |
| 328 | grading_scale_intervals = {} |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 329 | if not hasattr(frappe.local, "grading_scale"): |
| 330 | grading_scale = frappe.get_all( |
| 331 | "Grading Scale Interval", fields=["grade_code", "threshold"], filters={"parent": grading_scale} |
| 332 | ) |
Manas Solanki | 8985077 | 2018-01-26 11:20:33 +0530 | [diff] [blame] | 333 | frappe.local.grading_scale = grading_scale |
| 334 | for d in frappe.local.grading_scale: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 335 | grading_scale_intervals.update({d.threshold: d.grade_code}) |
Neil Trini Lasrado | 06ed74d | 2016-12-14 17:49:47 +0530 | [diff] [blame] | 336 | intervals = sorted(grading_scale_intervals.keys(), key=float, reverse=True) |
| 337 | for interval in intervals: |
| 338 | if flt(percentage) >= interval: |
| 339 | grade = grading_scale_intervals.get(interval) |
| 340 | break |
| 341 | else: |
Neil Trini Lasrado | 2a9e0f6 | 2017-01-09 18:25:43 +0530 | [diff] [blame] | 342 | grade = "" |
| 343 | return grade |
| 344 | |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 345 | |
Neil Trini Lasrado | 2a9e0f6 | 2017-01-09 18:25:43 +0530 | [diff] [blame] | 346 | @frappe.whitelist() |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 347 | def mark_assessment_result(assessment_plan, scores): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 348 | student_score = json.loads(scores) |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 349 | assessment_details = [] |
| 350 | for criteria in student_score.get("assessment_details"): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 351 | assessment_details.append( |
| 352 | {"assessment_criteria": criteria, "score": flt(student_score["assessment_details"][criteria])} |
| 353 | ) |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 354 | assessment_result = get_assessment_result_doc(student_score["student"], assessment_plan) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 355 | assessment_result.update( |
| 356 | { |
| 357 | "student": student_score.get("student"), |
| 358 | "assessment_plan": assessment_plan, |
| 359 | "comment": student_score.get("comment"), |
| 360 | "total_score": student_score.get("total_score"), |
| 361 | "details": assessment_details, |
| 362 | } |
| 363 | ) |
Neil Trini Lasrado | 2a9e0f6 | 2017-01-09 18:25:43 +0530 | [diff] [blame] | 364 | assessment_result.save() |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 365 | details = {} |
| 366 | for d in assessment_result.details: |
| 367 | details.update({d.assessment_criteria: d.grade}) |
| 368 | assessment_result_dict = { |
| 369 | "name": assessment_result.name, |
| 370 | "student": assessment_result.student, |
| 371 | "total_score": assessment_result.total_score, |
| 372 | "grade": assessment_result.grade, |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 373 | "details": details, |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 374 | } |
| 375 | return assessment_result_dict |
| 376 | |
| 377 | |
| 378 | @frappe.whitelist() |
| 379 | def submit_assessment_results(assessment_plan, student_group): |
| 380 | total_result = 0 |
| 381 | student_list = get_student_group_students(student_group) |
| 382 | for i, student in enumerate(student_list): |
| 383 | doc = get_result(student.student, assessment_plan) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 384 | if doc and doc.docstatus == 0: |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 385 | total_result += 1 |
| 386 | doc.submit() |
| 387 | return total_result |
| 388 | |
| 389 | |
| 390 | def get_assessment_result_doc(student, assessment_plan): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 391 | assessment_result = frappe.get_all( |
| 392 | "Assessment Result", |
| 393 | filters={"student": student, "assessment_plan": assessment_plan, "docstatus": ("!=", 2)}, |
| 394 | ) |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 395 | if assessment_result: |
| 396 | doc = frappe.get_doc("Assessment Result", assessment_result[0]) |
| 397 | if doc.docstatus == 0: |
| 398 | return doc |
| 399 | elif doc.docstatus == 1: |
Nabin Hait | e6d65bc | 2018-02-14 17:44:06 +0530 | [diff] [blame] | 400 | frappe.msgprint(_("Result already Submitted")) |
Manas Solanki | a22c94c | 2017-09-18 16:59:54 +0530 | [diff] [blame] | 401 | return None |
| 402 | else: |
| 403 | return frappe.new_doc("Assessment Result") |
| 404 | |
Neil Trini Lasrado | fa2023d | 2017-02-13 19:26:16 +0530 | [diff] [blame] | 405 | |
| 406 | @frappe.whitelist() |
| 407 | def update_email_group(doctype, name): |
| 408 | if not frappe.db.exists("Email Group", name): |
| 409 | email_group = frappe.new_doc("Email Group") |
| 410 | email_group.title = name |
| 411 | email_group.save() |
| 412 | email_list = [] |
| 413 | students = [] |
Neil Trini Lasrado | fa2023d | 2017-02-13 19:26:16 +0530 | [diff] [blame] | 414 | if doctype == "Student Group": |
| 415 | students = get_student_group_students(name) |
| 416 | for stud in students: |
| 417 | for guard in get_student_guardians(stud.student): |
| 418 | email = frappe.db.get_value("Guardian", guard.guardian, "email_address") |
| 419 | if email: |
scmmishra | 5e758ae | 2018-10-29 13:03:45 +0530 | [diff] [blame] | 420 | email_list.append(email) |
Nabin Hait | 753c8de | 2017-02-22 11:53:13 +0530 | [diff] [blame] | 421 | add_subscribers(name, email_list) |
Manas Solanki | 4e0559b | 2017-07-25 15:22:47 +0530 | [diff] [blame] | 422 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 423 | |
Manas Solanki | 4e0559b | 2017-07-25 15:22:47 +0530 | [diff] [blame] | 424 | @frappe.whitelist() |
| 425 | def get_current_enrollment(student, academic_year=None): |
| 426 | current_academic_year = academic_year or frappe.defaults.get_defaults().academic_year |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 427 | program_enrollment_list = frappe.db.sql( |
| 428 | """ |
Manas Solanki | 152ba1e | 2017-08-02 15:11:32 +0530 | [diff] [blame] | 429 | select |
| 430 | name as program_enrollment, student_name, program, student_batch_name as student_batch, |
| 431 | student_category, academic_term, academic_year |
Rucha Mahabal | 833682b | 2020-07-23 16:40:07 +0530 | [diff] [blame] | 432 | from |
Manas Solanki | 152ba1e | 2017-08-02 15:11:32 +0530 | [diff] [blame] | 433 | `tabProgram Enrollment` |
Rucha Mahabal | 833682b | 2020-07-23 16:40:07 +0530 | [diff] [blame] | 434 | where |
Manas Solanki | 152ba1e | 2017-08-02 15:11:32 +0530 | [diff] [blame] | 435 | student = %s and academic_year = %s |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 436 | order by creation""", |
| 437 | (student, current_academic_year), |
| 438 | as_dict=1, |
| 439 | ) |
Manas Solanki | 152ba1e | 2017-08-02 15:11:32 +0530 | [diff] [blame] | 440 | |
Manas Solanki | 152ba1e | 2017-08-02 15:11:32 +0530 | [diff] [blame] | 441 | if program_enrollment_list: |
| 442 | return program_enrollment_list[0] |
| 443 | else: |
| 444 | return None |