@frappe.whitelist()
def rename_doc(doctype, old, new, force=False, merge=False, ignore_permissions=False):
 if (not frappe.db.exists(doctype, old)):
  return
 force = cint(force)
 merge = cint(merge)
 meta = frappe.get_meta(doctype)
 old_doc = frappe.get_doc(doctype, old)
 out = (old_doc.run_method(u'before_rename', old, new, merge) or {})
 new = ((out.get(u'new') or new) if isinstance(out, dict) else (out or new))
 if (doctype != u'DocType'):
  new = validate_rename(doctype, new, meta, merge, force, ignore_permissions)
 if (not merge):
  rename_parent_and_child(doctype, old, new, meta)
 link_fields = get_link_fields(doctype)
 update_link_field_values(link_fields, old, new, doctype)
 rename_dynamic_links(doctype, old, new)
 if (doctype == u'DocType'):
  rename_doctype(doctype, old, new, force)
 update_attachments(doctype, old, new)
 if merge:
  frappe.delete_doc(doctype, old)
 new_doc = frappe.get_doc(doctype, new)
 new_doc._local = getattr(old_doc, u'_local', None)
 new_doc.run_method(u'after_rename', old, new, merge)
 rename_versions(doctype, old, new)
 if (not merge):
  rename_password(doctype, old, new)
 frappe.db.sql(u"update tabDefaultValue set defvalue=%s where parenttype='User Permission'\n DCTB  DCTB and defkey=%s and defvalue=%s", (new, doctype, old))
 frappe.clear_cache()
 if merge:
  new_doc.add_comment(u'Edit', _(u'merged {0} into {1}').format(frappe.bold(old), frappe.bold(new)))
 else:
  new_doc.add_comment(u'Edit', _(u'renamed from {0} to {1}').format(frappe.bold(old), frappe.bold(new)))
 return new

@ frappe . whitelist ( ) def rename_doc ( doctype , old , new , force = False , merge = False , ignore_permissions = False ) : if ( not frappe . db . exists ( doctype , old ) ) : return force = cint ( force ) merge = cint ( merge ) meta = frappe . get_meta ( doctype ) old_doc = frappe . get_doc ( doctype , old ) out = ( old_doc . run_method ( u'before_rename' , old , new , merge ) or { } ) new = ( ( out . get ( u'new' ) or new ) if isinstance ( out , dict ) else ( out or new ) ) if ( doctype != u'DocType' ) : new = validate_rename ( doctype , new , meta , merge , force , ignore_permissions ) if ( not merge ) : rename_parent_and_child ( doctype , old , new , meta ) link_fields = get_link_fields ( doctype ) update_link_field_values ( link_fields , old , new , doctype ) rename_dynamic_links ( doctype , old , new ) if ( doctype == u'DocType' ) : rename_doctype ( doctype , old , new , force ) update_attachments ( doctype , old , new ) if merge : frappe . delete_doc ( doctype , old ) new_doc = frappe . get_doc ( doctype , new ) new_doc . _local = getattr ( old_doc , u'_local' , None ) new_doc . run_method ( u'after_rename' , old , new , merge ) rename_versions ( doctype , old , new ) if ( not merge ) : rename_password ( doctype , old , new ) frappe . db . sql ( u"update tabDefaultValue set defvalue=%s where parenttype='User Permission'\n DCTB  DCTB and defkey=%s and defvalue=%s" , ( new , doctype , old ) ) frappe . clear_cache ( ) if merge : new_doc . add_comment ( u'Edit' , _ ( u'merged {0} into {1}' ) . format ( frappe . bold ( old ) , frappe . bold ( new ) ) ) else : new_doc . add_comment ( u'Edit' , _ ( u'renamed from {0} to {1}' ) . format ( frappe . bold ( old ) , frappe . bold ( new ) ) ) return new
rename a document .