ERPNext Doctype Guide 101
ERPNext Doctype Guide 101
Save changes and click button "Go to Expense Request List" on Top of
page
Now, you can see that you can add multiple Expense Lines in your
Expense Request
List View
Form View with 2 tabs
Configurations
Save changes and click button "Go to Expense Request List" on Top of
page
You should see changes in List and Form view.
Document Series
There are many ways to setup Naming, in this case we want to use
Expression = format:EXP{YY}{####}
Open DocType = Expense Request and setup Naming as follow,
Now, create new Expense Request, you will see that the ID (name) is a
Running Series
Note:
As an option, you can set another field as Title, which will show in Link field
too.
As "Name" is auto field (ID), just add one more field "Title"
Title will be on the left most of the list view instead of Name (ID)
Name (ID) is auto generated and will be on the right most of the list
view
Add Expense Type field as Link field in Expense Request
Add Expense Type with Type "Link" with Options "Expense Type"
if we did not use Tile option, we will see Expense Type by Name (ID) as
normal
Status field
Status field is a special field, which can have color highlighted
Once all has been set, we will see Status as part of the document
Server Script (Python)
In Frappe can write server side script with python for almost anything as Low-
Code, and hook it with DocType event.
total = 0.0
for line in doc.expense_lines:
total = total + line.amount
doc.total_amount = total
Test by adding Expense Lines with Amount, calculation will happen on
both create/update.
Types of Script
1. DocType Event
2. Scheduler Event
3. Permission Query (filter for list view and linked field)
4. API (public method)
frappe.ui.form.on('Expense Request', {
onload(frm) {
if (frm.doc.expense_type) {
return
}
frm.call({
method: 'frappe.client.get_single_value',
args: {
doctype: 'Expense Settings',
field: 'default_expense_type'
}
})
.then(r => {
frm.set_value('expense_type', r.message)
});
}
})
Test create new Expense Request, you will see the Expense Type is
now set to default type.
Now, in any Document with link field "Expense Type", use can set
session default value.
Go to Expense Request list, and open Session Defaults
Note:
Default value is set for each user.
Button Action
Buttons (and any UI element) in Frappe is adding by client script. Normally, a
button is used to execute extra business logic for current form.
Add 2 actions, "Approve" and "Change status", under a button group "Actions"
Web Form
Web Form is a web page that map directly with a DocType. This make it easy
for external users to create records without having to access the "Desk".
2. Enable Login
Enable Login
As Login Enabled, we can allow CRUD operation and declare columns
on List View
Save and "See on Website", you now see that now Login is required
Test a full CRUD operations
Web Page
While Web Form link directly with a DocType, Web Page does not. Web Page is
the way to easily create website page from template (think wordpress).
Print Format
By default, every DocType will has "Standard" print format ready to use. But
user can always create more print format easily.
Click "Save", the new Print Format will be created. You can go to Print
Format List to see it.
Go to Expense Request form, and click "Print" again with new Print
Format
Note:
Report View
Report is another type of view that can show more columns (List view only
limit to 7 columns).
Similar to print format, every DocType comes with a Standard Report View.
User can create more reports with ease.
Run report again, and it will show result as per last Save
Dashboard View
Dashboard View is the place to show Number Card and Chart for each
document type.
Note:
You can Customize Dashboard later on and create as many chart / card
you want
Kanban View
Kanban View another to organize documents based on some Selection Field.
Submittable Document
This is the way to control internal state of a document. Submitable only has 3
docstatus
1. Draft: docstatus = 0
2. Submitted: docstatus = 1
3. Cancelled: docstatus = 2
Note:
As there is "Status" field, the label (green) will follow status after
submitted (Approved)
If there is no "Status" field, the label will be "Submitted"
Approval Workflow
Each Doctype can has 1 active workflow. This is a simple workflow consisting
of States and Transition
Example:
Permissions
Permission in Frappe is very simple and straightforward, and it only has 3
types of permission.
Apply to All Document Types = True, any document with field Expense
Type will has this permission applied
Click "View Permitted Documents" to find see what documents this
user has permission to see.
Some Magics
Following are some useful tools / features that I can think of now. There are
more...
System Console
Run SQL or Python Code
Global Search
As Calculator
Global Search and field (Config in Doctype Field and Global Search
Setting)
Search by Tags
Rest API
Copy / Paste
Copy to clipboard
Simple URL
Error Logs