Frappe Impl Workflow 标志

Frappe Impl Workflow

组织
Impertio-Studio
frappe-impl-workflow

Use when implementing document Workflows, approval chains, or state-based transitions in Frappe. Prevents stuck documents from missing transitions, broken approval chains, and permission errors on workflow actions. Covers Workflow DocType, Workflow State, Workflow Action, transition rules, allowed roles, conditions, workflow_state field, apply_workflow. Keywords: workflow, approval, transition, Workflow State, Workflow Action, state machine, approval chain, workflow_state, approval chain, document approval, multi-step approval, workflow stuck, status transitions..

Add to TypingMind

概览

发布者Impertio-Studio
代码仓库Frappe_Claude_Skill_Package
技能名称frappe-impl-workflow
星标数
180
复刻数
53
附带文件
4
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 4 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 Impertio-Studio 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Frappe Impl Workflow AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package/tree/main/skills/source/impl/frappe-impl-workflow
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package.git /tmp/Frappe_Claude_Skill_Package
mkdir -p .claude/skills
cp -r /tmp/Frappe_Claude_Skill_Package/skills/source/impl/frappe-impl-workflow .claude/skills/frappe-impl-workflow
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Frappe Impl Workflow,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Frappe Impl Workflow。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Frappe Impl Workflow 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Frappe Workflow Implementation

Step-by-step guide for implementing document workflows in Frappe. Covers design, setup, testing, and common approval chain patterns.

Quick Reference: Implementation Checklist

1. □ Design states and transitions on paper/diagram first
2. □ Create Workflow State records (master list)
3. □ Create Workflow Action Master records (Approve, Reject, etc.)
4. □ Create the Workflow DocType record
5. □ Add states with correct doc_status values
6. □ Add transitions with roles, actions, and conditions
7. □ Set allow_edit roles per state
8. □ Configure email notifications (optional)
9. □ Test every transition path with test users
10. □ Verify self-approval blocking works as expected

Step 1: Design Your Workflow

Before touching the UI, map out your workflow on paper.

Identify States

ALWAYS start by listing every distinct document stage:

Example — Purchase Order Approval:
  Draft → Pending Review → Pending Approval → Approved → Submitted → Cancelled

Map DocStatus to States

For submittable DocTypes, ALWAYS assign doc_status correctly:

Stagedoc_statusMeaning
All "in-progress" states0Document is Draft, editable
Final approved/active state1Document is Submitted, locked
Cancelled state2Document is Cancelled

NEVER assign doc_status = 1 to intermediate approval states. A submitted document cannot return to draft. Once submitted, the only forward path is another submitted state or cancellation.

Map Transitions

For each state, define: What actions are possible? Who can perform them? Any conditions?

Draft         →[Submit for Review / Creator]→     Pending Review
Pending Review →[Approve / Reviewer]→              Pending Approval
Pending Review →[Reject / Reviewer]→               Draft
Pending Approval →[Approve / Manager]→             Approved
Pending Approval →[Reject / Manager]→              Draft
Approved      →[Submit / Manager]→                 Submitted (doc_status=1)
Submitted     →[Cancel / Manager]→                 Cancelled (doc_status=2)

Step 2: Create Prerequisite Records

2a. Create Workflow States

Navigate to Workflow State list or create via API:

python
# Create states with appropriate styles
states = [
    {"workflow_state_name": "Draft", "style": ""},
    {"workflow_state_name": "Pending Review", "style": "Primary"},
    {"workflow_state_name": "Pending Approval", "style": "Warning"},
    {"workflow_state_name": "Approved", "style": "Success"},
    {"workflow_state_name": "Submitted", "style": "Info"},
    {"workflow_state_name": "Rejected", "style": "Danger"},
    {"workflow_state_name": "Cancelled", "style": "Inverse"},
]
for s in states:
    if not frappe.db.exists("Workflow State", s["workflow_state_name"]):
        frappe.get_doc({"doctype": "Workflow State", **s}).insert()

Available styles: Primary, Success, Warning, Danger, Info, Inverse (or empty for default).

2b. Create Workflow Action Masters

python
actions = ["Submit for Review", "Approve", "Reject", "Send Back", "Cancel"]
for action in actions:
    if not frappe.db.exists("Workflow Action Master", action):
        frappe.get_doc({
            "doctype": "Workflow Action Master",
            "workflow_action_name": action
        }).insert()

Step 3: Create the Workflow

Via UI

Navigate to Setup > Workflow > New Workflow:

  1. Set Workflow Name (e.g., "Purchase Order Approval")
  2. Set Document Type (e.g., "Purchase Order")
  3. Check Is Active
  4. Add states in the States table
  5. Add transitions in the Transitions table

Via Python

python
workflow = frappe.get_doc({
    "doctype": "Workflow",
    "workflow_name": "Purchase Order Approval",
    "document_type": "Purchase Order",
    "is_active": 1,
    "send_email_alert": 1,
    "states": [
        {"state": "Draft", "doc_status": "0", "allow_edit": "Purchase User"},
        {"state": "Pending Approval", "doc_status": "0", "allow_edit": "Purchase Manager"},
        {"state": "Approved", "doc_status": "1", "allow_edit": "Purchase Manager"},
        {"state": "Rejected", "doc_status": "0", "allow_edit": "Purchase User"},
        {"state": "Cancelled", "doc_status": "2"},
    ],
    "transitions": [
        {
            "state": "Draft",
            "action": "Submit for Review",
            "next_state": "Pending Approval",
            "allowed": "Purchase User",
            "allow_self_approval": 1,
        },
        {
            "state": "Pending Approval",
            "action": "Approve",
            "next_state": "Approved",
            "allowed": "Purchase Manager",
            "allow_self_approval": 0,
        },
        {
            "state": "Pending Approval",
            "action": "Reject",
            "next_state": "Rejected",
            "allowed": "Purchase Manager",
        },
        {
            "state": "Rejected",
            "action": "Submit for Review",
            "next_state": "Pending Approval",
            "allowed": "Purchase User",
        },
        {
            "state": "Approved",
            "action": "Cancel",
            "next_state": "Cancelled",
            "allowed": "Purchase Manager",
        },
    ],
})
workflow.insert()

Step 4: Configure Advanced Features

Conditional Transitions

Add Python conditions to show transitions only when criteria are met:

python
# Only allow approval for orders above 50000 by Senior Manager
{
    "state": "Pending Approval",
    "action": "Approve",
    "next_state": "Approved",
    "allowed": "Senior Manager",
    "condition": "doc.grand_total > 50000",
}

# Standard approval for orders up to 50000
{
    "state": "Pending Approval",
    "action": "Approve",
    "next_state": "Approved",
    "allowed": "Purchase Manager",
    "condition": "doc.grand_total <= 50000",
}

ALWAYS use doc.fieldname syntax in conditions (the document is exposed as a dict).

Available in conditions: frappe.db.get_value(), frappe.db.get_list(), frappe.session.user, frappe.utils.now_datetime(), frappe.utils.add_to_date(), frappe.utils.get_datetime().

Self-Approval Blocking

Set allow_self_approval = 0 on approval transitions. This means:

  • The document owner (creator) CANNOT perform this action
  • Administrator is ALWAYS exempt from this restriction
  • Other users with the required role CAN perform the action

Email Notifications

  1. Set send_email_alert = 1 on the Workflow
  2. On each state row, set send_email = 1 (default)
  3. Optionally link an Email Template via next_action_email_template
  4. Add a custom message on the state row for inline notification text

Update Fields on State Change

Use update_field and update_value on state rows to automatically set document fields:

python
# Set approval_status when entering "Approved" state
{"state": "Approved", "doc_status": "1",
 "update_field": "approval_status", "update_value": "Approved"}

# Use expression to set approval date dynamically
{"state": "Approved", "doc_status": "1",
 "update_field": "custom_approved_on", "update_value": "frappe.utils.now()",
 "evaluate_as_expression": 1}

Step 5: Test Your Workflow

Manual Testing Checklist

  1. Create a test document — verify it starts in the first state (Draft)
  2. Check available actions — only roles with transitions from Draft should see buttons
  3. Perform each transition — verify state changes correctly
  4. Test rejection paths — verify documents return to correct state
  5. Test self-approval — log in as document owner, verify blocked transitions
  6. Test conditions — create documents that meet/fail conditions, verify button visibility
  7. Test email notifications — verify emails sent on state changes
  8. Test with non-submittable DocType — verify all doc_status = 0

Programmatic Testing

python
# Get available transitions for a document
from frappe.model.workflow import get_transitions, apply_workflow

doc = frappe.get_doc("Purchase Order", "PO-00001")
transitions = get_transitions(doc)
# Returns list of dicts with action, next_state, allowed, etc.

# Apply a workflow action
updated_doc = apply_workflow(doc, "Approve")
# Returns the updated document after state change

Common Workflow Patterns

Pattern 1: Sequential Approval Chain

Draft → Level 1 Review → Level 2 Review → Approved → Submitted

Each level has its own role. Document moves linearly through approvals.

Pattern 2: Conditional Routing by Amount

Draft → Pending Approval
  ├─[amount <= 10000 / Team Lead]─→ Approved
  ├─[amount <= 50000 / Manager]──→ Approved
  └─[amount > 50000 / Director]──→ Approved

Use condition on each transition to route based on document values.

Pattern 3: Review with Rejection Loop

Draft ←──[Reject]── Pending Review ──[Approve]──→ Approved
  └──[Submit for Review]──→ Pending Review

Rejected documents return to Draft for revision. Creator resubmits. This is the most common approval pattern.

Pattern 4: Leave Approval

Applied (doc_status=0, allow_edit=Employee)
  └─[Approve / Leave Approver]─→ Approved (doc_status=1)
  └─[Reject / Leave Approver]─→ Rejected (doc_status=0)
Approved
  └─[Cancel / HR Manager]─→ Cancelled (doc_status=2)

Pattern 5: Document Review (Non-Submittable)

For non-submittable DocTypes, ALL states MUST have doc_status = 0:

Draft → Under Review → Reviewed → Published
(all doc_status = 0)

Migrating from Manual DocStatus to Workflow

If your DocType currently uses manual Submit/Cancel buttons and you want to add a workflow:

  1. Map existing documents — The workflow engine auto-maps existing documents to states based on their docstatus when the workflow is created
  2. Define a state for each docstatus — ALWAYS have at least one state per docstatus value your documents currently use
  3. Test with existing data — Verify that existing submitted documents show the correct workflow state
  4. Update list views — If using override_status, the workflow state replaces the Status column

NEVER activate a workflow without a state for docstatus=0. New documents would have no valid initial state.

Decision Tree

Starting a new workflow implementation?
│
├── What type of DocType?
│   ├── Submittable → can use doc_status 0, 1, 2
│   └── Non-submittable → ALL states must be doc_status = 0
│
├── How many approval levels?
│   ├── Single → Two-state: Draft → Approved
│   ├── Sequential → Chain: Draft → L1 → L2 → Approved
│   └── Conditional → Route by field values using conditions
│
├── Need self-approval blocking?
│   └── Set allow_self_approval = 0 on approval transitions
│
├── Need rejection/revision loop?
│   └── Add Reject transition back to Draft or previous state
│
├── Need email notifications?
│   ├── Enable send_email_alert on Workflow
│   └── Link Email Template on each state
│
└── Need automated field updates?
    └── Use update_field + update_value on target state

Troubleshooting

ProblemCauseSolution
No action buttons visibleUser lacks required roleAdd role to user OR add transition for user's role
"Self approval is not allowed"User is doc owner + allow_self_approval=0Have different user approve, or set flag to 1
"Workflow State not set"Document created before workflow activationRun update_default_workflow_status or manually set state
Document stuck in stateNo outgoing transition defined for current state + user roleAdd missing transition
"Cannot cancel before submitting"Transition goes from doc_status=0 to doc_status=2Add intermediate submitted state
Actions show for wrong usersRole assignment too broadUse more specific roles or add conditions

See Also

  • Workflow Patterns — Detailed step-by-step workflow examples
  • Decision Tree — Extended decision tree for workflow design
  • Examples — Code examples for common scenarios
  • Anti-Patterns — Mistakes to avoid
  • frappe-core-workflow — Workflow engine internals and API reference

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Frappe Impl Workflow AI 技能有什么作用?

Use when implementing document Workflows, approval chains, or state-based transitions in Frappe. Prevents stuck documents from missing transitions, broken approval chains, and permission errors on workflow actions. Covers Workflow DocType, Workflow State, Workflow Action, transition rules, allowed roles, conditions, workflow_state field, apply_workflow. Keywords: workflow, approval, transition, Workflow State, Workflow Action, state machine, approval chain, workflow_state, approval chain, document approval, multi-step approval, workflow stuck, status transitions..

为什么在 TypingMind 中使用 Frappe Impl Workflow?

因为您只需安装一次,就能搭配任何模型使用。Frappe Impl Workflow 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Frappe Impl Workflow?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package/tree/main/skills/source/impl/frappe-impl-workflow。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Frappe Impl Workflow?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Frappe Impl Workflow 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Frappe Impl Workflow 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Frappe Impl Workflow AI 技能免费吗?

是的。Impertio-Studio 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇