From ee9aea4febee1dfa0113809053df526395ea02fe Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Tue, 24 Dec 2019 13:37:10 +0530 Subject: [PATCH] fix: date validation on student form, instructor duplicacy fix on student grp, instructor with same employee id fix --- erpnext/education/doctype/instructor/instructor.py | 9 +++++++++ erpnext/education/doctype/student/student.py | 3 +++ .../education/doctype/student_group/student_group.js | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/erpnext/education/doctype/instructor/instructor.py b/erpnext/education/doctype/instructor/instructor.py index 0756b5f01a..058d476f5b 100644 --- a/erpnext/education/doctype/instructor/instructor.py +++ b/erpnext/education/doctype/instructor/instructor.py @@ -22,3 +22,12 @@ class Instructor(Document): self.name = self.employee elif naming_method == 'Full Name': self.name = self.instructor_name + + def validate(self): + self.validate_duplicate_employee() + + def validate_duplicate_employee(self): + if self.employee and frappe.db.get_value("Instructor", {'employee': self.employee}, 'name'): + frappe.throw(_("Employee ID is linked with another instructor")) + + diff --git a/erpnext/education/doctype/student/student.py b/erpnext/education/doctype/student/student.py index 8e4b4e16f9..99c4c0e908 100644 --- a/erpnext/education/doctype/student/student.py +++ b/erpnext/education/doctype/student/student.py @@ -25,6 +25,9 @@ class Student(Document): if self.date_of_birth and getdate(self.date_of_birth) >= getdate(today()): frappe.throw(_("Date of Birth cannot be greater than today.")) + if self.joining_date and self.date_of_leaving and getdate(self.joining_date) > getdate(self.date_of_leaving): + frappe.throw(_("Joining Date can not be greater than Leaving Date")) + def update_student_name_in_linked_doctype(self): linked_doctypes = get_linked_doctypes("Student") for d in linked_doctypes: diff --git a/erpnext/education/doctype/student_group/student_group.js b/erpnext/education/doctype/student_group/student_group.js index c29c134843..372e190af9 100644 --- a/erpnext/education/doctype/student_group/student_group.js +++ b/erpnext/education/doctype/student_group/student_group.js @@ -122,3 +122,15 @@ frappe.ui.form.on("Student Group", { } } }); + +frappe.ui.form.on('Student Group Instructor', { + instructors_add: function(frm){ + frm.fields_dict['instructors'].grid.get_field('instructor').get_query = function(doc){ + let instructor_list = []; + $.each(doc.instructors, function(idx, val){ + instructor_list.push(val.instructor); + }); + return { filters: [['Instructor', 'name', 'not in', instructor_list]] }; + }; + } +}); \ No newline at end of file