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