fix: batch confirmation email trigger
This commit is contained in:
@@ -13,6 +13,8 @@ from frappe.utils import (
|
|||||||
format_date,
|
format_date,
|
||||||
format_datetime,
|
format_datetime,
|
||||||
get_time,
|
get_time,
|
||||||
|
getdate,
|
||||||
|
add_days
|
||||||
)
|
)
|
||||||
from lms.lms.utils import (
|
from lms.lms.utils import (
|
||||||
get_lessons,
|
get_lessons,
|
||||||
@@ -73,21 +75,21 @@ class LMSBatch(Document):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def validate_evaluation_end_date(self):
|
||||||
|
if self.evaluation_end_date and self.evaluation_end_date < self.end_date:
|
||||||
|
frappe.throw(_("Evaluation end date cannot be less than the batch end date."))
|
||||||
|
|
||||||
def send_confirmation_mail(self):
|
def send_confirmation_mail(self):
|
||||||
for student in self.students:
|
for student in self.students:
|
||||||
outgoing_email_account = frappe.get_cached_value(
|
outgoing_email_account = frappe.get_cached_value(
|
||||||
"Email Account", {"default_outgoing": 1, "enable_outgoing": 1}, "name"
|
"Email Account", {"default_outgoing": 1, "enable_outgoing": 1}, "name"
|
||||||
)
|
)
|
||||||
if not student.confirmation_email_sent and (
|
if not student.confirmation_email_sent and getdate(student.creation) >= add_days(getdate(), -2) and (
|
||||||
outgoing_email_account or frappe.conf.get("mail_login")
|
outgoing_email_account or frappe.conf.get("mail_login")
|
||||||
):
|
):
|
||||||
self.send_mail(student)
|
self.send_mail(student)
|
||||||
student.confirmation_email_sent = 1
|
student.confirmation_email_sent = 1
|
||||||
|
|
||||||
def validate_evaluation_end_date(self):
|
|
||||||
if self.evaluation_end_date and self.evaluation_end_date < self.end_date:
|
|
||||||
frappe.throw(_("Evaluation end date cannot be less than the batch end date."))
|
|
||||||
|
|
||||||
def send_mail(self, student):
|
def send_mail(self, student):
|
||||||
subject = _("Enrollment Confirmation for the Next Training Batch")
|
subject = _("Enrollment Confirmation for the Next Training Batch")
|
||||||
template = "batch_confirmation"
|
template = "batch_confirmation"
|
||||||
|
|||||||
Reference in New Issue
Block a user