Token导航 LogoToken导航TokenDH.com
待分类只读github未标认证来源可访问许可证需确认审计通过

frappe-syntax-hooks-eventsfrappe 语法挂钩事件

Agent Skill

frappe-syntax-hooks-events 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

582

周安装

24

GitHub Stars

87

下载量

190
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:frappe-syntax-hooks-events(frappe 语法挂钩事件)
来源仓库:https://github.com/openaec-foundation/erpnext_anthropic_claude_development_skill_package
仓库路径:skills/frappe-syntax-hooks-events
安装命令:
npx skills add https://github.com/openaec-foundation/erpnext_anthropic_claude_development_skill_package --skill frappe-syntax-hooks-events
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/openaec-foundation/erpnext_anthropic_claude_development_skill_package --skill frappe-syntax-hooks-events

简介

frappe-syntax-hooks-events 用于处理 GitHub 仓库、Issue、Pull Request 等协作信息,适合整理代码变更与项目状态。

  • 适用于围绕仓库状态、代码协作事项进行信息梳理的场景。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用。
  • 安装前需确认权限范围和维护状态,注意可能触发联网或命令执行操作。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Document Lifecycle Hooks (doc_events)

Quick Reference: Event Execution Order

Insert (new document)

OrderEventPurposeCan Raise?
1before_insertSet defaults before namingYES
2before_namingModify naming logicYES
3autonameSet the name propertyYES
4before_validateAuto-set missing valuesYES
5validateValidation logic — throw to abortYES
6before_saveFinal mutations before DB writeYES
7db_insert*Internal* — writes row to DB
8after_insertPost-insert logic (runs once ever)YES
9on_updatePost-save logic (runs on every save)YES
10on_changeFires if any field value changedYES

Save (existing document)

OrderEventPurpose
1before_validateAuto-set missing values
2validateValidation logic — throw to abort
3before_saveFinal mutations before DB write
4db_update*Internal* — updates row in DB
5on_updatePost-save logic
6on_changeFires if any field value changed

Submit

OrderEventPurpose
1before_validateAuto-set missing values
2validateValidation logic
3before_saveFinal mutations before DB write
4before_submitPre-submit logic — throw to abort
5db_update*Internal* — updates row in DB
6on_submitPost-submit logic (GL entries etc)
7on_updatePost-save logic
8on_changeFires if any field value changed

Cancel

OrderEventPurpose
1before_cancelPre-cancel validation
2db_update*Internal* — updates row in DB
3on_cancelPost-cancel logic (reverse GL etc)
4on_changeFires if any field value changed

Delete

OrderEventPurpose
1on_trashPre-delete cleanup
2after_deletePost-delete logic

Other Operations

OperationEvents (in order)
Renamebefore_renameafter_rename
Amendbefore_insert chain runs on the new amended doc
Update After Submitbefore_update_after_submitdb_updateon_update_after_submiton_change

doc_events in hooks.py: Syntax

Basic Structure

# hooks.py
doc_events = {
    "Sales Invoice": {
        "on_submit": "myapp.events.sales_invoice.on_submit",
        "on_cancel": "myapp.events.sales_invoice.on_cancel",
    },
    "Purchase Order": {
        "validate": "myapp.events.purchase_order.validate",
    }
}

Wildcard: Apply to ALL DocTypes

doc_events = {
    "*": {
        "after_insert": "myapp.events.global_handler.after_insert_all",
        "on_update": "myapp.events.global_handler.track_changes",
    }
}

ALWAYS use "*" (string with asterisk) as the key. This fires the handler for every DocType.

Multiple Handlers per Event

doc_events = {
    "Sales Invoice": {
        "on_submit": [
            "myapp.events.accounting.create_gl_entries",
            "myapp.events.notifications.send_invoice_email",
        ]
    }
}

Handler Function Signature

# myapp/events/sales_invoice.py
def on_submit(doc, method=None):
    """
    doc    — the Document instance (e.g., Sales Invoice)
    method — string name of the event (e.g., "on_submit"), or None
    """
    if doc.grand_total > 10000:
        frappe.sendmail(...)

ALWAYS accept method as the second parameter (with default None). Frappe passes it automatically.


Decision Tree: Which Event to Use

"I need to validate data before saving"

→ Use validate. ALWAYS raise frappe.throw() here to block invalid saves.

"I need to set default values automatically"

→ Use before_validate. This runs before validate, so your defaults are set before validation checks.

"I need to run logic only on first creation"

→ Use after_insert. This fires ONLY on insert, NEVER on subsequent saves.

"I need to run logic on every save (insert + update)"

→ Use on_update. This fires on both insert and save operations.

"I need to create linked documents after submit"

→ Use on_submit. NEVER create linked docs in validate — the document is not yet committed.

"I need to reverse linked documents on cancel"

→ Use on_cancel. ALWAYS clean up GL entries, stock ledger entries, and linked docs here.

"I need to modify the document name"

→ Use autoname in the controller, or before_naming for conditional logic.

"I need to prevent deletion under certain conditions"

→ Use on_trash. Raise frappe.throw() to block deletion.

"I need to update a submitted document's fields"

→ Use before_update_after_submit for validation and on_update_after_submit for side effects.

"I need logic that runs only when values actually changed"

→ Use on_change. This fires only when at least one field value differs from the DB state.


doc_events vs Controller Events

Both mechanisms trigger the SAME events. The difference is WHERE you register them.

AspectController (class method)doc_events (hooks.py)
Location{doctype}.py controller filehooks.py in your app
Use whenYou OWN the DocTypeYou are EXTENDING another app's DocType
ExecutionRuns first (controller)Runs after controller method
Multiple appsOnly one controller per DocTypeMultiple apps can register handlers

ALWAYS use doc_events when hooking into a DocType you do NOT own. NEVER modify another app's controller file directly.

Execution Order Within a Single Event

For a given event (e.g., validate):

  1. Controller method runs first (def validate(self))
  2. doc_events handlers run in app installation order
  3. Wildcard "*" handlers run after specific DocType handlers

extend_doctype_class [v16+]

In Frappe v16+, extend_doctype_class provides a cleaner alternative to doc_events for adding methods to existing DocTypes.

hooks.py

extend_doctype_class = {
    "Sales Invoice": [
        "myapp.overrides.sales_invoice.SalesInvoiceExtension"
    ]
}

Extension Class (Mixin)

# myapp/overrides/sales_invoice.py
import frappe

class SalesInvoiceExtension:
    def validate(self):
        """This is called as part of the controller chain."""
        if self.grand_total < 0:
            frappe.throw("Grand total cannot be negative")

    def custom_method(self):
        """Custom methods are also available on the doc instance."""
        return self.items

Key Rules

  • ALWAYS use extend_doctype_class over override_doctype_class in v16+ when multiple apps may extend the same DocType.
  • Multiple apps can extend the same DocType — extensions stack via MRO.
  • Class resolution order follows hooks priority: class Final(App2Mixin, App1Mixin, Original).
  • Extension methods (like validate) run as part of the controller, NOT as separate doc_events handlers.

override_doctype_class [v14+]

Completely replaces the controller class. Use with extreme caution.

# hooks.py
override_doctype_class = {
    "ToDo": "myapp.overrides.todo.CustomToDo"
}
# myapp/overrides/todo.py
from frappe.desk.doctype.todo.todo import ToDo

class CustomToDo(ToDo):
    def validate(self):
        super().validate()  # ALWAYS call super() to preserve original logic
        # Your additions here

NEVER use override_doctype_class if extend_doctype_class is available (v16+). Only ONE app can override a DocType — last-installed app wins, silently breaking other apps.


Multi-App Event Ordering

When multiple apps register doc_events for the same DocType and event:

  1. Handlers execute in app installation order (as listed in sites/{site}/site_config.jsoninstalled_apps).
  2. The order can be changed via Setup > Installed Applications > Update Hooks Resolution Order.
  3. For override_doctype_class, the last-installed app wins (only one override applies).
  4. For extend_doctype_class (v16+), all extensions stack cumulatively.

Transaction Behavior

All document events from before_validate through on_change run inside a single database transaction.

  • If ANY event raises an exception, the ENTIRE operation rolls back (including db_insert/db_update).
  • after_insert, on_update, on_submit, on_cancel — all run BEFORE the transaction commits.
  • The transaction commits only AFTER all events complete successfully.
  • after_delete runs after the DELETE statement but still within the request transaction.

NEVER assume data is committed to DB inside any event handler. Other concurrent requests will NOT see your changes until the full request completes.


Critical Rules

  1. ALWAYS use frappe.throw() to abort operations — NEVER use raise Exception.
  2. NEVER modify doc.name outside of autoname or before_naming.
  3. ALWAYS call super().{event}() when overriding controller methods in subclasses.
  4. NEVER use doc.save() inside validate or before_save — this causes infinite recursion.
  5. ALWAYS use doc.flags.ignore_permissions = True explicitly if your hook needs to bypass permissions — NEVER assume hooks run as Administrator.
  6. NEVER put slow operations (API calls, file I/O) in validate — use after_insert or on_update with frappe.enqueue() instead.
  7. ALWAYS use doc.flags to communicate between events in the same request (e.g., doc.flags.skip_notification = True).
  8. NEVER rely on on_change for critical logic — it only fires when values actually differ from the database state.

See Also

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.84%
按下载量换算70

Claude

28.02%
按下载量换算53

Cursor

21.03%
按下载量换算40

Gemini CLI

8.86%
按下载量换算17

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills