Added ability to send newsletter to Student batch Guardians and Student Group Guardians
This commit is contained in:
parent
2f7697d1bd
commit
fa2023d3da
@ -8,6 +8,7 @@ import json
|
||||
from frappe import _
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from frappe.utils import flt, cstr
|
||||
from frappe.email.doctype.email_group.email_group import add_subscribers
|
||||
|
||||
@frappe.whitelist()
|
||||
def enroll_student(source_name):
|
||||
@ -82,6 +83,16 @@ def make_attendance_records(student, student_name, status, course_schedule=None,
|
||||
student_attendance.status = status
|
||||
student_attendance.submit()
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_student_guardians(student):
|
||||
"""Returns List of Guardians of a Student.
|
||||
|
||||
:param student: Student.
|
||||
"""
|
||||
guardians = frappe.get_list("Student Guardian", fields=["guardian"] ,
|
||||
filters={"parent": student})
|
||||
return guardians
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_student_batch_students(student_batch):
|
||||
"""Returns List of student, student_name, idx in Student Batch.
|
||||
@ -253,4 +264,23 @@ def mark_assessment_result(student, assessment_plan, scores):
|
||||
})
|
||||
assessment_result.save()
|
||||
assessment_result.submit()
|
||||
return assessment_result
|
||||
return assessment_result
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_email_group(doctype, name):
|
||||
if not frappe.db.exists("Email Group", name):
|
||||
email_group = frappe.new_doc("Email Group")
|
||||
email_group.title = name
|
||||
email_group.save()
|
||||
email_list = []
|
||||
students = []
|
||||
if doctype == "Student Batch":
|
||||
students = get_student_batch_students(name)
|
||||
if doctype == "Student Group":
|
||||
students = get_student_group_students(name)
|
||||
for stud in students:
|
||||
for guard in get_student_guardians(stud.student):
|
||||
email = frappe.db.get_value("Guardian", guard.guardian, "email_address")
|
||||
if email:
|
||||
email_list.append(email)
|
||||
add_subscribers(name, email_list)
|
@ -3,7 +3,23 @@
|
||||
|
||||
frappe.ui.form.on('Student Batch', {
|
||||
refresh: function(frm) {
|
||||
|
||||
if (!frm.doc.__islocal) {
|
||||
frm.add_custom_button(__("Update Email Group"), function() {
|
||||
frappe.call({
|
||||
method: "erpnext.schools.api.update_email_group",
|
||||
args: {
|
||||
"doctype": "Student Batch",
|
||||
"name": frm.doc.name
|
||||
}
|
||||
});
|
||||
});
|
||||
frm.add_custom_button(__("Newsletter"), function() {
|
||||
frappe.route_options = {
|
||||
email_group: frm.doc.name
|
||||
}
|
||||
frappe.set_route("List", "Newsletter");
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onload: function(frm){
|
||||
|
@ -6,6 +6,7 @@ from __future__ import unicode_literals
|
||||
from frappe.model.document import Document
|
||||
from erpnext.schools.utils import validate_duplicate_student
|
||||
import frappe
|
||||
from frappe import _
|
||||
|
||||
class StudentBatch(Document):
|
||||
def autoname(self):
|
||||
@ -16,3 +17,8 @@ class StudentBatch(Document):
|
||||
|
||||
def validate(self):
|
||||
validate_duplicate_student(self.students)
|
||||
self.validate_name()
|
||||
|
||||
def validate_name(self):
|
||||
if frappe.db.exists("Student Group", self.name):
|
||||
frappe.throw(_("""Student Group exists with same name"""))
|
||||
|
@ -1,33 +1,48 @@
|
||||
cur_frm.add_fetch("student", "title", "student_name");
|
||||
|
||||
frappe.ui.form.on("Student Group", {
|
||||
refresh: function(frm) {
|
||||
if (!frm.doc.__islocal) {
|
||||
frm.add_custom_button(__("Course Schedule"), function() {
|
||||
frappe.route_options = {
|
||||
student_group: frm.doc.name
|
||||
}
|
||||
frappe.set_route("List", "Course Schedule");
|
||||
});
|
||||
refresh: function(frm) {
|
||||
if (!frm.doc.__islocal) {
|
||||
frm.add_custom_button(__("Course Schedule"), function() {
|
||||
frappe.route_options = {
|
||||
student_group: frm.doc.name
|
||||
}
|
||||
frappe.set_route("List", "Course Schedule");
|
||||
});
|
||||
|
||||
frm.add_custom_button(__("Assessment Plan"), function() {
|
||||
frappe.route_options = {
|
||||
student_group: frm.doc.name
|
||||
}
|
||||
frappe.set_route("List", "Assessment Plan");
|
||||
});
|
||||
}
|
||||
},
|
||||
frm.add_custom_button(__("Assessment Plan"), function() {
|
||||
frappe.route_options = {
|
||||
student_group: frm.doc.name
|
||||
}
|
||||
frappe.set_route("List", "Assessment Plan");
|
||||
});
|
||||
frm.add_custom_button(__("Update Email Group"), function() {
|
||||
frappe.call({
|
||||
method: "erpnext.schools.api.update_email_group",
|
||||
args: {
|
||||
"doctype": "Student Group",
|
||||
"name": frm.doc.name
|
||||
}
|
||||
});
|
||||
});
|
||||
frm.add_custom_button(__("Newsletter"), function() {
|
||||
frappe.route_options = {
|
||||
email_group: frm.doc.name
|
||||
}
|
||||
frappe.set_route("List", "Newsletter");
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onload: function(frm) {
|
||||
cur_frm.set_query("academic_term", function() {
|
||||
return {
|
||||
"filters": {
|
||||
"academic_year": (frm.doc.academic_year)
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
onload: function(frm) {
|
||||
frm.set_query("academic_term", function() {
|
||||
return {
|
||||
"filters": {
|
||||
"academic_year": (frm.doc.academic_year)
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//If Student Batch is entered, deduce program, academic_year and academic term from it
|
||||
|
@ -30,6 +30,7 @@ class StudentGroup(Document):
|
||||
def validate(self):
|
||||
self.validate_strength()
|
||||
self.validate_student_name()
|
||||
self.validate_name()
|
||||
if self.student_batch:
|
||||
self.validate_student_batch()
|
||||
validate_duplicate_student(self.students)
|
||||
@ -42,6 +43,10 @@ class StudentGroup(Document):
|
||||
for d in self.students:
|
||||
d.student_name = frappe.db.get_value("Student", d.student, "title")
|
||||
|
||||
def validate_name(self):
|
||||
if frappe.db.exists("Student Batch", self.name):
|
||||
frappe.throw(_("""Student Batch exists with same name"""))
|
||||
|
||||
def validate_student_batch(self):
|
||||
student_batch_students = []
|
||||
for d in get_student_batch_students(self.student_batch):
|
||||
|
Loading…
Reference in New Issue
Block a user