diff --git a/community/patches.txt b/community/patches.txt index 853dd9d0..0ab8479a 100644 --- a/community/patches.txt +++ b/community/patches.txt @@ -11,3 +11,4 @@ execute:frappe.delete_doc("DocType", "LMS Message") community.patches.v0_0.course_instructor_update execute:frappe.delete_doc("DocType", "Discussion Message") execute:frappe.delete_doc("DocType", "Discussion Thread") +community.patches.v0_0.rename_chapters_and_lessons_doctype diff --git a/community/patches/v0_0/rename_chapters_and_lessons_doctype.py b/community/patches/v0_0/rename_chapters_and_lessons_doctype.py new file mode 100644 index 00000000..82d45556 --- /dev/null +++ b/community/patches/v0_0/rename_chapters_and_lessons_doctype.py @@ -0,0 +1,32 @@ +import frappe + +def execute(): + frappe.reload_doc("lms", "doctype", "lms_course") + frappe.reload_doc("lms", "doctype", "chapter") + frappe.reload_doc("lms", "doctype", "lesson") + frappe.reload_doc("lms", "doctype", "chapter_reference") + frappe.reload_doc("lms", "doctype", "lesson_reference") + + if not frappe.db.count("Chapter Reference"): + move_chapters() + + if not frappe.db.count("Lesson Reference"): + move_lessons() + +def move_chapters(): + docs = frappe.get_all("Chapters", fields=["*"]) + for doc in docs: + keys = doc + keys.update({"doctype": "Chapter Reference"}) + del keys["name"] + frappe.get_doc(keys).save() + +def move_lessons(): + docs = frappe.get_all("Lessons", fields=["*"]) + for doc in docs: + keys = doc + keys.update({"doctype": "Lesson Reference"}) + del keys["name"] + frappe.get_doc(keys).save() + +