@@ -11,43 +11,55 @@ def execute():
11
11
12
12
# for converting student batch into student group
13
13
frappe .reload_doctype ("Student Group" )
14
- student_batches = frappe .db .sql ('''select name as student_group_name, student_batch_name as batch,
15
- program, academic_year, academic_term from `tabStudent Batch`''' , as_dict = 1 )
16
-
17
- for student_batch in student_batches :
18
- # create student batch name if does not exists !!
19
- if student_batch .get ("batch" ) and not frappe .db .exists ("Student Batch Name" , student_batch .get ("batch" )):
20
- frappe .get_doc ({
21
- "doctype" : "Student Batch Name" ,
22
- "batch_name" : student_batch .get ("batch" )
23
- }).insert (ignore_permissions = True )
24
-
25
- student_batch .update ({"doctype" :"Student Group" , "group_based_on" : "Batch" })
26
- doc = frappe .get_doc (student_batch )
27
- student_list = frappe .db .sql ('''select student, student_name, active from `tabStudent Batch Student`
28
- where parent=%s''' , (doc .name ), as_dict = 1 )
29
- for i , student in enumerate (student_list ):
30
- student .update ({"group_roll_number" : i + 1 })
31
-
32
- if student_list :
33
- doc .extend ("students" , student_list )
34
-
35
- instructor_list = frappe .db .sql ('''select instructor, instructor_name from `tabStudent Batch Instructor`
36
- where parent=%s''' , (doc .name ), as_dict = 1 )
37
- if instructor_list :
38
- doc .extend ("instructors" , instructor_list )
39
- doc .save ()
14
+
15
+ if frappe .db .table_exists ("Student Batch" ):
16
+ student_batches = frappe .db .sql ('''select name as student_group_name, student_batch_name as batch,
17
+ program, academic_year, academic_term from `tabStudent Batch`''' , as_dict = 1 )
18
+
19
+ for student_batch in student_batches :
20
+ # create student batch name if does not exists !!
21
+ if student_batch .get ("batch" ) and not frappe .db .exists ("Student Batch Name" , student_batch .get ("batch" )):
22
+ frappe .get_doc ({
23
+ "doctype" : "Student Batch Name" ,
24
+ "batch_name" : student_batch .get ("batch" )
25
+ }).insert (ignore_permissions = True )
26
+
27
+ student_batch .update ({"doctype" :"Student Group" , "group_based_on" : "Batch" })
28
+ doc = frappe .get_doc (student_batch )
29
+
30
+ if frappe .db .sql ("SHOW COLUMNS FROM `tabStudent Batch Student` LIKE 'active'" ):
31
+ cond = ", active"
32
+ else :
33
+ cond = " "
34
+ student_list = frappe .db .sql ('''select student, student_name {cond} from `tabStudent Batch Student`
35
+ where parent=%s''' .format (cond = cond ), (doc .name ), as_dict = 1 )
36
+
37
+ if student_list :
38
+ for i , student in enumerate (student_list ):
39
+ student .update ({"group_roll_number" : i + 1 })
40
+ doc .extend ("students" , student_list )
41
+
42
+ instructor_list = frappe .db .sql ('''select instructor, instructor_name from `tabStudent Batch Instructor`
43
+ where parent=%s''' , (doc .name ), as_dict = 1 )
44
+ if instructor_list :
45
+ doc .extend ("instructors" , instructor_list )
46
+ doc .save ()
40
47
41
48
# delete the student batch and child-table
42
- frappe .delete_doc ("DocType" , "Student Batch" , force = 1 )
43
- frappe .delete_doc ("DocType" , "Student Batch Student" , force = 1 )
44
- frappe .delete_doc ("DocType" , "Student Batch Instructor" , force = 1 )
49
+ if frappe .db .table_exists ("Student Batch" ):
50
+ frappe .delete_doc ("DocType" , "Student Batch" , force = 1 )
51
+ if frappe .db .table_exists ("Student Batch Student" ):
52
+ frappe .delete_doc ("DocType" , "Student Batch Student" , force = 1 )
53
+ if frappe .db .table_exists ("Student Batch Instructor" ):
54
+ frappe .delete_doc ("DocType" , "Student Batch Instructor" , force = 1 )
45
55
46
56
# delete the student batch creation tool
47
- frappe .delete_doc ("DocType" , "Student Batch Creation Tool" , force = 1 )
57
+ if frappe .db .table_exists ("Student Batch Creation Tool" ):
58
+ frappe .delete_doc ("DocType" , "Student Batch Creation Tool" , force = 1 )
48
59
49
60
# delete the student batch creation tool
50
- frappe .delete_doc ("DocType" , "Attendance Tool Student" , force = 1 )
61
+ if frappe .db .table_exists ("Attendance Tool Student" ):
62
+ frappe .delete_doc ("DocType" , "Attendance Tool Student" , force = 1 )
51
63
52
64
# change the student batch to student group in the student attendance
53
65
frappe .reload_doctype ("Student Attendance" )
0 commit comments