- 读 EHR 预支台账 → 按 ERP 付款申请单口径逐行建单,默认试算不写库 - 可选建单后自动提交、按套打样例生成 PDF 直连网络打印,打印完成钉钉提醒领取 - 含幂等查重与异常清单,业务口径与字段顺序按生产单核对 - 依赖 erpsdk / printkit / dingtalk_sdk(plugin.json requires.sdks 声明) - 需求单文档同步:开发/流程/评分/需求文档更新,新增交接文档
131 lines
5.4 KiB
Python
131 lines
5.4 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""插件自检(不联网:不登录 ERP、不出纸)。
|
||
|
||
会被壳子/SDK 分发流程当作自检入口(见 sdk.json 约定),也可手动跑:
|
||
.venv\\Scripts\\python.exe "plugins\\XQ0001-0100\\XQ0012 EHR预支及支付报酬自动发起ERP付款申请\\_selftest.py"
|
||
|
||
覆盖:配置常量 → payload 字段顺序 → 台账读取 → 套打 PDF 生成 → 流程试算。
|
||
"""
|
||
import sys
|
||
import types
|
||
from datetime import date
|
||
from pathlib import Path
|
||
|
||
HERE = Path(__file__).resolve().parent
|
||
|
||
# 以「包」的方式加载(跳过 __init__.py 的 webhost 依赖)
|
||
_pkg = types.ModuleType("xq0012")
|
||
_pkg.__path__ = [str(HERE)]
|
||
sys.modules["xq0012"] = _pkg
|
||
|
||
from xq0012 import config # noqa: E402
|
||
from xq0012.logic import payload, flow # noqa: E402
|
||
from xq0012.report import payapply_pdf, notify # noqa: E402
|
||
|
||
FAILED = []
|
||
|
||
|
||
def check(name, fn):
|
||
try:
|
||
fn()
|
||
print(f"[ok] {name}")
|
||
except Exception as e: # noqa: BLE001
|
||
FAILED.append((name, e))
|
||
print(f"[FAIL] {name}: {e}")
|
||
|
||
|
||
def t_config():
|
||
assert config.FORM_ID == 'CN_PAYAPPLY'
|
||
assert config.BILL_TYPE_ID == 'FKSQ006.0YS'
|
||
assert config.SAVE_OPTIONS['is_auto_adjust_field'] is False, 'IsAutoAdjustField 必须关'
|
||
|
||
|
||
def t_payload_order():
|
||
row = {'seq': '1', 'month': '202610', 'staff': '37000365', 'name': '何广飞',
|
||
'date': '2026-10-30', 'amount': 2000.0, 'reason': '缴纳弟弟生活费',
|
||
'org_path': '集团-金色印象事业部-第一大区-水晶郦城CEO会馆', 'dept': '接待组'}
|
||
m = payload.build_model(row, org_code='99.01.06.01.02.01.05', dept_code='BM000477',
|
||
purpose_id='SFKYT11_SYS', apply_date=date(2026, 10, 30), expect_days=1,
|
||
venue='水晶郦城CEO会馆')
|
||
keys = list(m)
|
||
assert keys[-1] == 'FPAYAPPLYENTRY', '分录必须最后'
|
||
assert keys.index('FBJ_SQR') < keys.index('F_VTUY_Base_re5'), '部门必须在申请人之后'
|
||
assert m['FBJ_SQR'] == {'FSTAFFNUMBER': '37000365'}
|
||
assert m['FCONTACTUNIT'] == {'FNumber': '37000365'}, '往来单位用工号键 FNumber'
|
||
assert m['FPAYAPPLYENTRY'][0]['FAPPLYAMOUNTFOR'] == 2000.0
|
||
assert m['FPAYAPPLYENTRY'][0]['FEXPECTPAYDATE'] == '2026-10-31'
|
||
assert '何广飞' in m['F_VTUY_Remarks_qtr']
|
||
|
||
|
||
def t_ledger_read():
|
||
p = config.LEDGER_DIR_DEFAULT
|
||
import os
|
||
if not os.path.isdir(p):
|
||
print(' (台账目录不存在,跳过)')
|
||
return
|
||
sys.path.insert(0, str(HERE))
|
||
from xq0012.data import ledger
|
||
f = ledger.find_latest_ledger(p)
|
||
rows = ledger.read_rows(f)
|
||
assert rows and rows[0]['staff'], '台账应至少有一条有效行'
|
||
org = ledger.load_org_map(f)
|
||
print(f' {Path(f).name}: {len(rows)} 行,组织映射 {len(org)} 条')
|
||
|
||
|
||
def t_render_pdf():
|
||
data = payapply_pdf.from_view({}, 'SELFTEST-0001')
|
||
data.update({'applicant': '何广飞', 'applicant_no': '37000365', 'dept': '人力资源部',
|
||
'pay_org': '重庆三十七度健康管理有限公司', 'apply_amount': '2000.00',
|
||
'approve_amount': '2000.00', 'create_date': '2026/11/14', 'currency': '人民币'})
|
||
data['entries'] = [{'cost': '预支工资', 'account_name': '何广飞', 'bank': '招商银行',
|
||
'account_no': '6222***0000', 'amount': '2000.00', 'dept': '', 'remark': ''}]
|
||
out = str(HERE.parents[2] / 'out' / '_selftest_payapply.pdf')
|
||
payapply_pdf.render_payapply(data, out)
|
||
import pymupdf
|
||
doc = pymupdf.open(out)
|
||
assert doc.page_count == 1
|
||
text = doc[0].get_text('text')
|
||
assert 'SELFTEST-0001' in text and '2000.00' in text
|
||
assert len([d for d in doc[0].get_drawings()]) >= 30, '表格线数量异常'
|
||
doc.close()
|
||
|
||
|
||
def t_notify_message():
|
||
body = notify.build_message(
|
||
[{'bill_no': 'FKSQ20261100001', 'name': '何广飞', 'amount': 2000.0},
|
||
{'bill_no': 'FKSQ20261100002', 'name': '唐雪非', 'amount': 1500.5}],
|
||
'网络信息部', failed=1)
|
||
assert '网络信息部' in body and '打印机处领取' in body
|
||
assert 'FKSQ20261100001' in body and '1500.50' in body
|
||
assert '合计 3500.50 元' in body
|
||
assert '打印失败' in body
|
||
|
||
|
||
def t_notify_recipients():
|
||
got = notify.parse_recipients('陈莲/37001090、张三(37000236); 李四')
|
||
assert got[0] == ('陈莲', '37001090') and got[1] == ('张三', '37000236')
|
||
assert got[2] == ('李四', '')
|
||
|
||
|
||
def t_flow_dry_run():
|
||
rows = [{'seq': '1', 'staff': '37000365', 'name': '何广飞', 'date': '2026-10-30',
|
||
'amount': 2000.0, 'reason': '测试', 'org_path': '集团-水晶郦城CEO会馆', 'dept': '接待组'}]
|
||
out = flow.run_flow(rows_data=rows, org_map={'水晶郦城CEO会馆': '99.01.06.01.02.01.05'},
|
||
dry_run=True, apply_date=date(2026, 10, 30))
|
||
assert '试算' in out['summary'] and len(out['detail']) == 1
|
||
|
||
|
||
if __name__ == '__main__':
|
||
check('配置常量', t_config)
|
||
check('payload 字段顺序', t_payload_order)
|
||
check('台账读取', t_ledger_read)
|
||
check('套打 PDF', t_render_pdf)
|
||
check('钉钉提醒文案', t_notify_message)
|
||
check('钉钉接收人解析', t_notify_recipients)
|
||
check('流程试算', t_flow_dry_run)
|
||
print('=' * 50)
|
||
if FAILED:
|
||
print(f'失败 {len(FAILED)} 项')
|
||
sys.exit(1)
|
||
print('全部通过')
|