Hello everyone,
I’m quite new to Frappe, so please forgive any mistakes in my explanation or approach. I’m working on a custom workflow system for a doctype, and I need some help with a sub-workflow (transition flow) that manages sequential approvals.
What I’m Building
- Main Workflow:
I’ve set up a workflow for my target doctype with these states:- Draft: Employee creates and submits the document.
- Pending: If a sub-workflow is needed, the document transitions here.
- Approve: If all required sub-workflow approvals are completed, the document moves here.
- Reject: If anyone in the sub-workflow rejects, the document moves here.
- Sub-Workflow Doctype:
This is a custom doctype that stores:- Reference to the main workflow and doctype.
- Starting and ending states for the transition.
- A child table listing all approvers for this sub-workflow.
Requirements
- Sequential Approval:
Only the next approver in the list can approve or reject the document. Other users can only view the document; the approve/reject buttons are not visible to them. - Approval Trail:
The document must display an approval trail showing who approved/rejected and the date and time of each action.
Current Issue
The document enters the sub-workflow (Pending state) correctly. But, as soon as the administrator (first approver) approves, the document immediately shows as “Approved,” even if there are more approvers left.
I want the document to move to “Approved” only after all listed approvers have approved it.
Sub-Workflow Doctype Structure
- Fields:
- Main workflow reference
- Doctype reference
- Starting state (transition flow start)
- Ending state(s) (transition flow end)
- Child table of approvers (with user and status fields)
What I Need Help With
- How can I enforce sequential approval in the sub-workflow?
Only the next pending approver should see the approve/reject buttons. - How can I ensure the document only moves to “Approved” after all approvers have approved?
- How can I display a clear approval trail (user, action, timestamp) on the document?
Any guidance, sample code, or pointers to relevant Frappe documentation would be greatly appreciated!
PS: Python API for Sub-Workflow
I have also developed a custom Python API to handle the sub-workflow logic in Frappe.
What the Code Does
- Transition Handler:
The main handler (transition_flow_handler
) triggers on document save. It checks if the document has entered the sub-workflow’s starting state and, if so, sets up the approval flow. - Sequential Approval:
Only the current approver in the sequence can take action (approve/reject). The document is assigned to the next approver only after the previous one approves. - Approval Trail:
Every action (submission, assignment, approval, rejection) is logged in anapproval_trail
field (user, action, comments, timestamp), making the trail visible on the document. - Workflow State Management:
The document moves to “Approved” only after all approvers have approved, or to “Rejected” if anyone rejects. The workflow state is updated accordingly. - API Endpoints:
The API exposes whitelisted methods for processing approval actions and fetching the current approver, which can be called from the frontend or via REST API.
This setup helps enforce a strict, auditable, and sequential sub-workflow approval process for your documents in Frappe.
Again, apologies if my explanation or approach is off—I’m still learning Frappe and appreciate your patience.
Thanks in advance for any help or suggestions!