From 3959c7c3c1d2682371f698b8237ecb45e3eca22f Mon Sep 17 00:00:00 2001 From: Manas Solanki Date: Mon, 26 Jun 2017 17:29:09 +0530 Subject: [PATCH] filter out students which are already enrolled in program enrollment --- .../program_enrollment/program_enrollment.js | 10 ++++++++++ .../program_enrollment/program_enrollment.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/erpnext/schools/doctype/program_enrollment/program_enrollment.js b/erpnext/schools/doctype/program_enrollment/program_enrollment.js index dcdaabc83d..d1b703b8ca 100644 --- a/erpnext/schools/doctype/program_enrollment/program_enrollment.js +++ b/erpnext/schools/doctype/program_enrollment/program_enrollment.js @@ -30,6 +30,16 @@ frappe.ui.form.on("Program Enrollment", { } }); } + + frm.set_query("student", function() { + return{ + query: "erpnext.schools.doctype.program_enrollment.program_enrollment.get_students", + filters: { + 'academic_year': frm.doc.academic_year, + 'academic_term': frm.doc.academic_term + } + } + }); }, program: function(frm) { diff --git a/erpnext/schools/doctype/program_enrollment/program_enrollment.py b/erpnext/schools/doctype/program_enrollment/program_enrollment.py index feb4c2f60e..1346ef651e 100644 --- a/erpnext/schools/doctype/program_enrollment/program_enrollment.py +++ b/erpnext/schools/doctype/program_enrollment/program_enrollment.py @@ -77,3 +77,21 @@ def get_program_courses(doctype, txt, searchfield, start, page_len, filters): "_txt": txt.replace('%', ''), "program": filters['program'] }) + + +@frappe.whitelist() +def get_students(doctype, txt, searchfield, start, page_len, filters): + if not filters.get("academic_term"): + filters["academic_term"] = frappe.defaults.get_defaults().academic_term + if not filters.get("academic_year"): + filters["academic_year"] = frappe.defaults.get_defaults().academic_year + enrolled_students = frappe.get_list("Program Enrollment", fields=["student"], filters= + {"academic_term": filters.get('academic_term'), "academic_year": filters.get('academic_year')}) + students = [d.student for d in enrolled_students] if enrolled_students else [""] + return frappe.db.sql("""select name, title from tabStudent + where name not in (%s) + and `%s` LIKE %s + order by idx desc, name + limit %s, %s""" % + (", ".join(['%s']*len(students)), searchfield, "%s", "%s", "%s"), + tuple(students + ["%%%s%%" % txt, start, page_len]))