台账按月接口导出并追加目标工作簿;整表刷新「预支办结流程」供单据头 XLOOKUP 取收款信息;发起前对账命中回填已付;按台账口径新旧系统分流;建单后套打 ERP 单据 + 单子传递打印;含离线自检与打包脚本。
44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""打印层:套打 PDF → printkit 网络打印机出纸。
|
||
|
||
printkit 走 IPP over TLS,不装驱动、不弹框、不走 Windows 队列;
|
||
l6570(人力资源部)支持双面,l565(信息技术部)仅单面(printkit 会自动降级)。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import time
|
||
|
||
from printkit import Printer
|
||
|
||
from .. import config
|
||
|
||
TAG = '[打印]'
|
||
#: 打印机忙着处理上一份时会回 0x0507(server-error-busy),退避重试
|
||
RETRIES = 3
|
||
RETRY_WAIT = 6
|
||
|
||
|
||
def print_pdf(pdf_path: str, printer: str = '', copies: int = 1, dry_run: bool = False) -> list:
|
||
"""打印 PDF,返回每次结果(copies>1 时逐份提交,单份最多重试 ``RETRIES`` 次)。"""
|
||
name = printer or config.PRINTER_DEFAULT
|
||
results = []
|
||
for i in range(max(1, int(copies or 1))):
|
||
for attempt in range(1, RETRIES + 1):
|
||
try:
|
||
r = Printer(name).print(pdf_path, dry_run=dry_run)
|
||
results.append({'copies': i + 1, 'ok': bool(r.get('ok')),
|
||
'pages': len(r.get('pages') or []), 'attempts': attempt})
|
||
config.log(f'{TAG} 第 {i + 1} 份 → {name} ok={bool(r.get("ok"))}'
|
||
+ (f'(第 {attempt} 次)' if attempt > 1 else ''))
|
||
break
|
||
except Exception as e: # noqa: BLE001
|
||
if attempt < RETRIES:
|
||
config.log(f'{TAG} 第 {i + 1} 份失败({name}):{e},{RETRY_WAIT}s 后重试',
|
||
'WARN')
|
||
time.sleep(RETRY_WAIT)
|
||
continue
|
||
config.log(f'{TAG} 第 {i + 1} 份失败({name}):{e}', 'ERROR')
|
||
results.append({'copies': i + 1, 'ok': False, 'attempts': attempt,
|
||
'error': str(e)[:200]})
|
||
return results
|