erpnext-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- erpnext_mcp-0.1.0/.env.example +3 -0
- erpnext_mcp-0.1.0/.github/workflows/publish.yml +24 -0
- erpnext_mcp-0.1.0/.gitignore +21 -0
- erpnext_mcp-0.1.0/CLAUDE.md +23 -0
- erpnext_mcp-0.1.0/LICENSE +21 -0
- erpnext_mcp-0.1.0/PKG-INFO +146 -0
- erpnext_mcp-0.1.0/README.md +99 -0
- erpnext_mcp-0.1.0/docs/api-reference.md +303 -0
- erpnext_mcp-0.1.0/docs/development-notes.md +154 -0
- erpnext_mcp-0.1.0/docs/testing.md +106 -0
- erpnext_mcp-0.1.0/mcp.json.example +13 -0
- erpnext_mcp-0.1.0/pyproject.toml +49 -0
- erpnext_mcp-0.1.0/src/erpnext_mcp/__init__.py +0 -0
- erpnext_mcp-0.1.0/src/erpnext_mcp/client.py +209 -0
- erpnext_mcp-0.1.0/src/erpnext_mcp/server.py +318 -0
- erpnext_mcp-0.1.0/src/erpnext_mcp/types.py +25 -0
- erpnext_mcp-0.1.0/tests/__init__.py +0 -0
- erpnext_mcp-0.1.0/tests/test_integration.py +490 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
id-token: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
environment: pypi
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Install uv
|
|
18
|
+
uses: astral-sh/setup-uv@v4
|
|
19
|
+
|
|
20
|
+
- name: Build package
|
|
21
|
+
run: uv build
|
|
22
|
+
|
|
23
|
+
- name: Publish to PyPI
|
|
24
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# ERPNext MCP Server
|
|
2
|
+
|
|
3
|
+
## Run
|
|
4
|
+
```bash
|
|
5
|
+
cd /home/ct/SDD/erpnext-mcp
|
|
6
|
+
set -a && source .env && set +a && uv run erpnext-mcp
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Structure
|
|
10
|
+
- `src/erpnext_mcp/server.py` - MCP tool definitions (fastmcp)
|
|
11
|
+
- `src/erpnext_mcp/client.py` - ERPNext REST API client (httpx async)
|
|
12
|
+
- `src/erpnext_mcp/types.py` - Pydantic models
|
|
13
|
+
|
|
14
|
+
## Auth
|
|
15
|
+
Uses `Authorization: token {api_key}:{api_secret}` header. Set `ERPNEXT_API_KEY` and `ERPNEXT_API_SECRET` in `.env`.
|
|
16
|
+
|
|
17
|
+
## Docs
|
|
18
|
+
- `docs/api-reference.md` - 19 個 MCP tool 的參數、型別與範例
|
|
19
|
+
- `docs/testing.md` - 整合測試說明(43 項測試、執行方式、Phase 結構)
|
|
20
|
+
- `docs/development-notes.md` - 開發記錄(問題與解決方案、環境資訊)
|
|
21
|
+
|
|
22
|
+
## Adding Tools
|
|
23
|
+
Add `@mcp.tool()` decorated async functions in `server.py`. Use `get_client()` for API calls. Filter/data params accept JSON strings to stay MCP-compatible.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ching-Tech
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: erpnext-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP Server for ERPNext REST API
|
|
5
|
+
Project-URL: Homepage, https://github.com/ching-tech/erpnext-mcp
|
|
6
|
+
Project-URL: Repository, https://github.com/ching-tech/erpnext-mcp
|
|
7
|
+
Project-URL: Issues, https://github.com/ching-tech/erpnext-mcp/issues
|
|
8
|
+
Author: Ching-Tech
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2025 Ching-Tech
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: api,erp,erpnext,frappe,mcp
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
39
|
+
Classifier: Topic :: Office/Business
|
|
40
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
41
|
+
Requires-Python: >=3.11
|
|
42
|
+
Requires-Dist: fastmcp>=2.0.0
|
|
43
|
+
Requires-Dist: httpx>=0.27.0
|
|
44
|
+
Requires-Dist: pydantic>=2.0.0
|
|
45
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
|
|
48
|
+
# ERPNext MCP Server
|
|
49
|
+
|
|
50
|
+
MCP (Model Context Protocol) server for ERPNext REST API, built with [FastMCP](https://github.com/jlowin/fastmcp) and Python.
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
- **CRUD** — List, get, create, update, delete documents
|
|
55
|
+
- **Workflow** — Submit and cancel submittable documents
|
|
56
|
+
- **Reports** — Run ERPNext query reports
|
|
57
|
+
- **Schema** — Inspect DocType field definitions, list all DocTypes
|
|
58
|
+
- **Inventory** — Stock balance, stock ledger, item prices
|
|
59
|
+
- **Trading** — Document conversion (e.g. Quotation → Sales Order), party balance
|
|
60
|
+
- **Helpers** — Link search (autocomplete), document count, generic method calls
|
|
61
|
+
|
|
62
|
+
## Requirements
|
|
63
|
+
|
|
64
|
+
- Python >= 3.11
|
|
65
|
+
- [uv](https://docs.astral.sh/uv/) (recommended) or pip
|
|
66
|
+
- ERPNext instance with API key/secret
|
|
67
|
+
|
|
68
|
+
## Setup
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# Clone the repo
|
|
72
|
+
git clone <repo-url> && cd erpnext-mcp
|
|
73
|
+
|
|
74
|
+
# Create .env file
|
|
75
|
+
cat > .env << 'EOF'
|
|
76
|
+
ERPNEXT_URL=https://your-erpnext-instance.com
|
|
77
|
+
ERPNEXT_API_KEY=your_api_key
|
|
78
|
+
ERPNEXT_API_SECRET=your_api_secret
|
|
79
|
+
EOF
|
|
80
|
+
|
|
81
|
+
# Install dependencies
|
|
82
|
+
uv sync
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Run
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
set -a && source .env && set +a && uv run erpnext-mcp
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Available Tools
|
|
92
|
+
|
|
93
|
+
| Tool | Description |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `list_documents` | List documents with filters, sorting, pagination |
|
|
96
|
+
| `get_document` | Get a single document by name |
|
|
97
|
+
| `create_document` | Create a new document |
|
|
98
|
+
| `update_document` | Update an existing document |
|
|
99
|
+
| `delete_document` | Delete a document |
|
|
100
|
+
| `submit_document` | Submit a submittable document |
|
|
101
|
+
| `cancel_document` | Cancel a submitted document |
|
|
102
|
+
| `run_report` | Execute an ERPNext report |
|
|
103
|
+
| `get_count` | Get document count with optional filters |
|
|
104
|
+
| `get_list_with_summary` | List documents with total count |
|
|
105
|
+
| `run_method` | Call any whitelisted server-side method |
|
|
106
|
+
| `search_link` | Link field autocomplete search |
|
|
107
|
+
| `list_doctypes` | List all available DocType names |
|
|
108
|
+
| `get_doctype_meta` | Get field definitions for a DocType |
|
|
109
|
+
| `get_stock_balance` | Real-time stock balance from Bin |
|
|
110
|
+
| `get_stock_ledger` | Stock ledger entries (inventory history) |
|
|
111
|
+
| `get_item_price` | Item prices from price lists |
|
|
112
|
+
| `make_mapped_doc` | Document conversion (e.g. SO → DN) |
|
|
113
|
+
| `get_party_balance` | Outstanding balance for Customer/Supplier |
|
|
114
|
+
|
|
115
|
+
## MCP Client Configuration
|
|
116
|
+
|
|
117
|
+
Add to your MCP client config (e.g. Claude Desktop `claude_desktop_config.json`):
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"mcpServers": {
|
|
122
|
+
"erpnext": {
|
|
123
|
+
"command": "uv",
|
|
124
|
+
"args": ["--directory", "/path/to/erpnext-mcp", "run", "erpnext-mcp"],
|
|
125
|
+
"env": {
|
|
126
|
+
"ERPNEXT_URL": "https://your-erpnext-instance.com",
|
|
127
|
+
"ERPNEXT_API_KEY": "your_api_key",
|
|
128
|
+
"ERPNEXT_API_SECRET": "your_api_secret"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Project Structure
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
src/erpnext_mcp/
|
|
139
|
+
├── server.py # MCP tool definitions (FastMCP)
|
|
140
|
+
├── client.py # ERPNext REST API client (httpx async)
|
|
141
|
+
└── types.py # Pydantic models
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# ERPNext MCP Server
|
|
2
|
+
|
|
3
|
+
MCP (Model Context Protocol) server for ERPNext REST API, built with [FastMCP](https://github.com/jlowin/fastmcp) and Python.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **CRUD** — List, get, create, update, delete documents
|
|
8
|
+
- **Workflow** — Submit and cancel submittable documents
|
|
9
|
+
- **Reports** — Run ERPNext query reports
|
|
10
|
+
- **Schema** — Inspect DocType field definitions, list all DocTypes
|
|
11
|
+
- **Inventory** — Stock balance, stock ledger, item prices
|
|
12
|
+
- **Trading** — Document conversion (e.g. Quotation → Sales Order), party balance
|
|
13
|
+
- **Helpers** — Link search (autocomplete), document count, generic method calls
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- Python >= 3.11
|
|
18
|
+
- [uv](https://docs.astral.sh/uv/) (recommended) or pip
|
|
19
|
+
- ERPNext instance with API key/secret
|
|
20
|
+
|
|
21
|
+
## Setup
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Clone the repo
|
|
25
|
+
git clone <repo-url> && cd erpnext-mcp
|
|
26
|
+
|
|
27
|
+
# Create .env file
|
|
28
|
+
cat > .env << 'EOF'
|
|
29
|
+
ERPNEXT_URL=https://your-erpnext-instance.com
|
|
30
|
+
ERPNEXT_API_KEY=your_api_key
|
|
31
|
+
ERPNEXT_API_SECRET=your_api_secret
|
|
32
|
+
EOF
|
|
33
|
+
|
|
34
|
+
# Install dependencies
|
|
35
|
+
uv sync
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Run
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
set -a && source .env && set +a && uv run erpnext-mcp
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Available Tools
|
|
45
|
+
|
|
46
|
+
| Tool | Description |
|
|
47
|
+
|---|---|
|
|
48
|
+
| `list_documents` | List documents with filters, sorting, pagination |
|
|
49
|
+
| `get_document` | Get a single document by name |
|
|
50
|
+
| `create_document` | Create a new document |
|
|
51
|
+
| `update_document` | Update an existing document |
|
|
52
|
+
| `delete_document` | Delete a document |
|
|
53
|
+
| `submit_document` | Submit a submittable document |
|
|
54
|
+
| `cancel_document` | Cancel a submitted document |
|
|
55
|
+
| `run_report` | Execute an ERPNext report |
|
|
56
|
+
| `get_count` | Get document count with optional filters |
|
|
57
|
+
| `get_list_with_summary` | List documents with total count |
|
|
58
|
+
| `run_method` | Call any whitelisted server-side method |
|
|
59
|
+
| `search_link` | Link field autocomplete search |
|
|
60
|
+
| `list_doctypes` | List all available DocType names |
|
|
61
|
+
| `get_doctype_meta` | Get field definitions for a DocType |
|
|
62
|
+
| `get_stock_balance` | Real-time stock balance from Bin |
|
|
63
|
+
| `get_stock_ledger` | Stock ledger entries (inventory history) |
|
|
64
|
+
| `get_item_price` | Item prices from price lists |
|
|
65
|
+
| `make_mapped_doc` | Document conversion (e.g. SO → DN) |
|
|
66
|
+
| `get_party_balance` | Outstanding balance for Customer/Supplier |
|
|
67
|
+
|
|
68
|
+
## MCP Client Configuration
|
|
69
|
+
|
|
70
|
+
Add to your MCP client config (e.g. Claude Desktop `claude_desktop_config.json`):
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"mcpServers": {
|
|
75
|
+
"erpnext": {
|
|
76
|
+
"command": "uv",
|
|
77
|
+
"args": ["--directory", "/path/to/erpnext-mcp", "run", "erpnext-mcp"],
|
|
78
|
+
"env": {
|
|
79
|
+
"ERPNEXT_URL": "https://your-erpnext-instance.com",
|
|
80
|
+
"ERPNEXT_API_KEY": "your_api_key",
|
|
81
|
+
"ERPNEXT_API_SECRET": "your_api_secret"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Project Structure
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
src/erpnext_mcp/
|
|
92
|
+
├── server.py # MCP tool definitions (FastMCP)
|
|
93
|
+
├── client.py # ERPNext REST API client (httpx async)
|
|
94
|
+
└── types.py # Pydantic models
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# MCP Tool API 參考
|
|
2
|
+
|
|
3
|
+
ERPNext MCP Server 提供 19 個工具,分為 CRUD、報表、工作流、輔助、庫存交易五大類。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## CRUD
|
|
8
|
+
|
|
9
|
+
### list_documents
|
|
10
|
+
|
|
11
|
+
列出指定 DocType 的文件清單。
|
|
12
|
+
|
|
13
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
14
|
+
|------|------|------|------|
|
|
15
|
+
| doctype | str | Y | DocType 名稱,如 `"Sales Order"` |
|
|
16
|
+
| fields | list[str] | N | 回傳欄位,預設 `["name"]` |
|
|
17
|
+
| filters | str | N | JSON 篩選條件,如 `'{"status": "Open"}'` 或 `'[["status","=","Open"]]'` |
|
|
18
|
+
| or_filters | str | N | JSON OR 篩選條件 |
|
|
19
|
+
| order_by | str | N | 排序,如 `"creation desc"` |
|
|
20
|
+
| limit_start | int | N | 分頁起始(預設 0) |
|
|
21
|
+
| limit_page_length | int | N | 回傳筆數(預設 20,最大 100) |
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
// 範例
|
|
25
|
+
{"doctype": "Customer", "fields": ["name", "customer_name"], "filters": "{\"customer_type\": \"Individual\"}", "limit_page_length": 10}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### get_document
|
|
31
|
+
|
|
32
|
+
取得單一文件。
|
|
33
|
+
|
|
34
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
35
|
+
|------|------|------|------|
|
|
36
|
+
| doctype | str | Y | DocType 名稱 |
|
|
37
|
+
| name | str | Y | 文件名稱/ID |
|
|
38
|
+
| fields | list[str] | N | 指定回傳欄位 |
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{"doctype": "Sales Order", "name": "SO-00001", "fields": ["name", "status", "grand_total"]}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### create_document
|
|
47
|
+
|
|
48
|
+
建立新文件。
|
|
49
|
+
|
|
50
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
51
|
+
|------|------|------|------|
|
|
52
|
+
| doctype | str | Y | DocType 名稱 |
|
|
53
|
+
| data | str | Y | JSON 字串,欄位值 |
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{"doctype": "Customer", "data": "{\"customer_name\": \"Test Customer\", \"customer_type\": \"Individual\", \"customer_group\": \"All Customer Groups\", \"territory\": \"All Territories\"}"}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
含子表(child table)範例:
|
|
60
|
+
```json
|
|
61
|
+
{"doctype": "Sales Order", "data": "{\"customer\": \"CUST-001\", \"company\": \"My Company\", \"delivery_date\": \"2025-12-31\", \"items\": [{\"item_code\": \"ITEM-001\", \"qty\": 10, \"rate\": 100}]}"}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### update_document
|
|
67
|
+
|
|
68
|
+
更新現有文件。
|
|
69
|
+
|
|
70
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
71
|
+
|------|------|------|------|
|
|
72
|
+
| doctype | str | Y | DocType 名稱 |
|
|
73
|
+
| name | str | Y | 文件名稱/ID |
|
|
74
|
+
| data | str | Y | JSON 字串,要更新的欄位 |
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{"doctype": "Sales Order", "name": "SO-00001", "data": "{\"delivery_date\": \"2025-12-31\"}"}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
### delete_document
|
|
83
|
+
|
|
84
|
+
刪除文件。
|
|
85
|
+
|
|
86
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
87
|
+
|------|------|------|------|
|
|
88
|
+
| doctype | str | Y | DocType 名稱 |
|
|
89
|
+
| name | str | Y | 文件名稱/ID |
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{"doctype": "Customer", "name": "CUST-001"}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 報表
|
|
98
|
+
|
|
99
|
+
### run_report
|
|
100
|
+
|
|
101
|
+
執行 ERPNext 報表。
|
|
102
|
+
|
|
103
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
104
|
+
|------|------|------|------|
|
|
105
|
+
| report_name | str | Y | 報表名稱,如 `"Stock Balance"` |
|
|
106
|
+
| filters | str | N | JSON 篩選條件 |
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{"report_name": "Stock Balance", "filters": "{\"company\": \"擎添工業有限公司\"}"}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
### get_count
|
|
115
|
+
|
|
116
|
+
取得文件計數。
|
|
117
|
+
|
|
118
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
119
|
+
|------|------|------|------|
|
|
120
|
+
| doctype | str | Y | DocType 名稱 |
|
|
121
|
+
| filters | str | N | JSON 篩選條件 |
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{"doctype": "Sales Invoice", "filters": "{\"status\": \"Unpaid\"}"}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### get_list_with_summary
|
|
130
|
+
|
|
131
|
+
列出文件並附帶總筆數。
|
|
132
|
+
|
|
133
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
134
|
+
|------|------|------|------|
|
|
135
|
+
| doctype | str | Y | DocType 名稱 |
|
|
136
|
+
| fields | list[str] | N | 回傳欄位 |
|
|
137
|
+
| filters | str | N | JSON 篩選條件 |
|
|
138
|
+
| order_by | str | N | 排序 |
|
|
139
|
+
| limit_page_length | int | N | 回傳筆數(預設 20) |
|
|
140
|
+
|
|
141
|
+
回傳格式:`{"data": [...], "total_count": 123}`
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 工作流
|
|
146
|
+
|
|
147
|
+
### submit_document
|
|
148
|
+
|
|
149
|
+
提交可提交的文件(docstatus 0→1)。
|
|
150
|
+
|
|
151
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
152
|
+
|------|------|------|------|
|
|
153
|
+
| doctype | str | Y | DocType 名稱 |
|
|
154
|
+
| name | str | Y | 文件名稱/ID |
|
|
155
|
+
|
|
156
|
+
```json
|
|
157
|
+
{"doctype": "Sales Invoice", "name": "SINV-00001"}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### cancel_document
|
|
163
|
+
|
|
164
|
+
取消已提交的文件(docstatus 1→2)。
|
|
165
|
+
|
|
166
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
167
|
+
|------|------|------|------|
|
|
168
|
+
| doctype | str | Y | DocType 名稱 |
|
|
169
|
+
| name | str | Y | 文件名稱/ID |
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
### run_method
|
|
174
|
+
|
|
175
|
+
呼叫 ERPNext 白名單方法。
|
|
176
|
+
|
|
177
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
178
|
+
|------|------|------|------|
|
|
179
|
+
| method | str | Y | 方法路徑,如 `"frappe.client.get_count"` |
|
|
180
|
+
| http_method | str | N | `"GET"` 或 `"POST"`(預設 POST) |
|
|
181
|
+
| args | str | N | JSON 字串,關鍵字參數 |
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{"method": "frappe.client.get_count", "http_method": "GET", "args": "{\"doctype\": \"Customer\"}"}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## 輔助
|
|
190
|
+
|
|
191
|
+
### list_doctypes
|
|
192
|
+
|
|
193
|
+
列出可用的 DocType 名稱。
|
|
194
|
+
|
|
195
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
196
|
+
|------|------|------|------|
|
|
197
|
+
| module | str | N | 模組篩選,如 `"Selling"`, `"Stock"`, `"Accounts"` |
|
|
198
|
+
| is_submittable | bool | N | 只列出可提交的 DocType |
|
|
199
|
+
| limit | int | N | 最大筆數(預設 100) |
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
### search_link
|
|
204
|
+
|
|
205
|
+
連結欄位搜尋(自動完成)。
|
|
206
|
+
|
|
207
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
208
|
+
|------|------|------|------|
|
|
209
|
+
| doctype | str | Y | 目標 DocType |
|
|
210
|
+
| txt | str | Y | 搜尋文字 |
|
|
211
|
+
| filters | str | N | JSON 篩選條件 |
|
|
212
|
+
| page_length | int | N | 最大筆數(預設 20) |
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
### get_doctype_meta
|
|
217
|
+
|
|
218
|
+
取得 DocType 的欄位定義。
|
|
219
|
+
|
|
220
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
221
|
+
|------|------|------|------|
|
|
222
|
+
| doctype | str | Y | DocType 名稱 |
|
|
223
|
+
|
|
224
|
+
回傳欄位:`fieldname`, `fieldtype`, `label`, `reqd`, `options`
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 庫存與交易
|
|
229
|
+
|
|
230
|
+
### get_stock_balance
|
|
231
|
+
|
|
232
|
+
從 Bin 表取得即時庫存餘額。
|
|
233
|
+
|
|
234
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
235
|
+
|------|------|------|------|
|
|
236
|
+
| item_code | str | N | 品項代碼 |
|
|
237
|
+
| warehouse | str | N | 倉庫 |
|
|
238
|
+
|
|
239
|
+
回傳欄位:`item_code`, `warehouse`, `actual_qty`, `reserved_qty`, `ordered_qty`, `projected_qty`
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
### get_item_price
|
|
244
|
+
|
|
245
|
+
查詢品項價格。
|
|
246
|
+
|
|
247
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
248
|
+
|------|------|------|------|
|
|
249
|
+
| item_code | str | Y | 品項代碼 |
|
|
250
|
+
| price_list | str | N | 價格表名稱,如 `"Standard Selling"` |
|
|
251
|
+
|
|
252
|
+
回傳欄位:`item_code`, `price_list`, `price_list_rate`, `currency`, `uom`
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
### make_mapped_doc
|
|
257
|
+
|
|
258
|
+
從現有文件轉換建立新文件(文件轉換)。
|
|
259
|
+
|
|
260
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
261
|
+
|------|------|------|------|
|
|
262
|
+
| method | str | Y | 轉換方法路徑 |
|
|
263
|
+
| source_name | str | Y | 來源文件名稱/ID |
|
|
264
|
+
|
|
265
|
+
常用轉換方法:
|
|
266
|
+
|
|
267
|
+
| 方法 | 轉換 |
|
|
268
|
+
|------|------|
|
|
269
|
+
| `erpnext.selling.doctype.quotation.quotation.make_sales_order` | 報價單 → 銷售單 |
|
|
270
|
+
| `erpnext.selling.doctype.sales_order.sales_order.make_delivery_note` | 銷售單 → 出貨單 |
|
|
271
|
+
| `erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice` | 銷售單 → 銷售發票 |
|
|
272
|
+
| `erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice` | 出貨單 → 銷售發票 |
|
|
273
|
+
| `erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receipt` | 採購單 → 入庫單 |
|
|
274
|
+
| `erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_invoice` | 採購單 → 採購發票 |
|
|
275
|
+
|
|
276
|
+
回傳 draft 文件 JSON,可修改後用 `create_document` 建立再 `submit_document` 提交。
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
### get_party_balance
|
|
281
|
+
|
|
282
|
+
查詢客戶或供應商的未結餘額。
|
|
283
|
+
|
|
284
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
285
|
+
|------|------|------|------|
|
|
286
|
+
| party_type | str | Y | `"Customer"` 或 `"Supplier"` |
|
|
287
|
+
| party | str | Y | 對象名稱/ID |
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
### get_stock_ledger
|
|
292
|
+
|
|
293
|
+
查詢庫存異動記錄。
|
|
294
|
+
|
|
295
|
+
| 參數 | 型別 | 必填 | 說明 |
|
|
296
|
+
|------|------|------|------|
|
|
297
|
+
| item_code | str | N | 品項代碼 |
|
|
298
|
+
| warehouse | str | N | 倉庫 |
|
|
299
|
+
| limit | int | N | 最大筆數(預設 50) |
|
|
300
|
+
|
|
301
|
+
回傳欄位:`item_code`, `warehouse`, `posting_date`, `qty_after_transaction`, `actual_qty`, `voucher_type`, `voucher_no`
|
|
302
|
+
|
|
303
|
+
結果按 `posting_date desc, posting_time desc` 排序。
|