fix in the patch for merging the student batch and student group (#8961)

This commit is contained in:
Manas Solanki 2017-05-23 11:38:57 +05:30 committed by Nabin Hait
parent 2424aa73d7
commit 552f7ab678

View File

@ -11,6 +11,8 @@ def execute():
# for converting student batch into student group # for converting student batch into student group
frappe.reload_doctype("Student Group") frappe.reload_doctype("Student Group")
if frappe.db.table_exists("Student Batch"):
student_batches = frappe.db.sql('''select name as student_group_name, student_batch_name as batch, student_batches = frappe.db.sql('''select name as student_group_name, student_batch_name as batch,
program, academic_year, academic_term from `tabStudent Batch`''', as_dict=1) program, academic_year, academic_term from `tabStudent Batch`''', as_dict=1)
@ -24,12 +26,17 @@ def execute():
student_batch.update({"doctype":"Student Group", "group_based_on": "Batch"}) student_batch.update({"doctype":"Student Group", "group_based_on": "Batch"})
doc = frappe.get_doc(student_batch) doc = frappe.get_doc(student_batch)
student_list = frappe.db.sql('''select student, student_name, active from `tabStudent Batch Student`
where parent=%s''', (doc.name), as_dict=1) if frappe.db.sql("SHOW COLUMNS FROM `tabStudent Batch Student` LIKE 'active'"):
for i, student in enumerate(student_list): cond = ", active"
student.update({"group_roll_number": i+1}) else:
cond = " "
student_list = frappe.db.sql('''select student, student_name {cond} from `tabStudent Batch Student`
where parent=%s'''.format(cond=cond), (doc.name), as_dict=1)
if student_list: if student_list:
for i, student in enumerate(student_list):
student.update({"group_roll_number": i+1})
doc.extend("students", student_list) doc.extend("students", student_list)
instructor_list = frappe.db.sql('''select instructor, instructor_name from `tabStudent Batch Instructor` instructor_list = frappe.db.sql('''select instructor, instructor_name from `tabStudent Batch Instructor`
@ -39,14 +46,19 @@ def execute():
doc.save() doc.save()
# delete the student batch and child-table # delete the student batch and child-table
if frappe.db.table_exists("Student Batch"):
frappe.delete_doc("DocType", "Student Batch", force=1) frappe.delete_doc("DocType", "Student Batch", force=1)
if frappe.db.table_exists("Student Batch Student"):
frappe.delete_doc("DocType", "Student Batch Student", force=1) frappe.delete_doc("DocType", "Student Batch Student", force=1)
if frappe.db.table_exists("Student Batch Instructor"):
frappe.delete_doc("DocType", "Student Batch Instructor", force=1) frappe.delete_doc("DocType", "Student Batch Instructor", force=1)
# delete the student batch creation tool # delete the student batch creation tool
if frappe.db.table_exists("Student Batch Creation Tool"):
frappe.delete_doc("DocType", "Student Batch Creation Tool", force=1) frappe.delete_doc("DocType", "Student Batch Creation Tool", force=1)
# delete the student batch creation tool # delete the student batch creation tool
if frappe.db.table_exists("Attendance Tool Student"):
frappe.delete_doc("DocType", "Attendance Tool Student", force=1) frappe.delete_doc("DocType", "Attendance Tool Student", force=1)
# change the student batch to student group in the student attendance # change the student batch to student group in the student attendance