Complete guide to Frappe Framework document CRUD operations for ERPNext
The Document API provides methods for creating, reading, updating, and deleting documents in ERPNext. All operations interact with the Frappe Framework’s ORM layer.
import frappe# Get a specific Sales Invoiceinvoice = frappe.get_doc("Sales Invoice", "SI-2024-00001")print(invoice.customer)print(invoice.grand_total)# Get a Customercustomer = frappe.get_doc("Customer", "_Test Customer")print(customer.customer_name)
Similar to get_all() but with permission checks and additional features.
import frappe# Get list with permission filteringitems = frappe.get_list("Item", filters={"disabled": 0}, fields=["item_code", "item_name", "stock_uom"], order_by="item_name")
import frappe# Get document and validatedoc = frappe.get_doc("Sales Order", "SO-2024-00001")doc.validate() # Run validation hooks
import frappe# Submit a submittable documentinvoice = frappe.get_doc("Sales Invoice", "SI-2024-00001")invoice.submit()
import frappe# Cancel a submitted documentorder = frappe.get_doc("Purchase Order", "PO-2024-00001")order.cancel()
import frappe# Reload document from databasedoc = frappe.get_doc("Item", "ITEM-001")doc.item_name = "Updated Name"doc.reload() # Discard changes and reload from DB