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

erpnext-impl-controllerserpnext impl 控制器

Agent Skill

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

总安装

1,224

周安装

50

GitHub Stars

87

下载量

396
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/openaec-foundation/erpnext_anthropic_claude_development_skill_package --skill erpnext-impl-controllers

简介

指导 DocType 控制器的实现路径,支持外部库导入和复杂事务回滚机制。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中构建高内聚、低耦合的业务逻辑。
  • 强调 validate 与 on_update 的生命周期差异及 self 对象的非持久化特性。
  • 使用前需确认是否允许第三方依赖,避免因包缺失导致部署失败。
  • erpnext-impl-controllers 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

ERPNext Controllers - Implementation

This skill helps you determine HOW to implement server-side DocType logic. For exact syntax, see erpnext-syntax-controllers.

Version: v14/v15/v16 compatible

Main Decision: Controller vs Server Script?

┌───────────────────────────────────────────────────────────────────┐
│ WHAT DO YOU NEED?                                                 │
├───────────────────────────────────────────────────────────────────┤
│                                                                   │
│ ► Import external libraries (requests, pandas, numpy)             │
│   └── Controller ✓                                                │
│                                                                   │
│ ► Complex multi-document transactions with rollback               │
│   └── Controller ✓                                                │
│                                                                   │
│ ► Full Python power (try/except, classes, generators)             │
│   └── Controller ✓                                                │
│                                                                   │
│ ► Extend/override standard ERPNext DocType                        │
│   └── Controller (override_doctype_class in hooks.py)             │
│                                                                   │
│ ► Quick validation without custom app                             │
│   └── Server Script                                               │
│                                                                   │
│ ► Simple auto-fill or calculation                                 │
│   └── Server Script                                               │
│                                                                   │
└───────────────────────────────────────────────────────────────────┘

Rule: Controllers for custom apps with full Python power. Server Scripts for quick no-code solutions.

Decision Tree: Which Hook?

WHAT DO YOU WANT TO DO?
│
├─► Validate data or calculate fields before save?
│   └─► validate
│       NOTE: Changes to self ARE saved
│
├─► Action AFTER save (emails, linked docs, logs)?
│   └─► on_update
│       ⚠️ Changes to self are NOT saved! Use db_set instead
│
├─► Only for NEW documents?
│   └─► after_insert
│
├─► Only for SUBMIT (docstatus 0→1)?
│   ├─► Check before submit? → before_submit
│   └─► Action after submit? → on_submit
│
├─► Only for CANCEL (docstatus 1→2)?
│   ├─► Prevent cancel? → before_cancel
│   └─► Cleanup after cancel? → on_cancel
│
├─► Before DELETE?
│   └─► on_trash
│
├─► Custom document naming?
│   └─► autoname
│
└─► Detect any change (including db_set)?
    └─► on_change

→ See references/decision-tree.md for complete decision tree with all hooks.

CRITICAL: Changes After on_update

┌─────────────────────────────────────────────────────────────────────┐
│ ⚠️  CHANGES TO self AFTER on_update ARE NOT SAVED                  │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│ ❌ WRONG - This does NOTHING:                                       │
│    def on_update(self):                                             │
│        self.status = "Completed"  # NOT SAVED!                      │
│                                                                     │
│ ✅ CORRECT - Use db_set:                                            │
│    def on_update(self):                                             │
│        frappe.db.set_value(self.doctype, self.name,                 │
│                           "status", "Completed")                    │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Hook Comparison: validate vs on_update

Aspectvalidateon_update
WhenBefore DB writeAfter DB write
Changes to self✅ Saved❌ NOT saved
Can throw error✅ Aborts save⚠️ Already saved
Use forValidation, calculationsNotifications, linked docs
get_doc_before_save()✅ Available✅ Available

Common Implementation Patterns

Pattern 1: Validation with Error

def validate(self):
    if not self.items:
        frappe.throw(_("At least one item is required"))

    if self.from_date > self.to_date:
        frappe.throw(_("From Date cannot be after To Date"))

Pattern 2: Auto-Calculate Fields

def validate(self):
    self.total = sum(item.amount for item in self.items)
    self.tax_amount = self.total * 0.1
    self.grand_total = self.total + self.tax_amount

Pattern 3: Detect Field Changes

def validate(self):
    old_doc = self.get_doc_before_save()
    if old_doc and old_doc.status != self.status:
        self.flags.status_changed = True

def on_update(self):
    if self.flags.get('status_changed'):
        self.notify_status_change()

Pattern 4: Post-Save Actions

def on_update(self):
    # Update linked document
    if self.linked_doc:
        frappe.db.set_value("Other DocType", self.linked_doc,
                          "status", "Updated")

    # Send notification (never fails the save)
    try:
        self.send_notification()
    except Exception:
        frappe.log_error("Notification failed")

Pattern 5: Custom Naming

from frappe.model.naming import getseries

def autoname(self):
    # Format: CUST-ABC-001
    prefix = f"CUST-{self.customer[:3].upper()}-"
    self.name = getseries(prefix, 3)

→ See references/workflows.md for more implementation patterns.

Submittable Documents Workflow

DRAFT (docstatus=0)
    │
    ├── save() → validate → on_update
    │
    └── submit()
         │
         ├── validate
         ├── before_submit  ← Last chance to abort
         ├── [DB: docstatus=1]
         ├── on_update
         └── on_submit      ← Post-submit actions

SUBMITTED (docstatus=1)
    │
    └── cancel()
         │
         ├── before_cancel  ← Last chance to abort
         ├── [DB: docstatus=2]
         ├── on_cancel      ← Reverse actions
         └── [check_no_back_links]

Submittable Implementation

def before_submit(self):
    # Validation that only applies on submit
    if self.total > 50000 and not self.manager_approval:
        frappe.throw(_("Manager approval required for orders over 50,000"))

def on_submit(self):
    # Actions after submit
    self.update_stock_ledger()
    self.make_gl_entries()

def before_cancel(self):
    # Prevent cancel if linked docs exist
    if self.has_linked_invoices():
        frappe.throw(_("Cannot cancel - linked invoices exist"))

def on_cancel(self):
    # Reverse submitted actions
    self.reverse_stock_ledger()
    self.reverse_gl_entries()

Controller Override (hooks.py)

Method 1: Full Override

# hooks.py
override_doctype_class = {
    "Sales Invoice": "myapp.overrides.CustomSalesInvoice"
}

# myapp/overrides.py
from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice

class CustomSalesInvoice(SalesInvoice):
    def validate(self):
        super().validate()  # ALWAYS call parent
        self.custom_validation()

Method 2: Add Event Handler (Safer)

# hooks.py
doc_events = {
    "Sales Invoice": {
        "validate": "myapp.events.validate_sales_invoice",
    }
}

# myapp/events.py
def validate_sales_invoice(doc, method=None):
    if doc.grand_total < 0:
        frappe.throw(_("Invalid total"))

V16: extend_doctype_class (New)

# hooks.py (v16+)
extend_doctype_class = {
    "Sales Invoice": "myapp.extends.SalesInvoiceExtend"
}

# myapp/extends.py - Only methods to add/override
class SalesInvoiceExtend:
    def custom_method(self):
        pass

Flags System

# Document-level flags
doc.flags.ignore_permissions = True   # Bypass permissions
doc.flags.ignore_validate = True      # Skip validate()
doc.flags.ignore_mandatory = True     # Skip required fields

# Custom flags for inter-hook communication
def validate(self):
    if self.is_urgent:
        self.flags.needs_notification = True

def on_update(self):
    if self.flags.get('needs_notification'):
        self.notify_team()

# Insert/save with flags
doc.insert(ignore_permissions=True, ignore_mandatory=True)
doc.save(ignore_permissions=True)

Execution Order Reference

INSERT (New Document)

before_insert → before_naming → autoname → before_validate →
validate → before_save → [DB INSERT] → after_insert →
on_update → on_change

SAVE (Existing Document)

before_validate → validate → before_save → [DB UPDATE] →
on_update → on_change

SUBMIT

validate → before_submit → [DB: docstatus=1] → on_update →
on_submit → on_change

→ See references/decision-tree.md for all execution orders.

Quick Anti-Pattern Check

❌ Don't✅ Do Instead
self.x = y in on_updatefrappe.db.set_value(...)
frappe.db.commit() in hooksLet framework handle commits
Heavy operations in validateUse frappe.enqueue() in on_update
self.save() in on_updateCauses infinite loop!
Assume hook order across docsEach doc has its own cycle

→ See references/anti-patterns.md for complete list.

References

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

35.33%
按下载量换算140

Claude

27.52%
按下载量换算109

Cursor

18.66%
按下载量换算74

Gemini CLI

9.7%
按下载量换算38

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

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

安装前确认

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

来源信息

继续浏览同类 Skills