Skip to content

Commit

Permalink
fix(patch): Reload linked doctypes before renaming dt
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Jun 4, 2021
1 parent 0b7da52 commit 4e2e8da
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion erpnext/patches/v13_0/healthcare_lab_module_rename_doctypes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
import frappe
from frappe.model.utils.rename_field import rename_field
from frappe.model.rename_doc import get_link_fields

def execute():
if frappe.db.exists('DocType', 'Lab Test') and frappe.db.exists('DocType', 'Lab Test Template'):
Expand All @@ -17,9 +18,18 @@ def execute():
frappe.reload_doc('healthcare', 'doctype', 'lab_test_template')

for old_dt, new_dt in doctypes.items():
if not frappe.db.table_exists(new_dt) and frappe.db.table_exists(old_dt):
should_rename = (
frappe.db.table_exists(old_dt)
and not frappe.db.table_exists(new_dt)
)
if should_rename:
frappe.reload_doc('healthcare', 'doctype', frappe.scrub(old_dt))

linked_doctypes = {x.parent for x in get_link_fields(old_dt)}
for linked_doctype in linked_doctypes:
frappe.reload_doctype(linked_doctype, force=True)
frappe.rename_doc('DocType', old_dt, new_dt, force=True)

frappe.reload_doc('healthcare', 'doctype', frappe.scrub(new_dt))
frappe.delete_doc_if_exists('DocType', old_dt)

Expand Down

0 comments on commit 4e2e8da

Please sign in to comment.