---
name: kd-enterprise-python-plugin
description: >
  在已有金蝶AI星空企业版/标准版 BOS 脚本挂载点中实现或修改 IronPython 插件。
  Use when: 用户明确要求 Python/IronPython/BOS 脚本插件（表单列表操作转换报表套打排序等）。
  Do not use when: 默认企业版 C#、Cosmic Java、空目录建工程、与 BOS 无关的 CPython 项目。
---

# 企业版 IronPython 插件

默认企业版插件是 **C#**（`kd-enterprise-csharp`）。仅当用户**明确**要 Python/IronPython 时用本 skill。

## 形态硬事实（勿答错）

| 项 | 事实 |
|----|------|
| 默认语言 | **C#**，不是 Python |
| BOS 表单/列表/操作 **脚本插件** | **裸函数事件**（如 `def AfterBindData(e):`），**不是** `class Xxx(AbstractBillPlugIn)` |
| 导入 | `clr.AddReference` + `from Kingdee.BOS...` |
| 与 C# 插件区别 | C# 才是继承 `Abstract*PlugIn` 的 class；IPY 脚本挂载点是函数 |

运行时：IronPython on CLR（常见 2.7 兼容；勿默认 CPython 3.10+）。  
**认脚本路径 / 工程挂载点，再写代码**；不做空目录脚手架。


## When / Do not

**Use when**

- 明确 IronPython / BOS Python 脚本
- 能定位**真实脚本路径**或 BOS 已挂载的 `.py` 位置
- 套打排序 `OnPrepareNotePrintData` 等

**Do not use when**

- 未指定语言的企业版插件 → `kd-enterprise-csharp`
- Cosmic Java → `ok-cosmic`
- **空目录且无脚本挂载点**：先让用户在 BOS/工程中建好脚本入口，再写逻辑
- 普通 CPython 应用（非 BOS 脚本）

## 结构识别（编码前）

| 信号 | 动作 |
|------|------|
| 已有 `.py` 插件脚本 / 用户给出 BOS 脚本路径 | 在该路径改/增事件函数 |
| 仅有 C# 插件工程、无 Python 路径 | 确认用户是否真要 Python；否则转 C# skill |
| 空目录 | **停写**；说明需先有挂载点 |

## Input / Output

**Input**

| 字段 | 说明 |
|------|------|
| scriptPath | 真实脚本路径（必填或先查清） |
| pluginType | form/list/operation/convert/report/print-sort… |
| formId / fields / entity | 已验证 |
| events | AfterBindData / DataChanged / BeforeF7Select / *Operation* / OnPrepareNotePrintData… |
| print | 套打时 NotePrintTplId、DataSourceId |

**Output**

| 字段 | 说明 |
|------|------|
| files | `.py` 路径 |
| registration | BOS 注册 |
| facts | 已确认标识 |
| verify | 数据中心验证步骤 |

## Steps

```
- [ ] 1. plan：定位真实脚本路径；无路径则停；execute 前不写 .py
- [ ] 2. 确认类型/事件/FormId/字段；套打补 NotePrintTplId、DataSourceId
- [ ] 3. 读 assets 骨架：裸函数，无 class/self 插件壳
- [ ] 4. 必读 skills/_shared/three-identifiers.md：按 API 选标识/字段名/实体属性名
- [ ] 5. 编码：from Kingdee.BOS…；表单可用 this.View；操作/报表/转换无 View 假设
- [ ] 6. 禁止：循环查库、拼接 SQL、空 except、print 当业务日志、CPython3-only 语法、三标识混用
- [ ] 7. verify：注册点 + 数据中心操作路径验证（不以 py_compile 为交付门禁）
```

**失败策略**

| 失败 | 动作 |
|------|------|
| 用户未明确 Python | 改走 C# skill 或询问语言 |
| 无脚本路径 | 停止；先确定 BOS 挂载点 |
| 字段/模板 ID 不明 | 不写死字面量；先查证 |
| 不知标识 vs 库列 vs 实体属性 | **停写**；读 `skills/_shared/three-identifiers.md` |
| 脚本宿主语法错误 | 去掉 3.10+ 语法，按 IPY 能力改写 |
| 误用 Cosmic API | 全部改为 Kingdee.BOS.* |

## 资产

| 手册 | 骨架 |
|------|------|
| [FormPlugin.md](assets/FormPlugin.md) | [FormPluginTemplate.py](assets/FormPluginTemplate.py) |
| [ListPlugin.md](assets/ListPlugin.md) | [ListPluginTemplate.py](assets/ListPluginTemplate.py) |
| [OperationServicePlugin.md](assets/OperationServicePlugin.md) | [OperationServicePluginTemplate.py](assets/OperationServicePluginTemplate.py) |
| [ConvertPlugin.md](assets/ConvertPlugin.md) | [ConvertPluginTemplate.py](assets/ConvertPluginTemplate.py) |
| [ReportFormPlugin.md](assets/ReportFormPlugin.md) | [ReportFormPluginTemplate.py](assets/ReportFormPluginTemplate.py) |
| [ReportServicePlugin.md](assets/ReportServicePlugin.md) | [ReportServicePluginTemplate.py](assets/ReportServicePluginTemplate.py) |
| [PrintSortPlugin.md](assets/PrintSortPlugin.md) | [PrintSortPlugin.py](assets/PrintSortPlugin.py) |
| [UtilityCodeSnippets.md](assets/UtilityCodeSnippets.md) | — |

**必读**：[三标识决策卡](../_shared/three-identifiers.md)

## BOS 规则

- **默认形态：裸函数事件**（禁止默认答成 C# 式 class 继承 AbstractBillPlugIn）
- 表单/列表：`this.View.ShowMessage` / `ShowWarnningMessage`
- 服务/转换：`raise Exception(...)` 或平台约定
- `Kingdee.BOS.*` only
- **三标识**：View/FieldKey → Key；billObj → PropertyName（元数据）；SQL → FieldName。见 `skills/_shared/three-identifiers.md`





## 渐进披露

| 需要时 | 文件 |
|--------|------|
| **三标识何时用哪个** | [../_shared/three-identifiers.md](../_shared/three-identifiers.md) |
| Python 语言层（已裁 CPython 冲突） | [references/lang-python/python.md](references/lang-python/python.md) |
| 企业版主题 rules | `kd-enterprise-index` |

语言包**不是** CPython 应用指南；禁止按 3.10+/pytest/uv 生成 BOS 脚本。

## 验证

- 脚本路径已确认；`.py` 路径、注册、已确认事实、数据中心验证步骤与结果
