diff --git a/erpnext/education/doctype/student_attendance/student_attendance.py b/erpnext/education/doctype/student_attendance/student_attendance.py index c1b6850c56..55c6de6f1e 100644 --- a/erpnext/education/doctype/student_attendance/student_attendance.py +++ b/erpnext/education/doctype/student_attendance/student_attendance.py @@ -6,13 +6,13 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe import _ -from frappe.utils import get_link_to_form +from frappe.utils import get_link_to_form, getdate from erpnext.education.api import get_student_group_students - class StudentAttendance(Document): def validate(self): self.validate_mandatory() + self.validate_date() self.set_date() self.set_student_group() self.validate_student() @@ -27,6 +27,10 @@ class StudentAttendance(Document): frappe.throw(_('{0} or {1} is mandatory').format(frappe.bold('Student Group'), frappe.bold('Course Schedule')), title=_('Mandatory Fields')) + def validate_date(self): + if getdate(self.date) > getdate(): + frappe.throw(_('Attendance cannot be marked for future dates.')) + def set_student_group(self): if self.course_schedule: self.student_group = frappe.db.get_value('Course Schedule', self.course_schedule, 'student_group') diff --git a/erpnext/education/doctype/student_attendance_tool/student_attendance_tool.js b/erpnext/education/doctype/student_attendance_tool/student_attendance_tool.js index 0384505ec2..973082ffc0 100644 --- a/erpnext/education/doctype/student_attendance_tool/student_attendance_tool.js +++ b/erpnext/education/doctype/student_attendance_tool/student_attendance_tool.js @@ -52,6 +52,8 @@ frappe.ui.form.on('Student Attendance Tool', { }, date: function(frm) { + if (frm.doc.date > frappe.datetime.get_today()) + frappe.throw(__("Cannot mark attendance for future dates.")); frm.trigger("student_group"); },