Set up an approval workflow
This page sets up a two-level approval for Quotations:
- A user with the Sales User role creates a Quotation, and sends it for approval.
- A Sales Manager approves or rejects it.
- After the sales manager approves it, a Regional Manager approves or rejects it. The final approval submits the Quotation.
To learn the concepts first, read About workflows and approvals.
Prerequisites
- The System Manager role.
- The roles that approve, assigned to the right users. For example, create a Regional Manager role if it does not exist.
Step 1: Create the workflow states
A workflow state is one step of the workflow. ERPNext includes common states, such as Draft, Approved, Rejected, and Cancelled. Create the states that are missing:
- Open the Workflow State list, and select New.
- In State, enter the name, for example
Pending Sales Manager Approval. - In Style, select a color style, for example Warning.
- Select Save.
Repeat for Pending Regional Manager Approval.
Step 2: Create the workflow actions
A workflow action is a button, such as "Approve" or "Reject". ERPNext includes common actions. To add an action, open the Workflow Action Master list, select New, and enter the Workflow Action Name, for example Send for Approval.
Step 3: Create the workflow
- Open the Workflow list, and select New.
- Enter a Workflow Name, for example
Quotation Approval. - In Document Type, select Quotation.
- Keep Is Active selected. Only one workflow per DocType can be active.
- Fill in the Document States table, as described below.
- Fill in the Transitions table, as described below.
- Select Save.
Document states
Add one row for each state:
| State | Doc Status | Only Allow Edit For |
|---|---|---|
| Draft | 0 | Sales User |
| Pending Sales Manager Approval | 0 | Sales Manager |
| Pending Regional Manager Approval | 0 | Regional Manager |
| Approved | 1 | Regional Manager |
| Rejected | 0 | Sales User |
| Cancelled | 2 | Regional Manager |
- Doc Status: 0 for a saved draft, 1 for submitted, 2 for cancelled.
- Only Allow Edit For: the role that can edit the document in this state.
- Update Field and Update Value: optional. When the document enters the state, ERPNext sets this field to this value.
- Is Optional State: select it for states that are not part of the approval path, such as Rejected or Cancelled. ERPNext does not create workflow actions for optional states.
- Next Action Email Template: the email template for the approval email.
Transitions
Add one row for each move between states:
| State | Action | Next State | Allowed |
|---|---|---|---|
| Draft | Send for Approval | Pending Sales Manager Approval | Sales User |
| Pending Sales Manager Approval | Approve | Pending Regional Manager Approval | Sales Manager |
| Pending Sales Manager Approval | Reject | Rejected | Sales Manager |
| Pending Regional Manager Approval | Approve | Approved | Regional Manager |
| Pending Regional Manager Approval | Reject | Rejected | Regional Manager |
| Approved | Cancel | Cancelled | Regional Manager |
- Allowed: the role that can take the action.
- Allow Self Approval: clear it so that the user who created the document cannot approve it.
- Condition: optional. The transition is available only when the condition is true. Read Add conditions to transitions.
Step 4: Test the workflow
- Log in as a sales user, and create a Quotation. The form shows the Actions button instead of Submit.
- Select Actions > Send for Approval. The status changes to "Pending Sales Manager Approval".
- Log in as a sales manager, open the Quotation, and select Actions > Approve.
- Log in as a regional manager, and approve it. ERPNext submits the Quotation.
Workflow options
| Option | What it does |
|---|---|
| Is Active | Makes this the workflow of the DocType. Activating it deactivates other workflows on the same DocType. |
| Don't Override Status | Keeps the document's own status in the list, instead of the workflow state. |
| Send Email Alert | Emails the users who can take the next action. Read Approve documents with workflow actions. |
| Workflow State Field | The field that stores the state. The default is workflow_state. If the field does not exist, ERPNext creates it as a custom field. |
Add conditions to transitions
A condition is a Python expression. For example, to let the sales manager give the final approval only for quotations up to 100,000:
doc.grand_total <= 100000grand_total is the field name of Grand Total. To find a field name, open Customize Form, select the DocType, and read the Name column.
Conditions can also use these functions: frappe.db.get_value, frappe.db.get_list, frappe.session, frappe.utils.now_datetime, frappe.utils.get_datetime, frappe.utils.add_to_date, and frappe.utils.now. For example, this condition is true for documents created more than five days ago:
doc.creation < frappe.utils.add_to_date(frappe.utils.now_datetime(), days=-5, as_string=True, as_datetime=True)Things to know
- A workflow replaces the standard Submit and Cancel buttons. If no transition leads to a state with Doc Status 1, nobody can submit the document.
- To let users cancel, add a transition from a submitted state to a state with Doc Status 2.
Troubleshooting
"Cannot cancel before submitting. See Transition 2"
ERPNext shows this message when you save the workflow. The number is the row of the transition.
Cause: A transition goes from a state with Doc Status 0 directly to a state with Doc Status 2.
Fix: A cancelled state (Doc Status 2) can follow only a submitted state (Doc Status 1). Change the transition so that it starts from a submitted state.