[minor] create student batch if does not exists (#8781)

* [minor] create student batch if does not exists

* [fix] minor fixes in if condition
diff --git a/erpnext/patches/v8_0/merge_student_batch_and_student_group.py b/erpnext/patches/v8_0/merge_student_batch_and_student_group.py
index 5b45cc7..742457f 100644
--- a/erpnext/patches/v8_0/merge_student_batch_and_student_group.py
+++ b/erpnext/patches/v8_0/merge_student_batch_and_student_group.py
@@ -13,7 +13,15 @@
 	frappe.reload_doctype("Student Group")
 	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)
+
 	for student_batch in student_batches:
+		# create student batch name if does not exists !!
+		if student_batch.get("batch") and not frappe.db.exists("Student Batch Name", student_batch.get("batch")):
+			frappe.get_doc({
+				"doctype": "Student Batch Name",
+				"batch_name": student_batch.get("batch")
+			}).insert(ignore_permissions=True)
+
 		student_batch.update({"doctype":"Student Group", "group_based_on": "Batch"})
 		doc = frappe.get_doc(student_batch)
 		student_list = frappe.db.sql('''select student, student_name, active from `tabStudent Batch Student`