Check if doctype exists before renaming

This commit is contained in:
Nabin Hait 2017-05-23 21:51:32 +05:30
parent 258f7da778
commit 2f0c34385b

View File

@ -3,14 +3,17 @@ from frappe.model.utils.rename_field import rename_field
def execute(): def execute():
#Rename Grading Structure to Grading Scale #Rename Grading Structure to Grading Scale
frappe.rename_doc("DocType", "Grading Structure", "Grading Scale", force=True) if not frappe.db.exists("DocType", "Grading Scale"):
frappe.rename_doc("DocType", "Grade Interval", "Grading Scale Interval", force=True) frappe.rename_doc("DocType", "Grading Structure", "Grading Scale", force=True)
if not frappe.db.exists("DocType", "Grading Scale Interval"):
frappe.rename_doc("DocType", "Grade Interval", "Grading Scale Interval", force=True)
frappe.reload_doc("schools", "doctype", "grading_scale_interval") frappe.reload_doc("schools", "doctype", "grading_scale_interval")
if "to_score" in frappe.db.get_table_columns("Grading Scale Interval"): if "to_score" in frappe.db.get_table_columns("Grading Scale Interval"):
rename_field("Grading Scale Interval", "to_score", "threshold") rename_field("Grading Scale Interval", "to_score", "threshold")
frappe.rename_doc("DocType", "Assessment", "Assessment Plan", force=True) if not frappe.db.exists("DocType", "Assessment Plan"):
frappe.rename_doc("DocType", "Assessment", "Assessment Plan", force=True)
#Rename Assessment Results #Rename Assessment Results
frappe.reload_doc("schools", "doctype", "assessment_plan") frappe.reload_doc("schools", "doctype", "assessment_plan")
@ -22,9 +25,10 @@ def execute():
frappe.reload_doc("schools", "doctype", "assessment_criteria") frappe.reload_doc("schools", "doctype", "assessment_criteria")
for assessment in frappe.get_all("Assessment Plan", fields=["name", "grading_scale"], filters = [["docstatus", "!=", 2 ]]): for assessment in frappe.get_all("Assessment Plan",
print assessment fields=["name", "grading_scale"], filters = [["docstatus", "!=", 2 ]]):
for stud_result in frappe.db.sql("select * from `tabAssessment Result` where parent= %s", assessment.name, as_dict=True): for stud_result in frappe.db.sql("select * from `tabAssessment Result` where parent= %s",
assessment.name, as_dict=True):
if stud_result.result: if stud_result.result:
assessment_result = frappe.new_doc("Assessment Result") assessment_result = frappe.new_doc("Assessment Result")
assessment_result.student = stud_result.student assessment_result.student = stud_result.student