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