- 读 EHR 预支台账 → 按 ERP 付款申请单口径逐行建单,默认试算不写库 - 可选建单后自动提交、按套打样例生成 PDF 直连网络打印,打印完成钉钉提醒领取 - 含幂等查重与异常清单,业务口径与字段顺序按生产单核对 - 依赖 erpsdk / printkit / dingtalk_sdk(plugin.json requires.sdks 声明) - 需求单文档同步:开发/流程/评分/需求文档更新,新增交接文档
63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""ERP 动作层:登录 / 查重 / 建单 / 提交 / 撤回 / 删除(薄封装 erpsdk)。
|
||
|
||
已验证细节(2026-11-14 测试服):
|
||
- 提交后状态 B;撤回用 `CancelAssign`(`revoke()` 自动探测),B→D;只有 A/Z/D 可删;
|
||
- Save 必须传 `is_auto_adjust_field=False`(见 config.SAVE_OPTIONS);
|
||
- `view()` 不回 FBillNo,单号要自己带。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
from erpsdk import ErpClient, ErpError, save_options
|
||
|
||
from .. import config
|
||
|
||
TAG = '[ERP]'
|
||
|
||
|
||
def login(username: str, password: str, erp: str = 'new', acct: str = '') -> ErpClient:
|
||
client = ErpClient(erp, acct=(acct or None), timeout=config.TIMEOUT,
|
||
logger=config.log, retry=config.RETRY_MAX)
|
||
client.login(username, password)
|
||
return client
|
||
|
||
|
||
def find_duplicate(client: ErpClient, remark_fragment: str) -> list:
|
||
"""幂等查重:按申请说明片段查同月同日同人同额的已建单。
|
||
|
||
WAF 会拦含 `and` 的组合过滤,这里只用一个 like 条件。
|
||
"""
|
||
if not remark_fragment:
|
||
return []
|
||
try:
|
||
return client.bill_query(
|
||
config.FORM_ID, 'FBillNo,FDocumentStatus,FDATE',
|
||
filter_string=f"F_VTUY_Remarks_qtr like '%{remark_fragment}%'", limit=20) or []
|
||
except ErpError as e:
|
||
config.log(f'{TAG} 查重失败(忽略继续):{e}')
|
||
return []
|
||
|
||
|
||
def create(client: ErpClient, model: dict) -> tuple:
|
||
"""保存草稿 → (Id, 单号)。"""
|
||
res = client.save(config.FORM_ID, model, extra=save_options(**config.SAVE_OPTIONS))
|
||
return res.get('Id'), res.get('Number') or res.get('FBillNo')
|
||
|
||
|
||
def submit(client: ErpClient, number: str) -> None:
|
||
client.submit(config.FORM_ID, numbers=[number])
|
||
|
||
|
||
def revoke(client: ErpClient, number: str) -> None:
|
||
client.revoke(config.FORM_ID, numbers=[number])
|
||
|
||
|
||
def delete(client: ErpClient, bill_id) -> None:
|
||
client.delete(config.FORM_ID, ids=[bill_id])
|
||
|
||
|
||
def status(client: ErpClient, number: str) -> str | None:
|
||
rows = client.bill_query(config.FORM_ID, 'FBillNo,FDocumentStatus',
|
||
filter_string=f"FBillNo='{number}'", limit=5)
|
||
return rows[0][1] if rows else None
|