diff --git a/lms/lms/doctype/lms_batch/lms_batch.py b/lms/lms/doctype/lms_batch/lms_batch.py index 68ac25a7..828ef2f9 100644 --- a/lms/lms/doctype/lms_batch/lms_batch.py +++ b/lms/lms/doctype/lms_batch/lms_batch.py @@ -381,14 +381,3 @@ def get_timetable_details(timetable): timetable = sorted(timetable, key=lambda k: k["date"]) return timetable - - -@frappe.whitelist() -def send_email_to_students(batch, subject, message): - frappe.only_for("Moderator") - students = frappe.get_all("Batch Student", {"parent": batch}, pluck="student") - frappe.sendmail( - recipients=students, - subject=subject, - message=message, - ) diff --git a/lms/www/batches/batch.js b/lms/www/batches/batch.js index 1f4cd60d..f2f43f11 100644 --- a/lms/www/batches/batch.js +++ b/lms/www/batches/batch.js @@ -798,11 +798,33 @@ const email_to_students = () => { const send_email = (values) => { frappe.call({ - method: "lms.lms.doctype.lms_batch.lms_batch.send_email_to_students", + method: "frappe.client.get_list", args: { - batch: $(".class-details").data("batch"), + doctype: "Batch Student", + parent: "LMS Batch", + fields: ["student"], + filters: { + parent: $(".class-details").data("batch"), + }, + }, + callback: (data) => { + send_email_to_students(data.message, values); + }, + }); +}; + +const send_email_to_students = (students, values) => { + students = students.map((row) => row.student); + frappe.call({ + method: "frappe.core.doctype.communication.email.make", + args: { + recipients: students.join(", "), + cc: values.reply_to, subject: values.subject, - message: values.message, + content: values.message, + doctype: "LMS Batch", + name: $(".class-details").data("batch"), + send_email: 1, }, callback: (r) => { this.email_dialog.hide();