course_activity: create doctype for tracking student course activity

Co-authored-by: Chinmay Pai <chinmaydpai@gmail.com>
diff --git a/erpnext/education/doctype/student_course_activity/student_course_activity.json b/erpnext/education/doctype/student_course_activity/student_course_activity.json
index 96041c8..1d8f98d 100644
--- a/erpnext/education/doctype/student_course_activity/student_course_activity.json
+++ b/erpnext/education/doctype/student_course_activity/student_course_activity.json
@@ -3,6 +3,7 @@
  "allow_guest_to_view": 0, 
  "allow_import": 0, 
  "allow_rename": 0, 
+ "autoname": "format:{student_name}-{program_name}", 
  "beta": 0, 
  "creation": "2018-10-01 17:35:54.391413", 
  "custom": 0, 
@@ -19,8 +20,8 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "data_1", 
-   "fieldtype": "Data", 
+   "fieldname": "student_name", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -28,8 +29,76 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
+   "label": "Student Name", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "Student", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "translatable": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "program_name", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Program Name", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Program", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "translatable": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "lms_activity", 
+   "fieldtype": "Table", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "LMS Activity", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "LMS Activity", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -54,7 +123,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2018-10-01 17:35:54.391413", 
+ "modified": "2018-10-08 12:10:28.602848", 
  "modified_by": "Administrator", 
  "module": "Education", 
  "name": "Student Course Activity", 
diff --git a/erpnext/education/doctype/student_course_activity/student_course_activity.py b/erpnext/education/doctype/student_course_activity/student_course_activity.py
index 92d2682..bf5778f 100644
--- a/erpnext/education/doctype/student_course_activity/student_course_activity.py
+++ b/erpnext/education/doctype/student_course_activity/student_course_activity.py
@@ -7,4 +7,19 @@
 from frappe.model.document import Document
 
 class StudentCourseActivity(Document):
-	pass
+	def validate(self):
+		self.check_if_enrolled()
+		# self.check_if_course_present()
+
+	def check_if_enrolled(self):
+		programs_list = frappe.get_list("Program Enrollment", filters={'student': self.student_name}, fields=['program'])
+		programs_enrolled_by_student = [item.program for item in programs_list]
+		if self.program_name not in programs_enrolled_by_student:
+			frappe.throw("Student <b>{0}</b> is not enrolled in <b>program {1}</b> ".format(self.student_name, self.program_name))
+
+	# def check_if_course_present(self):
+	# 	""" Get set of unique courses from lms_activity child table and make a list of it as assign it to course_list"""
+	# 	course_list = list(set([activity.course_name for activity in self.lms_activity]))
+	# 	current_program = frappe.get_doc('Program', self.program_name)
+	# 	courses_in_current_program = [course.course_name for course in current_program.courses]
+	# 	if len(set(courses_in_current_program) - set(course_list)) == 0:
\ No newline at end of file