feat: Student Group with Student Category filter

The Student Category field is added to the Student Group doctype.The
students are fetched from Program Enrollment with added Student Category.
This helps in creating student group based on Program,Batch and Student
Category.Which helps in creating fee schedule with fee structures
defined based on student category.

Signed-off-by: Syed Mujeer Hashmi <mujeerhashmi@4csolutions.in>
This commit is contained in:
Syed Mujeer Hashmi 2019-04-26 11:37:41 +05:30 committed by Syed Mujeer Hashmi
parent fa626bd3ab
commit b146df6460
3 changed files with 148 additions and 535 deletions

View File

@ -19,6 +19,7 @@ frappe.ui.form.on("Student Group", {
'academic_term': frm.doc.academic_term, 'academic_term': frm.doc.academic_term,
'program': frm.doc.program, 'program': frm.doc.program,
'batch': frm.doc.batch, 'batch': frm.doc.batch,
'student_category': frm.doc.student_category,
'course': frm.doc.course, 'course': frm.doc.course,
'student_group': frm.doc.name 'student_group': frm.doc.name
} }
@ -92,6 +93,7 @@ frappe.ui.form.on("Student Group", {
"group_based_on": frm.doc.group_based_on, "group_based_on": frm.doc.group_based_on,
"program": frm.doc.program, "program": frm.doc.program,
"batch" : frm.doc.batch, "batch" : frm.doc.batch,
"student_category" : frm.doc.student_category,
"course": frm.doc.course "course": frm.doc.course
}, },
callback: function(r) { callback: function(r) {

View File

@ -1,552 +1,161 @@
{ {
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 1, "allow_import": 1,
"allow_rename": 1, "allow_rename": 1,
"autoname": "field:student_group_name", "autoname": "field:student_group_name",
"beta": 0,
"creation": "2015-09-07 12:55:52.072792", "creation": "2015-09-07 12:55:52.072792",
"custom": 0,
"docstatus": 0,
"doctype": "DocType", "doctype": "DocType",
"document_type": "Document", "document_type": "Document",
"editable_grid": 0,
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [
"academic_year",
"group_based_on",
"student_group_name",
"max_strength",
"column_break_3",
"academic_term",
"program",
"batch",
"student_category",
"course",
"disabled",
"section_break_6",
"get_students",
"students",
"section_break_12",
"instructors"
],
"fields": [ "fields": [
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "academic_year", "fieldname": "academic_year",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Academic Year", "label": "Academic Year",
"length": 0,
"no_copy": 0,
"options": "Academic Year", "options": "Academic Year",
"permlevel": 0, "set_only_once": 1
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 1,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "group_based_on", "fieldname": "group_based_on",
"fieldtype": "Select", "fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 0,
"label": "Group Based on", "label": "Group Based on",
"length": 0,
"no_copy": 0,
"options": "\nBatch\nCourse\nActivity", "options": "\nBatch\nCourse\nActivity",
"permlevel": 0, "reqd": 1
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"fieldname": "student_group_name", "fieldname": "student_group_name",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Student Group Name", "label": "Student Group Name",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1, "reqd": 1,
"search_index": 0, "unique": 1
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"description": "Set 0 for no limit", "description": "Set 0 for no limit",
"fieldname": "max_strength", "fieldname": "max_strength",
"fieldtype": "Int", "fieldtype": "Int",
"hidden": 0, "label": "Max Strength"
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Max Strength",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_3", "fieldname": "column_break_3",
"fieldtype": "Column Break", "fieldtype": "Column Break"
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "academic_term", "fieldname": "academic_term",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Academic Term", "label": "Academic Term",
"length": 0, "options": "Academic Term"
"no_copy": 0,
"options": "Academic Term",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"fieldname": "program", "fieldname": "program",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 1, "in_global_search": 1,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Program", "label": "Program",
"length": 0, "options": "Program"
"no_copy": 0,
"options": "Program",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"fieldname": "batch", "fieldname": "batch",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 1, "in_global_search": 1,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Batch", "label": "Batch",
"length": 0, "options": "Student Batch Name"
"no_copy": 0,
"options": "Student Batch Name",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "eval:doc.group_based_on == 'Course'", "depends_on": "eval:doc.group_based_on == 'Course'",
"fieldname": "course", "fieldname": "course",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 1, "in_global_search": 1,
"in_list_view": 0,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Course", "label": "Course",
"length": 0, "options": "Course"
"no_copy": 0,
"options": "Course",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "0", "default": "0",
"fieldname": "disabled", "fieldname": "disabled",
"fieldtype": "Check", "fieldtype": "Check",
"hidden": 0, "label": "Disabled"
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Disabled",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": "",
"columns": 0,
"depends_on": "eval:!doc.__islocal", "depends_on": "eval:!doc.__islocal",
"fieldname": "section_break_6", "fieldname": "section_break_6",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "label": "Students"
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Students",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "get_students", "fieldname": "get_students",
"fieldtype": "Button", "fieldtype": "Button",
"hidden": 0, "label": "Get Students"
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Get Students",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 1, "allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "students", "fieldname": "students",
"fieldtype": "Table", "fieldtype": "Table",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Students", "label": "Students",
"length": 0, "options": "Student Group Student"
"no_copy": 0,
"options": "Student Group Student",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "section_break_12", "fieldname": "section_break_12",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "label": "Instructors"
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Instructors",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "instructors", "fieldname": "instructors",
"fieldtype": "Table", "fieldtype": "Table",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Instructors", "label": "Instructors",
"length": 0, "options": "Student Group Instructor"
"no_copy": 0, },
"options": "Student Group Instructor", {
"permlevel": 0, "fieldname": "student_category",
"precision": "", "fieldtype": "Link",
"print_hide": 0, "label": "Student Category",
"print_hide_if_no_value": 0, "options": "Student Category"
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
} }
], ],
"has_web_view": 0, "modified": "2019-04-26 10:52:57.303951",
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2018-07-26 04:17:10.836912",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Education", "module": "Education",
"name": "Student Group", "name": "Student Group",
"name_case": "",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 0,
"delete": 0,
"email": 0,
"export": 0,
"if_owner": 0,
"import": 0,
"permlevel": 0,
"print": 0,
"read": 1, "read": 1,
"report": 0, "role": "Instructor"
"role": "Instructor",
"set_user_permissions": 0,
"share": 0,
"submit": 0,
"write": 0
}, },
{ {
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 1, "create": 1,
"delete": 1, "delete": 1,
"email": 1, "email": 1,
"export": 1, "export": 1,
"if_owner": 0,
"import": 0,
"permlevel": 0,
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "Academics User", "role": "Academics User",
"set_user_permissions": 0,
"share": 1, "share": 1,
"submit": 0,
"write": 1 "write": 1
} }
], ],
"quick_entry": 0,
"read_only": 0,
"read_only_onload": 0,
"restrict_to_domain": "Education", "restrict_to_domain": "Education",
"search_fields": "program, batch, course", "search_fields": "program, batch, course",
"show_name_in_global_search": 0,
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC"
"title_field": "",
"track_changes": 0,
"track_seen": 0
} }

View File

@ -30,7 +30,7 @@ class StudentGroup(Document):
frappe.throw(_("""Cannot enroll more than {0} students for this student group.""").format(self.max_strength)) frappe.throw(_("""Cannot enroll more than {0} students for this student group.""").format(self.max_strength))
def validate_students(self): def validate_students(self):
program_enrollment = get_program_enrollment(self.academic_year, self.academic_term, self.program, self.batch, self.course) program_enrollment = get_program_enrollment(self.academic_year, self.academic_term, self.program, self.batch, self.student_category, self.course)
students = [d.student for d in program_enrollment] if program_enrollment else [] students = [d.student for d in program_enrollment] if program_enrollment else []
for d in self.students: for d in self.students:
if not frappe.db.get_value("Student", d.student, "enabled") and d.active and not self.disabled: if not frappe.db.get_value("Student", d.student, "enabled") and d.active and not self.disabled:
@ -60,8 +60,8 @@ class StudentGroup(Document):
roll_no_list.append(d.group_roll_number) roll_no_list.append(d.group_roll_number)
@frappe.whitelist() @frappe.whitelist()
def get_students(academic_year, group_based_on, academic_term=None, program=None, batch=None, course=None): def get_students(academic_year, group_based_on, academic_term=None, program=None, batch=None, student_category=None, course=None):
enrolled_students = get_program_enrollment(academic_year, academic_term, program, batch, course) enrolled_students = get_program_enrollment(academic_year, academic_term, program, batch, student_category, course)
if enrolled_students: if enrolled_students:
student_list = [] student_list = []
@ -76,7 +76,7 @@ def get_students(academic_year, group_based_on, academic_term=None, program=None
frappe.msgprint(_("No students found")) frappe.msgprint(_("No students found"))
return [] return []
def get_program_enrollment(academic_year, academic_term=None, program=None, batch=None, course=None): def get_program_enrollment(academic_year, academic_term=None, program=None, batch=None, student_category=None, course=None):
condition1 = " " condition1 = " "
condition2 = " " condition2 = " "
@ -86,6 +86,8 @@ def get_program_enrollment(academic_year, academic_term=None, program=None, batc
condition1 += " and pe.program = %(program)s" condition1 += " and pe.program = %(program)s"
if batch: if batch:
condition1 += " and pe.student_batch_name = %(batch)s" condition1 += " and pe.student_batch_name = %(batch)s"
if student_category:
condition1 += " and pe.student_category = %(student_category)s"
if course: if course:
condition1 += " and pe.name = pec.parent and pec.course = %(course)s" condition1 += " and pe.name = pec.parent and pec.course = %(course)s"
condition2 = ", `tabProgram Enrollment Course` pec" condition2 = ", `tabProgram Enrollment Course` pec"
@ -100,14 +102,14 @@ def get_program_enrollment(academic_year, academic_term=None, program=None, batc
order by order by
pe.student_name asc pe.student_name asc
'''.format(condition1=condition1, condition2=condition2), '''.format(condition1=condition1, condition2=condition2),
({"academic_year": academic_year, "academic_term":academic_term, "program": program, "batch": batch, "course": course}), as_dict=1) ({"academic_year": academic_year, "academic_term":academic_term, "program": program, "batch": batch, "student_category": student_category, "course": course}), as_dict=1)
@frappe.whitelist() @frappe.whitelist()
def fetch_students(doctype, txt, searchfield, start, page_len, filters): def fetch_students(doctype, txt, searchfield, start, page_len, filters):
if filters.get("group_based_on") != "Activity": if filters.get("group_based_on") != "Activity":
enrolled_students = get_program_enrollment(filters.get('academic_year'), filters.get('academic_term'), enrolled_students = get_program_enrollment(filters.get('academic_year'), filters.get('academic_term'),
filters.get('program'), filters.get('batch')) filters.get('program'), filters.get('batch'), filters.get('student_category'))
student_group_student = frappe.db.sql_list('''select student from `tabStudent Group Student` where parent=%s''', student_group_student = frappe.db.sql_list('''select student from `tabStudent Group Student` where parent=%s''',
(filters.get('student_group'))) (filters.get('student_group')))
students = ([d.student for d in enrolled_students if d.student not in student_group_student] students = ([d.student for d in enrolled_students if d.student not in student_group_student]