feat: Document.rename API

Transform current document object using the rename_doc API. The design
of the API should allow for easy action queueing.

Defined as `rename(self, name: str, merge: bool = False, force: bool = False)`

Usage:

    In [1]: doc = frappe.get_doc("Person", "5a188f66c1")

    In [2]: doc.rename("5a188f66c2")

    In [3]: doc.name
    Out[3]: '5a188f66c2'
This commit is contained in:
Gavin D'souza 2022-02-25 01:27:21 +05:30
parent 0b418d2728
commit 5a3d8f925e

View file

@ -938,6 +938,14 @@ class Document(BaseDocument):
self.docstatus = DocStatus.cancelled()
return self.save()
@whitelist.__func__
def _rename(self, name: str, merge: bool = False, force: bool = False):
"""Cancel the document. Sets `docstatus` = 2, then saves.
"""
from frappe.model.rename_doc import rename_doc
self.name = rename_doc(doc=self, new=name, merge=merge, force=force)
self.reload()
@whitelist.__func__
def submit(self):
"""Submit the document. Sets `docstatus` = 1, then saves."""
@ -948,6 +956,12 @@ class Document(BaseDocument):
"""Cancel the document. Sets `docstatus` = 2, then saves."""
return self._cancel()
@whitelist.__func__
def rename(self, name: str, merge: bool = False, force: bool = False):
"""Rename the document to `name`. This transforms the current object.
"""
return self._rename(name=name, merge=merge, force=force)
def delete(self, ignore_permissions=False):
"""Delete document."""
frappe.delete_doc(self.doctype, self.name, ignore_permissions = ignore_permissions, flags=self.flags)