diff --git a/erpnext/schools/doctype/student_group/student_group.py b/erpnext/schools/doctype/student_group/student_group.py index f60477392c..2f2795757e 100644 --- a/erpnext/schools/doctype/student_group/student_group.py +++ b/erpnext/schools/doctype/student_group/student_group.py @@ -7,6 +7,7 @@ import frappe from frappe.model.document import Document from frappe import _ from erpnext.schools.utils import validate_duplicate_student +from erpnext.schools.api import get_student_batch_students class StudentGroup(Document): def autoname(self): @@ -29,6 +30,8 @@ class StudentGroup(Document): def validate(self): self.validate_strength() self.validate_student_name() + if self.student_batch: + self.validate_student_batch() validate_duplicate_student(self.students) def validate_strength(self): @@ -39,4 +42,10 @@ class StudentGroup(Document): for d in self.students: d.student_name = frappe.db.get_value("Student", d.student, "title") - \ No newline at end of file + def validate_student_batch(self): + student_batch_students = [] + for d in get_student_batch_students(self.student_batch): + student_batch_students.append(d.student) + for d in self.students: + if d.student not in student_batch_students: + frappe.throw(_("""Student {0}: {1} does not belong to Student Batch {2}""".format(d.student, d.student_name, self.student_batch))) \ No newline at end of file