test case fixed
This commit is contained in:
parent
810e483757
commit
6293263095
@ -13,7 +13,7 @@ class CourseSchedule(Document):
|
||||
self.set_title()
|
||||
self.validate_mandatory()
|
||||
self.validate_course()
|
||||
self.set_student_batch()
|
||||
# self.set_student_batch()
|
||||
self.validate_date()
|
||||
self.validate_overlap()
|
||||
|
||||
|
@ -24,28 +24,28 @@ class TestCourseSchedule(unittest.TestCase):
|
||||
cs1 = make_course_schedule_test_record(simulate= True)
|
||||
|
||||
cs2 = make_course_schedule_test_record(from_time= cs1.from_time, to_time= cs1.to_time,
|
||||
student_group="TC1-TP2--2014-2015-2014-2015 (_Test Academic Term)", room="RM0002", do_not_save= 1)
|
||||
student_group="Course-TC101-2014-2015 (_Test Academic Term)", room="RM0002", do_not_save= 1)
|
||||
self.assertRaises(OverlapError, cs2.save)
|
||||
|
||||
def test_room_conflict(self):
|
||||
cs1 = make_course_schedule_test_record(simulate= True)
|
||||
|
||||
cs2 = make_course_schedule_test_record(from_time= cs1.from_time, to_time= cs1.to_time,
|
||||
student_group="TC1-TP2--2014-2015-2014-2015 (_Test Academic Term)", instructor="_T-Instructor-00002", do_not_save= 1)
|
||||
student_group="Course-TC101-2014-2015 (_Test Academic Term)", instructor="_T-Instructor-00002", do_not_save= 1)
|
||||
self.assertRaises(OverlapError, cs2.save)
|
||||
|
||||
def test_no_conflict(self):
|
||||
cs1 = make_course_schedule_test_record(simulate= True)
|
||||
|
||||
make_course_schedule_test_record(from_time= cs1.from_time, to_time= cs1.to_time,
|
||||
student_group="TC1-TP2-2014-2015-2014-2015 (_Test Academic Term)", instructor="_T-Instructor-00002", room="RM0002")
|
||||
student_group="Course-TC102-2014-2015 (_Test Academic Term)", instructor="_T-Instructor-00002", room="RM0002")
|
||||
|
||||
def make_course_schedule_test_record(**args):
|
||||
args = frappe._dict(args)
|
||||
|
||||
course_schedule = frappe.new_doc("Course Schedule")
|
||||
course_schedule.student_group = args.student_group or "TC-TP1-2014-2015-2014-2015 (_Test Academic Term)"
|
||||
course_schedule.course = args.course or "TC100"
|
||||
course_schedule.student_group = args.student_group or "Course-TC101-2014-2015 (_Test Academic Term)"
|
||||
course_schedule.course = args.course or "TC101"
|
||||
course_schedule.instructor = args.instructor or "_T-Instructor-00001"
|
||||
course_schedule.room = args.room or "RM0001"
|
||||
|
||||
|
@ -71,31 +71,47 @@ frappe.ui.form.on("Student Group", {
|
||||
frm.trigger("set_name");
|
||||
},
|
||||
|
||||
update_students: function(frm) {
|
||||
if (frm.doc.students.length === 0) {
|
||||
frm.doc.next_group_roll_number = 1;
|
||||
}
|
||||
frappe.call({
|
||||
method: "update_students",
|
||||
doc:frm.doc,
|
||||
callback: function(r) {
|
||||
if(r.message) {
|
||||
$.each(r.message, function(i, d) {
|
||||
var s = frm.add_child("students");
|
||||
s.student = d.student;
|
||||
s.student_name = d.student_name;
|
||||
if (d.active === 0) {
|
||||
s.active = 0;
|
||||
}
|
||||
s.group_roll_number = frm.doc.next_group_roll_number;
|
||||
frm.doc.next_group_roll_number += 1;
|
||||
});
|
||||
frm.save();
|
||||
} else {
|
||||
frappe.msgprint(__("Group already updated"))
|
||||
get_students: function(frm) {
|
||||
if (frm.doc.group_based_on != "Activity") {
|
||||
var student_list = [];
|
||||
var max_roll_no = 0;
|
||||
$.each(frm.doc.students, function(i,d) {
|
||||
student_list.push(d.student);
|
||||
if (d.group_roll_number>max_roll_no) {
|
||||
max_roll_no = d.group_roll_number;
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
frappe.call({
|
||||
method: "erpnext.schools.doctype.student_group.student_group.get_students",
|
||||
args: {
|
||||
"academic_year": frm.doc.academic_year,
|
||||
"group_based_on": frm.doc.group_based_on,
|
||||
"program": frm.doc.program,
|
||||
"batch" : frm.doc.batch,
|
||||
"course": frm.doc.course
|
||||
},
|
||||
callback: function(r) {
|
||||
if(r.message) {
|
||||
$.each(r.message, function(i, d) {
|
||||
if(!in_list(student_list, d.student)) {
|
||||
var s = frm.add_child("students");
|
||||
s.student = d.student;
|
||||
s.student_name = d.student_name;
|
||||
if (d.active === 0) {
|
||||
s.active = 0;
|
||||
}
|
||||
s.group_roll_number = ++max_roll_no;
|
||||
}
|
||||
});
|
||||
frm.save();
|
||||
} else {
|
||||
frappe.msgprint(__("Student Group is already updated."))
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
frappe.msgprint(__("Select students manually for the Activity based Group"));
|
||||
}
|
||||
}
|
||||
|
||||
});
|
@ -14,6 +14,7 @@
|
||||
"engine": "InnoDB",
|
||||
"fields": [
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -44,6 +45,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -74,6 +76,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -104,6 +107,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -132,6 +136,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -162,6 +167,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -193,6 +199,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -224,6 +231,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -255,6 +263,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -285,6 +294,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -316,11 +326,12 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "update_students",
|
||||
"fieldname": "get_students",
|
||||
"fieldtype": "Button",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
@ -329,7 +340,7 @@
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Update Students",
|
||||
"label": "Get Students",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
@ -345,6 +356,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 1,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -375,6 +387,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -404,6 +417,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -432,35 +446,6 @@
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "next_group_roll_number",
|
||||
"fieldtype": "Int",
|
||||
"hidden": 1,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Next Group Roll Number",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"has_web_view": 0,
|
||||
@ -474,7 +459,7 @@
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"menu_index": 0,
|
||||
"modified": "2017-04-19 12:48:46.526133",
|
||||
"modified": "2017-04-24 15:53:35.593913",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Schools",
|
||||
"name": "Student Group",
|
||||
|
@ -27,47 +27,42 @@ class StudentGroup(Document):
|
||||
frappe.throw(_("""Cannot enroll more than {0} students for this student group.""").format(self.max_strength))
|
||||
|
||||
def validate_students(self):
|
||||
program_enrollment = self.get_program_enrollment()
|
||||
program_enrollment = get_program_enrollment(self.academic_year, self.group_based_on, self.program, self.batch, self.course)
|
||||
students = [d.student for d in program_enrollment] if program_enrollment else None
|
||||
for d in self.students:
|
||||
if d.student not in students:
|
||||
if self.group_based_on != "Activity" and d.student not in students:
|
||||
frappe.throw(_("{0} - {1} is not enrolled in the given {2}".format(d.student, d.student_name, self.group_based_on)))
|
||||
if not frappe.db.get_value("Student", d.student, "enabled") and d.active:
|
||||
d.active = 0
|
||||
frappe.throw(_("{0} - {1} is inactive student".format(d.student, d.student_name)))
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_students(academic_year, group_based_on, program=None, batch=None, course=None):
|
||||
enrolled_students = get_program_enrollment(academic_year, group_based_on, program, batch, course)
|
||||
|
||||
def update_students(self):
|
||||
enrolled_students = self.get_program_enrollment()
|
||||
group_student_list = [student.student for student in self.students]
|
||||
if enrolled_students:
|
||||
student_list = []
|
||||
for s in enrolled_students:
|
||||
if frappe.db.get_value("Student", s.student, "enabled"):
|
||||
s.update({"active": 1})
|
||||
else:
|
||||
s.update({"active": 0})
|
||||
student_list.append(s)
|
||||
return student_list
|
||||
|
||||
if enrolled_students:
|
||||
student_list = [];
|
||||
for s in enrolled_students:
|
||||
if s.student not in group_student_list:
|
||||
student_list.append(s.update({"active": 1}) if frappe.db.get_value("Student", s.student, "enabled")
|
||||
else s.update({"active": 0}))
|
||||
return student_list
|
||||
elif self.group_based_on != "Activity":
|
||||
frappe.throw(_("No students are enrolled in the given {}".format(self.group_based_on)))
|
||||
else:
|
||||
frappe.throw(_("Select students manually for the Activity based Group"))
|
||||
def get_program_enrollment(academic_year, group_based_on, program=None, batch=None, course=None):
|
||||
if group_based_on == "Batch":
|
||||
return frappe.db.sql('''select student, student_name from `tabProgram Enrollment` where academic_year = %s
|
||||
and program = %s and student_batch_name = %s order by student_name asc''',(academic_year, program, batch), as_dict=1)
|
||||
|
||||
def get_program_enrollment(self):
|
||||
if self.group_based_on == "Batch":
|
||||
return frappe.db.sql('''select student, student_name from `tabProgram Enrollment` where academic_year = %s
|
||||
and program = %s and student_batch_name = %s order by student_name asc''',(self.academic_year, self.program, self.batch), as_dict=1)
|
||||
|
||||
elif self.group_based_on == "Course":
|
||||
return frappe.db.sql('''
|
||||
select
|
||||
pe.student, pe.student_name
|
||||
from
|
||||
`tabProgram Enrollment` pe, `tabProgram Enrollment Course` pec
|
||||
where
|
||||
pe.name = pec.parent and pec.course = %s
|
||||
order by
|
||||
pe.student_name asc
|
||||
''', (self.course), as_dict=1)
|
||||
else:
|
||||
return
|
||||
elif group_based_on == "Course":
|
||||
return frappe.db.sql('''
|
||||
select
|
||||
pe.student, pe.student_name
|
||||
from
|
||||
`tabProgram Enrollment` pe, `tabProgram Enrollment Course` pec
|
||||
where
|
||||
pe.name = pec.parent and pec.course = %s
|
||||
order by
|
||||
pe.student_name asc
|
||||
''', (course), as_dict=1)
|
@ -14,6 +14,13 @@
|
||||
"academic_year": "2014-2015",
|
||||
"academic_term": "2014-2015 (_Test Academic Term)"
|
||||
},
|
||||
{
|
||||
"student_group_name": "Course-TC102-2014-2015 (_Test Academic Term)",
|
||||
"group_based_on": "Course",
|
||||
"course": "TC102",
|
||||
"academic_year": "2014-2015",
|
||||
"academic_term": "2014-2015 (_Test Academic Term)"
|
||||
},
|
||||
{
|
||||
"student_group_name": "Activity-2014-2015 (_Test Academic Term)",
|
||||
"group_based_on": "Activity",
|
||||
|
Loading…
Reference in New Issue
Block a user