Fixes in Student Group
diff --git a/erpnext/schools/doctype/student_group/student_group.js b/erpnext/schools/doctype/student_group/student_group.js
index 29d8bdb..c2c6912 100644
--- a/erpnext/schools/doctype/student_group/student_group.js
+++ b/erpnext/schools/doctype/student_group/student_group.js
@@ -1,4 +1,4 @@
- cur_frm.add_fetch("student", "title", "student_name");
+cur_frm.add_fetch("student", "title", "student_name");
frappe.ui.form.on("Student Group", {
onload: function(frm) {
@@ -39,41 +39,6 @@
if (frm.doc.group_based_on == "Batch") {
frm.doc.course = null;
}
- else if (frm.doc.group_based_on == "Course") {
- frm.doc.program = null;
- frm.doc.batch = null;
- }
- else if (frm.doc.group_based_on == "Activity") {
- frm.doc.program =null;
- frm.doc.batch =null;
- frm.doc.CourseQ =null;
- }
- frm.trigger("set_name");
- },
-
- set_name: function(frm) {
- var name;
- if (frm.doc.group_based_on == "Course") {
- name = "Course-" + frm.doc.course + "-" + (frm.doc.academic_term?frm.doc.academic_term:frm.doc.academic_year);
- } else if (frm.doc.group_based_on == "Batch") {
- name = "Batch-" + frm.doc.program + "-" + frm.doc.batch + "-"
- + (frm.doc.academic_term?frm.doc.academic_term:frm.doc.academic_year);
- } else if (frm.doc.group_based_on == "Activity") {
- name = "Activity" + "-" + (frm.doc.academic_term?frm.doc.academic_term:frm.doc.academic_year);
- }
- frm.set_value("student_group_name", name);
- },
-
- program:function(frm) {
- frm.trigger("set_name");
- },
-
- batch:function(frm) {
- frm.trigger("set_name");
- },
-
- course:function(frm) {
- frm.trigger("set_name");
},
get_students: function(frm) {
@@ -90,6 +55,7 @@
method: "erpnext.schools.doctype.student_group.student_group.get_students",
args: {
"academic_year": frm.doc.academic_year,
+ "academic_term": frm.doc.academic_term,
"group_based_on": frm.doc.group_based_on,
"program": frm.doc.program,
"batch" : frm.doc.batch,
@@ -119,5 +85,4 @@
frappe.msgprint(__("Select students manually for the Activity based Group"));
}
}
-
});
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_group/student_group.json b/erpnext/schools/doctype/student_group/student_group.json
index 2caaa7c..a82ac0f 100644
--- a/erpnext/schools/doctype/student_group/student_group.json
+++ b/erpnext/schools/doctype/student_group/student_group.json
@@ -72,7 +72,7 @@
"report_hide": 0,
"reqd": 1,
"search_index": 0,
- "set_only_once": 1,
+ "set_only_once": 0,
"unique": 0
},
{
@@ -81,7 +81,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "depends_on": "eval: doc.batch || doc.course || doc.group_based_on == \"Activity\"",
+ "depends_on": "",
"fieldname": "student_group_name",
"fieldtype": "Data",
"hidden": 0,
@@ -101,7 +101,7 @@
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
- "reqd": 0,
+ "reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
@@ -194,7 +194,7 @@
"report_hide": 0,
"reqd": 0,
"search_index": 0,
- "set_only_once": 1,
+ "set_only_once": 0,
"unique": 0
},
{
@@ -203,7 +203,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "depends_on": "eval:doc.group_based_on == 'Batch' || doc.group_based_on == 'Course' ",
+ "depends_on": "",
"fieldname": "program",
"fieldtype": "Link",
"hidden": 0,
@@ -226,7 +226,7 @@
"report_hide": 0,
"reqd": 0,
"search_index": 0,
- "set_only_once": 1,
+ "set_only_once": 0,
"unique": 0
},
{
@@ -235,7 +235,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "depends_on": "eval:doc.group_based_on == 'Batch' || doc.group_based_on == 'Course' ",
+ "depends_on": "",
"fieldname": "batch",
"fieldtype": "Link",
"hidden": 0,
@@ -258,7 +258,7 @@
"report_hide": 0,
"reqd": 0,
"search_index": 0,
- "set_only_once": 1,
+ "set_only_once": 0,
"unique": 0
},
{
@@ -290,7 +290,7 @@
"report_hide": 0,
"reqd": 0,
"search_index": 0,
- "set_only_once": 1,
+ "set_only_once": 0,
"unique": 0
},
{
@@ -459,7 +459,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
- "modified": "2017-04-25 18:26:27.414487",
+ "modified": "2017-04-28 11:46:51.946103",
"modified_by": "Administrator",
"module": "Schools",
"name": "Student Group",
diff --git a/erpnext/schools/doctype/student_group/student_group.py b/erpnext/schools/doctype/student_group/student_group.py
index afcf970..5520ec7 100644
--- a/erpnext/schools/doctype/student_group/student_group.py
+++ b/erpnext/schools/doctype/student_group/student_group.py
@@ -13,34 +13,34 @@
def validate(self):
self.validate_mandatory_fields()
self.validate_strength()
- if frappe.defaults.get_defaults().student_validation_setting
+ if frappe.defaults.get_defaults().student_validation_setting:
self.validate_students()
validate_duplicate_student(self.students)
def validate_mandatory_fields(self):
if self.group_based_on == "Course" and not self.course:
frappe.throw(_("Please select Course"))
- elif self.group_based_on == "Batch" and (not self.program or not self.batch):
- frappe.throw(_("Please select Program and Batch"))
+ if self.group_based_on == "Course" and (not self.program and self.batch):
+ frappe.throw(_("Please select Program"))
+ if self.group_based_on == "Batch" and not self.program:
+ frappe.throw(_("Please select Program"))
def validate_strength(self):
if self.max_strength and len(self.students) > self.max_strength:
frappe.throw(_("""Cannot enroll more than {0} students for this student group.""").format(self.max_strength))
def validate_students(self):
- program_enrollment = get_program_enrollment(self.academic_year, self.group_based_on, self.program, self.batch, self.course)
+ program_enrollment = get_program_enrollment(self.academic_year, self.academic_term, 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 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 self.group_based_on != "Activity" and d.student not in students and d.active == 1:
+ frappe.throw(_("{0} - {1} is not enrolled in the given {2}".format(d.group_roll_number, 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.throw(_("{0} - {1} is inactive student".format(d.group_roll_number, 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)
- print enrolled_students
+def get_students(academic_year, group_based_on, academic_term=None, program=None, batch=None, course=None):
+ enrolled_students = get_program_enrollment(academic_year, academic_term, program, batch, course)
if enrolled_students:
student_list = []
@@ -51,32 +51,32 @@
s.update({"active": 0})
student_list.append(s)
return student_list
+ else:
+ frappe.throw(_("No students found"))
-def get_program_enrollment(academic_year, group_based_on, program=None, batch=None, course=None):
+def get_program_enrollment(academic_year, academic_term=None, program=None, batch=None, course=None):
- condition_course = " and pe.name = pec.parent and pec.course = %(course)s"
- condition1_course = ", `tabProgram Enrollment Course` pec"
- condition_batch = " and pe.program = %(program)s and pe.student_batch_name = %(batch)s"
-
- if group_based_on == "Batch":
- condition1 = ""
- condition2 = condition_batch
- elif group_based_on == "Course" and not (program and batch):
- condition1 = condition1_course
- condition2 = condition_course
- elif group_based_on == "Course" and program and batch:
- condition1 = condition1_course
- condition2 = condition_course + condition_batch
+ condition1 = " "
+ condition2 = " "
+ if academic_term:
+ condition1 += " and pe.academic_term = %(academic_term)s"
+ if program:
+ condition1 += " and pe.program = %(program)s"
+ if batch:
+ condition1 += " and pe.student_batch_name = %(batch)s"
+ if course:
+ condition1 += " and pe.name = pec.parent and pec.course = %(course)s"
+ condition2 = ", `tabProgram Enrollment Course` pec"
return frappe.db.sql('''
select
pe.student, pe.student_name
from
- `tabProgram Enrollment` pe {condition1}
+ `tabProgram Enrollment` pe {condition2}
where
- pe.academic_year = %(academic_year)s {condition2}
+ pe.academic_year = %(academic_year)s {condition1}
order by
pe.student_name asc
'''.format(condition1=condition1, condition2=condition2),
- ({"academic_year": academic_year, "program": program, "batch": batch, "course": course}), as_dict=1)
+ ({"academic_year": academic_year, "academic_term":academic_term, "program": program, "batch": batch, "course": course}), as_dict=1)