Version 6.x.x Source

Class Document

Inherits from frappe.model.base_document.BaseDocument

All controllers inherit from Document.

__init__ (self, arg1, arg2=None)

Constructor.

Parameters:

If DocType name and document name are passed, the object will load all values (including child documents) from the database.


_set_defaults (self)

No docs


_validate (self)

No docs


_validate_links (self)

No docs


_validate_mandatory (self)

No docs


add_comment (self, comment_type, text=None, comment_by=None, reference_doctype=None, reference_name=None)

Add a comment to this document.

Parameters:


cancel (self)

Cancel the document. Sets docstatus = 2, then saves.


check_docstatus_transition (self, docstatus)

Ensures valid docstatus transition. Valid transitions are (number in brackets is docstatus):


check_if_latest (self)

Checks if modified timestamp provided by document being updated is same as the modified timestamp in the database. If there is a different, the document has been updated in the database after the current copy was read. Will throw an error if timestamps don't match.

Will also validate document transitions (Save > Submit > Cancel) calling self.check_docstatus_transition.


check_no_back_links_exist (self)

Check if document links to any active document before Cancel.


check_permission (self, permtype, permlabel=None)

Raise frappe.PermissionError if not permitted


clear_cache (self)

No docs


clear_linked_with_cache (self)

No docs


delete (self)

Delete document.


get_all_children (self, parenttype=None)

Returns all children documents from Table type field in a list.


get_latest (self)

No docs


get_liked_by (self)

No docs


get_permlevel_access (self)

No docs


get_signature (self)

Returns signature (hash) for private URL.


get_url (self)

Returns Desk URL for this document. /desk#Form/{doctype}/{name}


has_permission (self, permtype=read, verbose=False)

Call frappe.has_permission if self.flags.ignore_permissions is not set.

Parameters:


has_website_permission (self, permtype=read, verbose=False)

Call frappe.has_website_permission if self.flags.ignore_permissions is not set.

Parameters:


insert (self, ignore_permissions=None)

Insert the document in the database (as a new document). This will check for user permissions and execute before_insert, validate, on_update, after_insert methods if they are written.

Parameters:


is_whitelisted (self, method)

No docs


load_from_db (self)

Load document and children from database and create properties from fields


notify_update (self)

Publish realtime that the current document is modified


raise_no_permission_to (self, perm_type)

Raise frappe.PermissionError.


reload (self)

Reload document from database


round_floats_in (self, doc, fieldnames=None)

Round floats for all Currency, Float, Percent fields for the given doc.

Parameters:


run_before_save_methods (self)

Run standard methods before INSERT or UPDATE. Standard Methods are:

Will also update title_field if set


run_method (self, method)

run standard triggers, plus those in hooks


run_post_save_methods (self)

Run standard methods after INSERT or UPDATE. Standard Methods are:


save (self, ignore_permissions=None)

Save the current document in the database in the DocType's table or tabSingles (for single types).

This will check for user permissions and execute validate before updating, on_update after updating triggers.

Parameters:


set_docstatus_user_and_timestamp (self)

No docs


set_new_name (self)

Calls frappe.naming.se_new_name for parent and child docs.


set_onload (self, key, value)

No docs


set_parent_in_children (self)

Updates parent and parenttype property in all children.


set_title_field (self)

Set title field based on template


submit (self)

Submit the document. Sets docstatus = 1, then saves.


update_children (self)

No docs


update_single (self, d)

Updates values for Single type Document in tabSingles.


validate_higher_perm_levels (self)

If the user does not have permissions at permlevel > 0, then reset the values to original / default


validate_table_has_rows (self, parentfield, raise_exception=None)

Raise exception if Table field is empty.


validate_update_after_submit (self)

No docs


validate_value (self, fieldname, condition, val2, doc=None, raise_exception=None)

Check that value of fieldname should be 'condition' val2 else throw Exception.



frappe.model.document.get_doc (arg1, arg2=None)

returns a frappe.model.Document object.

Parameters:

There are two ways to call get_doc

# will fetch the latest user object (with child table) from the database
user = get_doc("User", "test@example.com")

# create a new object
user = get_doc({
    "doctype":"User"
    "email_id": "test@example.com",
    "user_roles: [
        {"role": "System Manager"}
    ]
})