From ddffc8372b879bbee19da2e4c5f79ea38088944a Mon Sep 17 00:00:00 2001 From: pateljannat Date: Wed, 29 Sep 2021 17:55:08 +0530 Subject: [PATCH] fix: condition to check course and chapter --- community/patches.txt | 2 +- .../v0_0/rename_chapter_and_lesson_doctype.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/community/patches.txt b/community/patches.txt index 9d729b93..e386940b 100644 --- a/community/patches.txt +++ b/community/patches.txt @@ -12,4 +12,4 @@ 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 -community.patches.v0_0.rename_chapter_and_lesson_doctype #25-09-2021 +community.patches.v0_0.rename_chapter_and_lesson_doctype #26-09-2021 diff --git a/community/patches/v0_0/rename_chapter_and_lesson_doctype.py b/community/patches/v0_0/rename_chapter_and_lesson_doctype.py index b0b544a6..b6863b6f 100644 --- a/community/patches/v0_0/rename_chapter_and_lesson_doctype.py +++ b/community/patches/v0_0/rename_chapter_and_lesson_doctype.py @@ -16,15 +16,17 @@ def execute(): def move_chapters(): docs = frappe.get_all("Chapter", fields=["*"]) for doc in docs: - keys = doc - keys.update({"doctype": "Course Chapter"}) - del keys["name"] - frappe.get_doc(keys).save() + if frappe.db.exists("LMS Course", doc.course): + keys = doc + keys.update({"doctype": "Course Chapter"}) + del keys["name"] + frappe.get_doc(keys).save() def move_lessons(): docs = frappe.get_all("Lesson", fields=["*"]) for doc in docs: - keys = doc - keys.update({"doctype": "Course Lesson"}) - del keys["name"] - frappe.get_doc(keys).save() + if frappe.db.exists("Chapter", doc.chapter): + keys = doc + keys.update({"doctype": "Course Lesson"}) + del keys["name"] + frappe.get_doc(keys).save()