Files
puddy 4a5a1c2bd4 feat(plugin): XQ0012 预支付款申请 0.2.5(对账回填、新旧系统分流、两份打印、钉钉提醒模块)
台账按月接口导出并追加目标工作簿;整表刷新「预支办结流程」供单据头 XLOOKUP 取收款信息;发起前对账命中回填已付;按台账口径新旧系统分流;建单后套打 ERP 单据 + 单子传递打印;含离线自检与打包脚本。
2026-11-16 17:14:17 +08:00

106 lines
3.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- 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
def list_payapply(client: ErpClient, begin: str, end: str = '') -> list:
"""查 FDATE 区间内的付款申请单(用于发起前对账),排除作废单。
Args:
begin/end: ``YYYY-MM-DD``;end 留空=不限上界。
Returns:
[{"bill_no", "status", "date", "staff", "name", "remark", "amount",
"payee_staff", "payee_name"}]
``staff`` 是申请人(代提人),``payee_*`` 是收款单位(真实受款员工)。
"""
cond = f"FDATE>='{begin}'"
if end:
cond += f" and FDATE<='{end}'"
try:
rows = client.bill_query_all(config.FORM_ID, config.ERP_QUERY_FIELDS,
filter_string=cond, order_string='FID DESC',
page_size=500, max_rows=5000) or []
except ErpError as e:
config.log(f'{TAG} 付款申请单查询失败:{e}', 'WARN')
return []
out = []
for r in rows:
if not r:
continue
vals = list(r) + [None] * 8
state = str(vals[1] or '').strip().upper()
if state == config.ERP_VOID_STATUS:
continue
out.append({
'bill_no': str(vals[0] or '').strip(),
'status': state,
'date': str(vals[2] or '')[:10],
'staff': str(vals[3] or '').strip(),
'remark': str(vals[4] or '').strip(),
'amount': float(vals[5] or 0),
'payee_staff': str(vals[6] or '').strip(),
'payee_name': str(vals[7] or '').strip(),
})
config.log(f'{TAG} {begin}~{end or "今天"} 付款申请单 {len(out)} 张(已排除作废)')
return out