blob: e48748e621bdc25f25f160a0453659ca1c49bd32 [file] [log] [blame]
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +05301# -*- coding: utf-8 -*-
2# Copyright (c) 2015, Frappe Technologies and contributors
3# For license information, please see license.txt
4
5from __future__ import unicode_literals
6import frappe
7import json
8from frappe import _
9from frappe.model.mapper import get_mapped_doc
10from frappe.utils import flt
11
12@frappe.whitelist()
13def enroll_student(source_name):
14 """Creates a Student Record and returns a Program Enrollment.
15
16 :param source_name: Student Applicant.
17 """
18 student = get_mapped_doc("Student Applicant", source_name,
19 {"Student Applicant": {
20 "doctype": "Student",
21 "field_map": {
22 "name": "student_applicant"
23 }
Neil Trini Lasrado06724592016-08-22 12:57:09 +053024 }}, ignore_permissions=True)
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053025 student.save()
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053026 program_enrollment = frappe.new_doc("Program Enrollment")
27 program_enrollment.student = student.name
28 program_enrollment.student_name = student.title
29 program_enrollment.program = frappe.db.get_value("Student Applicant", source_name, "program")
30 return program_enrollment
31
32@frappe.whitelist()
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053033def check_attendance_records_exist(course_schedule=None, student_batch=None, date=None):
34 """Check if Attendance Records are made against the specified Course Schedule or Student Batch for given date.
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053035
36 :param course_schedule: Course Schedule.
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053037 :param student_batch: Student Batch.
38 :param date: Date.
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053039 """
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053040 if course_schedule:
41 return frappe.get_list("Student Attendance", filters={"course_schedule": course_schedule})
42 else:
43 return frappe.get_list("Student Attendance", filters={"student_batch": student_batch, "date": date})
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053044
45@frappe.whitelist()
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053046def mark_attendance(students_present, students_absent, course_schedule=None, student_batch=None, date=None):
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053047 """Creates Multiple Attendance Records.
48
49 :param students_present: Students Present JSON.
50 :param students_absent: Students Absent JSON.
51 :param course_schedule: Course Schedule.
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053052 :param student_batch: Student Batch.
53 :param date: Date.
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053054 """
Neil Trini Lasradoeccbf432016-12-09 17:38:59 +053055
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053056 present = json.loads(students_present)
57 absent = json.loads(students_absent)
Neil Trini Lasradoeccbf432016-12-09 17:38:59 +053058
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053059 for d in present:
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053060 make_attendance_records(d["student"], d["student_name"], "Present", course_schedule, student_batch, date)
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053061
62 for d in absent:
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053063 make_attendance_records(d["student"], d["student_name"], "Absent", course_schedule, student_batch, date)
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053064
Neil Trini Lasrado6841b312016-12-01 18:40:27 +053065 frappe.db.commit()
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053066 frappe.msgprint(_("Attendance has been marked successfully."))
67
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053068def make_attendance_records(student, student_name, status, course_schedule=None, student_batch=None, date=None):
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053069 """Creates Attendance Record.
70
71 :param student: Student.
72 :param student_name: Student Name.
73 :param course_schedule: Course Schedule.
74 :param status: Status (Present/Absent)
75 """
76 student_attendance = frappe.new_doc("Student Attendance")
77 student_attendance.student = student
78 student_attendance.student_name = student_name
79 student_attendance.course_schedule = course_schedule
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053080 student_attendance.student_batch = student_batch
81 student_attendance.date = date
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053082 student_attendance.status = status
83 student_attendance.submit()
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053084
85@frappe.whitelist()
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053086def get_student_batch_students(student_batch):
87 """Returns List of student, student_name in Student Batch.
88
89 :param student_batch: Student Batch.
90 """
Neil Trini Lasrado6841b312016-12-01 18:40:27 +053091 students = frappe.get_list("Student Batch Student", fields=["student", "student_name", "idx"] , filters={"parent": student_batch}, order_by= "idx")
Neil Trini Lasradod9bc5592016-11-17 15:35:54 +053092 return students
93
94@frappe.whitelist()
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053095def get_student_group_students(student_group):
96 """Returns List of student, student_name in Student Group.
97
98 :param student_group: Student Group.
99 """
100 students = frappe.get_list("Student Group Student", fields=["student", "student_name"] , filters={"parent": student_group}, order_by= "idx")
101 return students
102
103@frappe.whitelist()
104def get_fee_structure(program, academic_term=None):
105 """Returns Fee Structure.
106
107 :param program: Program.
108 :param academic_term: Academic Term.
109 """
110 fee_structure = frappe.db.get_values("Fee Structure", {"program": program,
111 "academic_term": academic_term}, 'name', as_dict=True)
112 return fee_structure[0].name if fee_structure else None
113
114@frappe.whitelist()
Neil Trini Lasradof02a0d42016-08-05 15:50:52 +0530115def get_fee_components(fee_structure):
116 """Returns Fee Components.
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +0530117
118 :param fee_structure: Fee Structure.
119 """
120 if fee_structure:
Neil Trini Lasradof02a0d42016-08-05 15:50:52 +0530121 fs = frappe.get_list("Fee Component", fields=["fees_category", "amount"] , filters={"parent": fee_structure}, order_by= "idx")
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +0530122 return fs
123
124@frappe.whitelist()
Neil Trini Lasradoc20adb52016-09-05 16:55:54 +0530125def get_fee_schedule(program, student_category=None):
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +0530126 """Returns Fee Schedule.
127
128 :param program: Program.
Neil Trini Lasradoc20adb52016-09-05 16:55:54 +0530129 :param student_category: Student Category
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +0530130 """
131 fs = frappe.get_list("Program Fee", fields=["academic_term", "fee_structure", "due_date", "amount"] ,
Neil Trini Lasradoc20adb52016-09-05 16:55:54 +0530132 filters={"parent": program, "student_category": student_category }, order_by= "idx")
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +0530133 return fs
134
135@frappe.whitelist()
136def collect_fees(fees, amt):
137 paid_amount = flt(amt) + flt(frappe.db.get_value("Fees", fees, "paid_amount"))
138 total_amount = flt(frappe.db.get_value("Fees", fees, "total_amount"))
139 frappe.db.set_value("Fees", fees, "paid_amount", paid_amount)
140 frappe.db.set_value("Fees", fees, "outstanding_amount", (total_amount - paid_amount))
141 return paid_amount
142
143@frappe.whitelist()
144def get_course_schedule_events(start, end, filters=None):
145 """Returns events for Course Schedule Calendar view rendering.
146
147 :param start: Start date-time.
148 :param end: End date-time.
149 :param filters: Filters (JSON).
150 """
151 from frappe.desk.calendar import get_event_conditions
152 conditions = get_event_conditions("Course Schedule", filters)
153
154 data = frappe.db.sql("""select name, course,
155 timestamp(schedule_date, from_time) as from_datetime,
156 timestamp(schedule_date, to_time) as to_datetime,
157 room, student_group, 0 as 'allDay'
158 from `tabCourse Schedule`
159 where ( schedule_date between %(start)s and %(end)s )
160 {conditions}""".format(conditions=conditions), {
161 "start": start,
162 "end": end
163 }, as_dict=True, update={"allDay": 0})
164
165 return data
Neil Trini Lasrado06ed74d2016-12-14 17:49:47 +0530166
167@frappe.whitelist()
168def get_evaluation_criterias(course):
169 """Returns Evaluation Criterias and their Weightage from Course Master.
170
171 :param Course: Course
172 """
173 return frappe.get_list("Course Evaluation Criteria", \
174 fields=["evaluation_criteria", "weightage"], filters={"parent": course}, order_by= "idx")
175
176@frappe.whitelist()
Neil Trini Lasradoa56224c2017-01-04 17:00:43 +0530177def get_assessment_details(assessment_plan):
178 """Returns Evaluation Criteria and Maximum Score from Assessment Plan Master.
Neil Trini Lasrado06ed74d2016-12-14 17:49:47 +0530179
Neil Trini Lasradoa56224c2017-01-04 17:00:43 +0530180 :param Assessment Plan: Assessment Plan
Neil Trini Lasrado06ed74d2016-12-14 17:49:47 +0530181 """
182 return frappe.get_list("Assessment Evaluation Criteria", \
Neil Trini Lasradoa56224c2017-01-04 17:00:43 +0530183 fields=["evaluation_criteria", "maximum_score"], filters={"parent": assessment_plan}, order_by= "idx")
Neil Trini Lasrado06ed74d2016-12-14 17:49:47 +0530184
185
186@frappe.whitelist()
187def get_grade(grading_scale, percentage):
188 """Returns Grade based on the Grading Scale and Score.
189
190 :param Grading Scale: Grading Scale
191 :param Percentage: Score Percentage Percentage
192 """
193 grading_scale_intervals = {}
Neil Trini Lasrado233ecfd2017-01-04 15:41:38 +0530194 for d in frappe.get_all("Grading Scale Interval", fields=["grade_code", "threshold"], filters={"parent": grading_scale}):
195 grading_scale_intervals.update({d.threshold:d.grade_code})
Neil Trini Lasrado06ed74d2016-12-14 17:49:47 +0530196 intervals = sorted(grading_scale_intervals.keys(), key=float, reverse=True)
197 for interval in intervals:
198 if flt(percentage) >= interval:
199 grade = grading_scale_intervals.get(interval)
200 break
201 else:
202 grade = "Unsuccessful"
203 return grade