elc-invoice-engine-cli 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,383 @@
1
+ Metadata-Version: 2.4
2
+ Name: elc-invoice-engine-cli
3
+ Version: 0.1.0
4
+ Summary: CLI client for ELC Invoice Engine V2 API
5
+ License-Expression: MIT
6
+ Keywords: invoice,elc,cli,kingdee
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Environment :: Console
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: typer==0.9.4
16
+ Requires-Dist: click==8.1.7
17
+ Requires-Dist: httpx==0.27.0
18
+ Requires-Dist: python-dotenv==1.0.1
19
+ Requires-Dist: rich==13.7.1
20
+ Requires-Dist: lxml==5.3.0
21
+ Requires-Dist: openpyxl==3.1.5
22
+
23
+ # elc-invoice-engine-cli
24
+
25
+ ELC Invoice Engine V2 接口命令行工具。基于 Python + Typer 构建,支持开票申请单、发票、交易方、商品、税目、汇率等全套 V2 接口操作。
26
+
27
+ ## 前置要求
28
+
29
+ - Python 3.10+(推荐通过 [Homebrew](https://brew.sh) 安装:`brew install python@3.10`)
30
+ - 可访问的 ELC Invoice Engine V2 服务
31
+
32
+ ---
33
+
34
+ ## 安装
35
+
36
+ ```bash
37
+ # 1. 进入项目目录
38
+ cd elc-invoice-engine-cli
39
+
40
+ # 2. 创建虚拟环境
41
+ python3 -m venv .venv
42
+ source .venv/bin/activate # macOS / Linux
43
+ # .venv\Scripts\activate # Windows
44
+
45
+ # 3. 安装(可编辑模式,`elc` 命令立即可用)
46
+ pip install -e .
47
+ ```
48
+
49
+ 安装完成后,`elc` 命令即挂载到当前虚拟环境:
50
+
51
+ ```bash
52
+ elc --help
53
+ ```
54
+
55
+ ---
56
+
57
+ ## 配置与登录
58
+
59
+ ### 方式一:交互式登录(推荐)
60
+
61
+ ```bash
62
+ elc login
63
+ ```
64
+
65
+ 按提示依次输入租户域名、应用 ID、密钥、手机号、组织编号。
66
+ Token 保存到 `~/.elc/token.json`,有效期内无需重复登录。
67
+
68
+ 也可以通过选项直接传入,跳过交互:
69
+
70
+ ```bash
71
+ elc login \
72
+ --domain kingdee-fpy \
73
+ --app-id your_app_id \
74
+ --secret your_secret \
75
+ --mobile 138xxxx \
76
+ --org-num HXB-10151 \
77
+ --url http://localhost:12007/xm-demo
78
+ ```
79
+
80
+ ### 方式二:.env.local 文件(适合 CI / 脚本)
81
+
82
+ ```bash
83
+ cp .env.example .env.local
84
+ # 然后编辑 .env.local 填写以下字段
85
+ ```
86
+
87
+ | 字段 | 说明 |
88
+ |------|------|
89
+ | `BASE_URL` | 服务地址,如 `http://localhost:12007/xm-demo` |
90
+ | `SSO_APP_ID` | 应用 ID |
91
+ | `SSO_SECRET` | 应用密钥 |
92
+ | `SSO_DOMAIN` | 租户域名 |
93
+ | `SSO_MOBILE` | 登录手机号 |
94
+ | `SSO_ORG_NUM` | 组织编号 |
95
+ | `X_COMPANY_ID` | 租户公司 ID(`X-Company-Id` 请求头) |
96
+
97
+ ### 登录状态管理
98
+
99
+ ```bash
100
+ elc login status # 查看当前登录状态
101
+ elc login logout # 退出登录(清除本地 token)
102
+ ```
103
+
104
+ ---
105
+
106
+ ## 命令参考
107
+
108
+ ### 通用选项
109
+
110
+ 所有查询命令均支持 `-o` 控制输出格式:
111
+
112
+ | 值 | 说明 |
113
+ |----|------|
114
+ | `table` | 富文本表格(默认) |
115
+ | `json` | 原始 JSON |
116
+
117
+ ---
118
+
119
+ ### `invoice-request` — 开票申请单
120
+
121
+ ```bash
122
+ # 查询列表
123
+ elc invoice-request list
124
+ elc invoice-request list --status PENDING --source-system ERP -o json
125
+
126
+ # 查询详情
127
+ elc invoice-request get <invoiceRequestId>
128
+
129
+ # 创建(上传 KDUBL XML)
130
+ elc invoice-request create -f payload.xml --source-system MY_ERP --source-id BILL-001
131
+
132
+ # 同批次多单(共用 batch-id)
133
+ elc invoice-request create -f payload.xml --batch-id <uuid>
134
+
135
+ # 更新(状态为 draft / validate_failed / pending 时可更新)
136
+ elc invoice-request update <invoiceRequestId> -f updated.xml
137
+
138
+ # 作废
139
+ elc invoice-request void <invoiceRequestId>
140
+
141
+ # 触发开票
142
+ elc invoice-request issue <invoiceRequestId>
143
+
144
+ # 查询申请单下的发票
145
+ elc invoice-request invoices <invoiceRequestId>
146
+
147
+ # Credit Note 蓝冲匹配
148
+ elc invoice-request match-cn-create -f cn.xml
149
+ elc invoice-request match-cn-run <invoiceRequestId> --reason RETURN
150
+ elc invoice-request match-cn-results <invoiceRequestId>
151
+ elc invoice-request match-cn-unlink <invoiceRequestId>
152
+ ```
153
+
154
+ ---
155
+
156
+ ### `invoice` — 发票
157
+
158
+ ```bash
159
+ # 查询详情
160
+ elc invoice get <invoiceId>
161
+
162
+ # 获取文件下载链接
163
+ elc invoice file-link <invoiceId> --type Humanreadable # PDF
164
+ elc invoice file-link <invoiceId> --type Target # 电子发票格式
165
+ elc invoice file-link <invoiceId> --type Source # KDUBL 原文
166
+
167
+ # 取消发票(仅 MY,72 小时内)
168
+ elc invoice cancel <invoiceId> --reason "Customer requested cancellation"
169
+ ```
170
+
171
+ ---
172
+
173
+ ### `party` — 注册主体
174
+
175
+ ```bash
176
+ elc party list --keyword ACME --type 1
177
+ elc party get <id>
178
+ elc party upsert -f party.json
179
+ elc party upsert -d '{"type":1,"name":"ACME","organizationNo":"ORG001","country":"DE","status":1,"identifiers":[...]}'
180
+ elc party delete <id>
181
+ ```
182
+
183
+ ---
184
+
185
+ ### `product` — 商品
186
+
187
+ ```bash
188
+ elc product list --category GOODS
189
+ elc product get <id>
190
+ elc product upsert -f product.json
191
+ elc product delete <id>
192
+ ```
193
+
194
+ ---
195
+
196
+ ### `tax` — 税目
197
+
198
+ ```bash
199
+ elc tax list --country MY
200
+ elc tax get <id>
201
+ elc tax create -f tax.json
202
+ elc tax delete <id>
203
+ ```
204
+
205
+ ---
206
+
207
+ ### `exchange` — 汇率
208
+
209
+ ```bash
210
+ elc exchange list --from USD --to CNY
211
+ elc exchange latest USD CNY
212
+ elc exchange create --from USD --to EUR --rate 0.92 --date 2026-06-30
213
+ elc exchange delete <id>
214
+ elc exchange currencies
215
+ ```
216
+
217
+ ---
218
+
219
+ ### `export` — 导出
220
+
221
+ ```bash
222
+ elc export invoices --output invoices.xlsx
223
+ ```
224
+
225
+ ---
226
+
227
+ ### `describe` — AI 上下文描述
228
+
229
+ ```bash
230
+ elc describe
231
+ ```
232
+
233
+ 输出当前可用接口的结构化描述,供 AI 工具(如 Claude、GPT)理解 CLI 能力。
234
+
235
+ ---
236
+
237
+ ## 工程结构
238
+
239
+ ```
240
+ elc-invoice-engine-cli/
241
+ ├── pyproject.toml # 构建配置 & 依赖,定义 `elc` 入口点
242
+ ├── requirements.txt # 锁定依赖版本(与 pyproject.toml 一致)
243
+ ├── .env.example # 配置模板,复制为 .env.local 后填写
244
+ ├── .env.local # 本地配置(不提交 git)
245
+ └── cli/
246
+ ├── main.py # 入口,注册所有命令组
247
+ ├── auth.py # SSO MD5 签名登录
248
+ ├── client.py # httpx 封装
249
+ ├── config.py # 环境变量读取
250
+ ├── output.py # rich 表格 / JSON 输出
251
+ ├── session.py # 懒加载 ApiClient(优先读本地 token)
252
+ ├── token_store.py # ~/.elc/token.json 读写
253
+ ├── commands/
254
+ │ ├── login.py # elc login / logout / status
255
+ │ ├── invoice.py # elc invoice-request ...
256
+ │ ├── invoice_doc.py # elc invoice ...
257
+ │ ├── party.py # elc party ...
258
+ │ ├── product.py # elc product ...
259
+ │ ├── tax.py # elc tax ...
260
+ │ ├── exchange.py # elc exchange ...
261
+ │ ├── export.py # elc export ...
262
+ │ └── describe.py # elc describe
263
+ └── export/
264
+ ├── mapping_store.py
265
+ ├── xml_parser.py
266
+ └── excel_writer.py
267
+ ```
268
+
269
+ ---
270
+
271
+ ## 常见问
272
+
273
+ **Q: `elc: command not found`**
274
+ 确认虚拟环境已激活(`source .venv/bin/activate`),或重新执行 `pip install -e .`。
275
+
276
+ **Q: token 过期 / 401 错误**
277
+ 运行 `elc login` 重新登录,或检查 `.env.local` 中的 `SSO_SECRET` 是否正确。
278
+
279
+ **Q: 如何切换不同环境(dev / staging / prod)**
280
+ 修改 `.env.local` 中的 `BASE_URL`,或在登录时通过 `--url` 选项指定。
281
+
282
+ ---
283
+
284
+ ## 发布到 PyPI
285
+
286
+ ### 前置准备
287
+
288
+ ```bash
289
+ pip install build twine
290
+ ```
291
+
292
+ 注册账号:
293
+ - 正式发布:[https://pypi.org/account/register/](https://pypi.org/account/register/)
294
+ - 测试发布:[https://test.pypi.org/account/register/](https://test.pypi.org/account/register/)
295
+
296
+ 在 PyPI 账户设置中创建 **API Token**,范围选"Entire account"(首次发布前包还不存在,无法选具体包)。
297
+
298
+ 配置本地凭证(只需做一次):
299
+
300
+ ```bash
301
+ # ~/.pypirc
302
+ cat > ~/.pypirc <<'EOF'
303
+ [distutils]
304
+ index-servers =
305
+ pypi
306
+ testpypi
307
+
308
+ [pypi]
309
+ username = __token__
310
+ password = pypi-xxxxxxxxxxxxxxxx # 替换为你的 API Token
311
+
312
+ [testpypi]
313
+ repository = https://test.pypi.org/legacy/
314
+ username = __token__
315
+ password = pypi-xxxxxxxxxxxxxxxx # 替换为 Test PyPI 的 API Token
316
+ EOF
317
+ chmod 600 ~/.pypirc
318
+ ```
319
+
320
+ ### 发布流程
321
+
322
+ **1. 更新版本号**
323
+
324
+ 编辑 `pyproject.toml`,修改 `version` 字段,遵循 [语义化版本](https://semver.org/lang/zh-CN/):
325
+
326
+ ```toml
327
+ version = "0.2.0"
328
+ ```
329
+
330
+ **2. 构建发行包**
331
+
332
+ ```bash
333
+ # 清理旧产物
334
+ rm -rf dist/
335
+
336
+ # 构建 wheel + sdist
337
+ python -m build
338
+ ```
339
+
340
+ 构建完成后 `dist/` 目录下会生成:
341
+
342
+ ```
343
+ dist/
344
+ ├── elc_invoice_engine_cli-0.2.0-py3-none-any.whl
345
+ └── elc_invoice_engine_cli-0.2.0.tar.gz
346
+ ```
347
+
348
+ **3. 先发到 Test PyPI 验证**
349
+
350
+ ```bash
351
+ twine upload --repository testpypi dist/*
352
+ ```
353
+
354
+ 验证安装:
355
+
356
+ ```bash
357
+ pip install --index-url https://test.pypi.org/simple/ elc-invoice-engine-cli
358
+ elc --help
359
+ ```
360
+
361
+ **4. 发布到正式 PyPI**
362
+
363
+ ```bash
364
+ twine upload dist/*
365
+ ```
366
+
367
+ 发布后用户即可直接安装:
368
+
369
+ ```bash
370
+ pip install elc-invoice-engine-cli
371
+ elc --help
372
+ ```
373
+
374
+ ### 版本迭代
375
+
376
+ 每次发布前必须递增 `pyproject.toml` 中的 `version`,PyPI 不允许覆盖已发布的版本号。
377
+
378
+ 推荐在 `git` 中打 tag 与版本对应:
379
+
380
+ ```bash
381
+ git tag v0.2.0
382
+ git push origin v0.2.0
383
+ ```
@@ -0,0 +1,27 @@
1
+ cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ cli/auth.py,sha256=Tn_Kf4RbiBjf5beLnOC4-U_QQbv_uC45h4aCDwA9LNw,1361
3
+ cli/client.py,sha256=U4XTf7S3fy6xhS5ZFtrP8nt3oqGn1oBNcadAP3l10XU,1883
4
+ cli/config.py,sha256=fq6rnLKGkkyRaIMTJDC-6K5zr6J8ybCSvSAOd_2aVCM,935
5
+ cli/main.py,sha256=vOJ4V54sUyhNnzV_uDyWSFsprsRfuoTyH0BvMVZ-N1Y,827
6
+ cli/output.py,sha256=NzQvF6bDUfHocE_Jbz6Zq0MxQCWtYqkgNxeyRxxU4vY,1345
7
+ cli/session.py,sha256=yaHz2xJVBxZk2DXMRjYyMy4tI_Hoom-jNrnpyt-GC9g,957
8
+ cli/token_store.py,sha256=_jU0Q_1Pm8HA9acjxov9qUg7tbiTruNd1PQmVOuee20,961
9
+ cli/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ cli/commands/describe.py,sha256=UdqgQDGL1jFKfH-qDE1nhrsJENLmaRiOes4HplhEw1M,7664
11
+ cli/commands/exchange.py,sha256=SVEsb_9dBSij8QrBuLYK-Gy6sAcWjF8Ll6vP4yLr5x8,2986
12
+ cli/commands/export.py,sha256=NTae6twwJVHY04Yh4FxWfUDaDgDQPt7qR-c6DaUav54,13541
13
+ cli/commands/invoice.py,sha256=_GpfTvFgAuhRN9m_lqZ8dGN384TxbHBa2B-0oUTamxo,9753
14
+ cli/commands/invoice_doc.py,sha256=rbXuYWg7DfUYTiK6-1D3DKNSW2CXK4IPNvWuDclHM2A,3922
15
+ cli/commands/login.py,sha256=peOQ5tWBhbgltgJPeQFwenWH2QhE7WlyX_NLY0MH3nQ,3338
16
+ cli/commands/party.py,sha256=G3YDmnUEBiLYrnpqXlE3W3mOi6DytNg7So0IrJoeCzg,2361
17
+ cli/commands/product.py,sha256=Sw_Kaivx0dRfeisUrugUutXkHZxT-vsPIDzMQI5Pe48,2094
18
+ cli/commands/tax.py,sha256=qfK89DPhOt2A5Hy_l_8bTinwRtJLFdhiCubRIBZi1nM,2032
19
+ cli/export/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ cli/export/excel_writer.py,sha256=3ozsnm-5rO-MMprXy_mloFusdHBcoUCELe7JLxe3oik,3542
21
+ cli/export/mapping_store.py,sha256=lehrCw2my0ifph9SCajK45QS4R2Oksbrz-QMfiboG9s,1393
22
+ cli/export/xml_parser.py,sha256=H6noKAAyhn2EheL1TFHOAQ2JZrG7l2F-MlKAgCPyqHA,1921
23
+ elc_invoice_engine_cli-0.1.0.dist-info/METADATA,sha256=b4kmxpOPnJGxKx5Oy7TXfhvS7rw5Ww9b1YEDb8F15xI,9096
24
+ elc_invoice_engine_cli-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
25
+ elc_invoice_engine_cli-0.1.0.dist-info/entry_points.txt,sha256=2tQR1lqAO4yHtYuDbBp_oxLN5wC-fIpW7s0LoC4TnK4,37
26
+ elc_invoice_engine_cli-0.1.0.dist-info/top_level.txt,sha256=2ImG917oaVHlm0nP9oJE-Qrgs-fq_fGWgba2H1f8fpE,4
27
+ elc_invoice_engine_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ elc = cli.main:app