Inherits from frappe.model.base_document.BaseDocument
All controllers inherit from Document
.
__init__ (self, arg1, arg2=None)
Constructor.
Parameters:
arg1
- DocType name as string or document dictarg2
- Document name, if arg1
is DocType name.If DocType name and document name are passed, the object will load all values (including child documents) from the database.
No docs
No docs
No docs
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:
comment_type
- e.g. Comment
. See Comment for more info.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
):
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
No docs
clear_linked_with_cache (self)
No docs
Delete document.
get_all_children (self, parenttype=None)
Returns all children documents from Table type field in a list.
No docs
No docs
No docs
Returns signature (hash) for private URL.
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:
permtype
- one of read
, write
, submit
, cancel
, delete
has_website_permission (self, permtype=read, verbose=False)
Call frappe.has_website_permission
if self.flags.ignore_permissions
is not set.
Parameters:
permtype
- one of read
, write
, submit
, cancel
, delete
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:
ignore_permissions
- Do not check permissions if True.No docs
Load document and children from database and create properties from fields
Publish realtime that the current document is modified
raise_no_permission_to (self, perm_type)
Raise frappe.PermissionError
.
Reload document from database
round_floats_in (self, doc, fieldnames=None)
Round floats for all Currency
, Float
, Percent
fields for the given doc.
Parameters:
doc
- Document whose numeric properties are to be rounded.fieldnames
- [Optional] List of fields to be rounded.run_before_save_methods (self)
Run standard methods before INSERT
or UPDATE
. Standard Methods are:
validate
, before_save
for Save.validate
, before_submit
for Submit.before_cancel
for Cancelbefore_update_after_submit
for Update after SubmitWill also update title_field if set
run standard triggers, plus those in hooks
Run standard methods after INSERT
or UPDATE
. Standard Methods are:
on_update
for Save.on_update
, on_submit
for Submit.on_cancel
for Cancelupdate_after_submit
for Update after Submitsave (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:
ignore_permissions
- Do not check permissions if True.set_docstatus_user_and_timestamp (self)
No docs
Calls frappe.naming.se_new_name
for parent and child docs.
No docs
Updates parent
and parenttype
property in all children.
Set title field based on template
Submit the document. Sets docstatus
= 1, then saves.
No docs
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:
arg1
- Document dict or DocType name.arg2
- [optional] document name.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"}
]
})