frappe-core-workflow

在创建或修改 Frappe 工作流及相关元素时使用的工具,覆盖定义工作流、状态与转换、添加操作条件、排查工作流权限错误等,旨在防止因转换配置错误、状态权限缺失或循环路径导致文档卡住。涵盖工作流 DocType、状态、转换、操作、条件(Python 表达式)、工作流权限、workflow_state 字段与 Workflow Action DocType,关键词包括工作流、状态、转换、操作、条件、审批与文档卡住等。

仓库最近推送
GitHub Stars
211
Forks
61
Issues / PRs
4

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "frappe-core-workflow":https://skillpi.com/zh/skills/deepskill-fbce09bed0cbda7bd806db805b4e5dba872ca438425f57e6494e617e8d768645。安装前核对上游来源和版本:https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

在创建或修改 Frappe 工作流及相关元素时使用的工具,覆盖定义工作流、状态与转换、添加操作条件、排查工作流权限错误等,旨在防止因转换配置错误、状态权限缺失或循环路径导致文档卡住。涵盖工作流 DocType、状态、转换、操作、条件(Python 表达式)、工作流权限、workflow_state 字段与 Workflow Action DocType,关键词包括工作流、状态、转换、操作、条件、审批与文档卡住等。

0 下载

介绍来源: third_party · Impertio-Studio · 2.0 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: frappe-core-workflow
description: >
  Use when creating or modifying Frappe Workflows, defining states and transitions, adding action conditions, or troubleshooting workflow permission errors.
  Prevents stuck documents from misconfigured transitions, missing state permissions, and circular workflow paths.
  Covers Workflow DocType, workflow states, transitions, actions, conditions (Python expressions), workflow permissions, workflow_state field, Workflow Action DocType.
  Keywords: workflow, states, transitions, actions, conditions, workflow_state, Workflow Action, approval, document workflow, approval process, document stuck, cannot change status, workflow not moving, who can approve..
license: MIT
compatibility: "Claude Code, Claude.ai Projects, Claude API. Frappe v14-v16."
metadata:
  author: OpenAEC-Foundation
  version: "2.0"

Workflow Engine

The Frappe Workflow engine is a state machine that controls document lifecycle through configurable states, transitions, and role-based permissions. It governs when and how documents change status, who can perform actions, and what side effects occur on each transition.

Quick Reference

Workflow DocType            → Defines the state machine for a specific DocType
├── states (child table)    → Workflow Document State rows
│   ├── state               → Link to Workflow State
│   ├── doc_status          → 0 (Draft), 1 (Submitted), 2 (Cancelled)
│   ├── allow_edit          → Role that can edit in this state
│   ├── update_field        → Field to update when entering state
│   ├── update_value        → Value to set (literal or expression)
│   └── next_action_email_template → Email Template link
└── transitions (child table) → Workflow Transition rows
    ├── state               → Source state (Link to Workflow State)
    ├── action              → Link to Workflow Action Master
    ├── next_state          → Target state (Link to Workflow State)
    ├── allowed             → Role that can perform this action
    ├── allow_self_approval → Check (default: 1)
    ├── condition           → Python expression (optional)
    └── transition_tasks    → Link to Workflow Transition Tasks

Key Fields on Workflow DocType

Field Type Purpose
workflow_name Data Unique identifier
document_type Link → DocType Target DocType
is_active Check Only ONE workflow per DocType can be active
workflow_state_field Data Default: workflow_state
override_status Check Prevent workflow from overriding list view status
send_email_alert Check Email notifications with next possible actions

How the Engine Works

1. Activation and Field Creation

When a Workflow is saved with is_active = 1:

  • All other workflows for the same DocType are deactivated automatically
  • A hidden Custom Field (workflow_state_field, default workflow_state) is created on the target DocType if it does not exist
  • The field is type Link to Workflow State, with hidden=1, allow_on_submit=1, no_copy=1
  • Existing documents with empty workflow state get their state set based on their current docstatus

2. State Resolution

Every document under a workflow has a workflow_state field. The engine resolves available transitions by:

  1. Reading current workflow_state from the document
  2. Filtering workflow.transitions where transition.state == current_state
  3. Filtering by user roles: transition.allowed in frappe.get_roles()
  4. Evaluating transition.condition via frappe.safe_eval() (if set)
  5. Returning matching transitions as available actions

3. Applying a Transition

When apply_workflow(doc, action) is called:

  1. Load document from DB (fresh read)
  2. Get available transitions for current user
  3. Find transition matching the requested action
  4. Check self-approval: blocked if allow_self_approval=0 AND user is document owner
  5. Set workflow_state_field to transition.next_state
  6. If update_field is set on the target state, update that field
  7. Execute transition tasks (sync first, then async via frappe.enqueue)
  8. Handle docstatus change based on source/target state doc_status values
  9. Save/Submit/Cancel document accordingly
  10. Add workflow comment

Workflow and DocStatus Interaction

CRITICAL: The workflow engine controls docstatus transitions. You NEVER call doc.submit() or doc.cancel() directly on a workflow-controlled document. The workflow does it.

DocStatus Transition Rules

Source doc_status Target doc_status Engine Action Valid?
0 (Draft) 0 (Draft) doc.save() YES
0 (Draft) 1 (Submitted) doc.submit() YES
1 (Submitted) 1 (Submitted) doc.save() YES
1 (Submitted) 2 (Cancelled) doc.cancel() YES
2 (Cancelled) ANY BLOCKED NO
1 (Submitted) 0 (Draft) BLOCKED NO
0 (Draft) 2 (Cancelled) BLOCKED NO

ALWAYS define your states so that docstatus only moves forward: 0→0, 0→1, 1→1, 1→2. NEVER create a transition from a cancelled state or from submitted back to draft.

Non-Submittable DocTypes

If the target DocType is NOT submittable, ALL states MUST have doc_status = 0. The engine validates this and throws an error if any state has doc_status = 1 or 2 on a non-submittable DocType.

Workflow States

Workflow State is a separate DocType used as a master list. Each state has:

Field Purpose
state Display name of the state
style CSS class for badge display (Primary, Success, Warning, Danger, Info, Inverse)
icon Font Awesome icon class

State Row Fields (Workflow Document State)

Field Purpose
state Link to Workflow State
doc_status Select: 0, 1, or 2
allow_edit Link to Role — ONLY this role can edit the document in this state
update_field Field to update when document enters this state
update_value Value to set (string or Python expression if evaluate_as_expression=1)
is_optional_state Check — optional states are skipped in get_next_possible_transitions
send_email Check (default 1) — send email notification on entering this state
next_action_email_template Link to Email Template
message Text message for the email notification

Workflow Transitions

Each transition row defines one possible action:

Field Purpose
state Source state (MUST exist in states table)
action Link to Workflow Action Master (e.g., "Approve", "Reject", "Review")
next_state Target state (MUST exist in states table)
allowed Link to Role — ONLY users with this role see this action
allow_self_approval Check (default 1) — if 0, document owner cannot perform this action
condition Python expression evaluated with frappe.safe_eval()
transition_tasks Link to Workflow Transition Tasks (v15+)

Condition Expressions

Conditions are Python expressions evaluated in a sandboxed environment. Available globals:

# Available in condition expressions:
frappe.db.get_value(doctype, name, fieldname)
frappe.db.get_list(doctype, filters, fields)
frappe.session.user
frappe.session.roles  # NOT available — use frappe.get_roles() outside conditions
frappe.utils.now_datetime()
frappe.utils.add_to_date(date, **kwargs)
frappe.utils.get_datetime(datetime_str)
frappe.utils.now()
doc.fieldname  # Access any field on the document (as dict)

Example conditions:

doc.grand_total > 50000
doc.department == "HR"
doc.grand_total > 50000 and doc.department != "Finance"

Workflow Actions

Workflow Action Master

Simple DocType with just a workflow_action_name field. Common actions: Approve, Reject, Review, Send Back, Cancel. Create these first before defining transitions.

Workflow Action DocType

Tracks pending actions for users. Created automatically when a document enters a state with outgoing transitions.

Field Purpose
status Open or Completed
reference_doctype The DocType of the document
reference_name The document name
workflow_state Current workflow state
user Assigned user
permitted_roles Table MultiSelect of roles that can act
completed_by User who completed the action
completed_by_role Role used to complete

Workflow Actions appear in the user's "Workflow Action" list and can be acted on via email links.

Self-Approval Control

def has_approval_access(user, doc, transition):
    return (user == "Administrator"
            or transition.get("allow_self_approval")
            or user != doc.get("owner"))
  • Administrator ALWAYS has approval access regardless of settings
  • If allow_self_approval = 1 (default): document owner CAN approve
  • If allow_self_approval = 0: document owner CANNOT approve their own document

Decision Tree

Need workflow on a DocType?
├── Is DocType submittable?
│   ├── YES → States can use doc_status 0, 1, 2
│   └── NO  → ALL states MUST have doc_status = 0
├── Define states → Create Workflow State records first
├── Define transitions → Need Workflow Action Master records first
├── Who can edit in each state? → Set allow_edit per state
├── Need conditional transitions?
│   └── Use Python expressions with doc.field access
├── Need to block self-approval?
│   └── Set allow_self_approval = 0 on specific transitions
└── Need email notifications?
    └── Set send_email_alert on Workflow + email templates on states

Common Errors

Error Cause Fix
WorkflowStateError Document has no workflow_state set Ensure workflow sets initial state on creation
WorkflowTransitionError Action not valid for current state/role Verify transitions table covers all needed paths
WorkflowPermissionError User lacks role for transition, or self-approval blocked Check allowed role and allow_self_approval
"Illegal Document Status" Invalid docstatus transition (e.g., 0→2) Fix state doc_status values
"Cannot cancel before submitting" Transition from draft (0) to cancelled (2) Add intermediate submitted (1) state

See Also

  • API Reference — Complete workflow Python API
  • Examples — Workflow configuration examples
  • Anti-Patterns — Common mistakes and how to avoid them
  • frappe-impl-workflow — Step-by-step implementation guide

版本历史

  1. v3.1.1 GitHub ↗
    原版更新说明

    ## What's new Expanded Keywords in all skill descriptions with user-friendly, non-technical discovery terms. Skills are now easier to find when users describe problems in plain language instead of technical terminology. Examples of added terms: - Symptom-based: "app is slow", "nothing shows", "container won't start" - Beginner-friendly: "how do I start", "what is", "getting started" - Error messages: literal error text users would paste - Alternative names: common synonyms and abbreviations No skill content was changed. Only the Keywords line in SKILL.md frontmatter was expanded.

  2. v3.1.0 GitHub ↗
    原版更新说明

    ## What's new - package.json with agents.skills[] manifest for external discovery (60 skills) - agents/openai.yaml for OpenAI Codex - GitHub topic agentskills added - SKILLS_LOG.md added to .gitignore - Em-dashes replaced with colons in 31 SKILL.md section headings Enables discovery via npx skills add, skills.sh, LobeHub, and other platforms.

  3. v3.0.0 GitHub ↗
    原版更新说明

    ## Summary - **60 deterministic skills** for Frappe Framework v14-v16 (up from 53 in v2.0) - **~95% surface area coverage** (up from ~85%) - 7 new skills + 12 existing skills extended with new reference files ## New Skills (7) | Skill | Category | Coverage | |-------|----------|----------| | `frappe-core-translation` | core | i18n, _(), __(), CSV/PO files, string extraction | | `frappe-core-utils` | core | 140+ date, number, string, validation functions | | `frappe-syntax-print` | syntax | Print formats, PDF generation, Letter Head | | `frappe-syntax-query-builder` | syntax | frappe.qb, joins, aggregation, cross-DB | | `frappe-impl-workspace` | impl | Workspace builder, number cards, charts | | `frappe-core-logging` | core | frappe.logger(), Error Log, Sentry integration | | `frappe-core-search` | core | Link search, global search, SQLiteSearch FTS5 | ## Extended Skills (12) 13 new reference files added to existing skills covering: Controls API, Tree View, Portal Generators, Print Format decision tree, Email system, Module/Workspace shipping, complete Document API, custom bench commands, request lifecycle, advanced debugging (VS Code DAP), Frappe Packages, data masking (v16+), and Python type stubs. ## Stats | Category | Count | |----------|:-----:| | syntax/ | 13 | | core/ | 11 | | impl/ | 14 | | errors/ | 7 | | ops/ | 8 | | agents/ | 5 | | testing/ | 2 | | **Total** | **60** | ## Install ```bash git clone https://github.com/OpenAEC-Foundation/Frappe_Claude_Skill_Package.git cp -r Frappe_Claude_Skill_Package/skills/source/* ~/.claude/skills/ ```

  4. v2.0.0 GitHub ↗
    原版更新说明

    ## Frappe Claude Skill Package v2.0.0 Massive upgrade from 28 ERPNext-specific skills to **53 Frappe Framework skills** covering ~85% of the Frappe surface area. ### What's New - **25 new skills** across 3 new categories (ops, testing, agents) - **28 existing skills** fully rewritten with fresh research - **Renamed** from `erpnext-*` to `frappe-*` (all skills are Frappe Framework, not ERPNext-specific) - **7 categories**: syntax (11), core (7), impl (13), errors (7), ops (8), agents (5), testing (2) ### New Categories - **ops/** — Bench CLI, deployment, backup, performance, upgrades, frontend build, cloud - **testing/** — Unit/integration tests, CI/CD with GitHub Actions - **3 new agents** — debugger, migrator, architect ### Key Improvements - All skills verified against official Frappe docs (March 2026) - v16 features documented: `extend_doctype_class`, data masking, type annotations - MIT license (was LGPL-3.0) - Deterministic language throughout (ALWAYS/NEVER) 🤖 Generated with [Claude Code](https://claude.com/claude-code)

  5. v1.1.0 GitHub ↗
    原版更新说明

    V16 compatibility update and documentation improvements. ## Added - USAGE.md with platform-specific guides (Claude.ai, Claude Code, API) - Complete README overhaul with quick start guide ## Changed - All 28 skills updated for ERPNext/Frappe V16 compatibility - Agent Skills now follow standard skill structure - Improved validation: 28/28 skills pass all checks ## Fixed - V16-specific syntax changes in 9 skills - Agent SKILL.md files now under 500 lines

此处仅展示最近 5 个版本。 在原站查看完整版本历史 ↗

当前收录版本

2.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供 Frappe 工作流引擎的完整技术文档,涵盖状态机设计、权限控制、条件表达式等核心机制
  • 面向开发者解决实际工作流配置与调试问题,实用性强
触发精准95/100

亮点

  • 触发词覆盖全面(workflow, states, transitions, actions, conditions, workflow_state, approval 等),边界清晰
结构规范90/100

亮点

  • 文档结构清晰,含 Quick Reference、How the Engine Works、Decision Tree、Common Errors 等章节
  • frontmatter 完整,有代码示例和表格说明
执行可靠90/100

亮点

  • 内容基于 Frappe 官方工作流机制,参数说明准确
  • 涵盖异常处理(如 docstatus 转换规则、self-approval 控制),无不可逆操作风险
证据可验 (前四项均值)90/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 保存或修改文件

    先确认输出目录和同名文件是否会被覆盖;重要文件保留备份,优先写入新的输出目录。

    主文档提及 · 第 94, 96 行
  • 管理员或提升权限

    确认确有必要再提升权限;不要关闭防护、绕过证书验证或扩大整个系统的访问权限。

    主文档提及 · 第 198, 203 行

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。