set student roll no in backend if not given (#9039)

This commit is contained in:
Manas Solanki 2017-05-30 15:33:50 +05:30 committed by Nabin Hait
parent 465d8352aa
commit 5f7b88d9c3
2 changed files with 27 additions and 5 deletions

View File

@ -14,7 +14,7 @@ class StudentGroup(Document):
self.validate_strength()
if frappe.defaults.get_defaults().student_validation_setting:
self.validate_students()
self.validate_roll_no()
self.validate_and_set_child_table_fields()
validate_duplicate_student(self.students)
def validate_mandatory_fields(self):
@ -38,9 +38,16 @@ class StudentGroup(Document):
if not frappe.db.get_value("Student", d.student, "enabled") and d.active:
frappe.throw(_("{0} - {1} is inactive student".format(d.group_roll_number, d.student_name)))
def validate_roll_no(self):
def validate_and_set_child_table_fields(self):
roll_numbers = [d.group_roll_number for d in self.students if d.group_roll_number]
max_roll_no = max(roll_numbers) if roll_numbers else 0
roll_no_list = []
for d in self.students:
if not d.student_name:
d.student_name = frappe.db.get_value("Student", d.student, "title")
if not d.group_roll_number:
max_roll_no += 1
d.group_roll_number = max_roll_no
if d.group_roll_number in roll_no_list:
frappe.throw(_("Duplicate roll number for student {0}".format(d.student_name)))
else:

View File

@ -5,8 +5,23 @@ from __future__ import unicode_literals
import frappe
import unittest
# test_records = frappe.get_test_records('Student Group')
from frappe.utils.make_random import get_random
class TestStudentGroup(unittest.TestCase):
pass
def test_student_roll_no(self):
doc = frappe.get_doc({
"doctype": "Student Group",
"student_group_name": "_Test Student Group R",
"group_based_on": "Activity"
}).insert()
student_list = []
while len(student_list) < 3:
s = get_random("Student")
if s not in student_list:
student_list.append(s)
doc.extend("students", [{"student":d} for d in student_list])
doc.save()
self.assertEquals(max([d.group_roll_number for d in doc.students]), 3)