增加生成学校易耗品填写的转换程序
This commit is contained in:
@@ -115,6 +115,8 @@ def _build_summary(data: dict[str, Any]) -> dict[str, str]:
|
||||
"general": "普通发票",
|
||||
"payment": "支付记录",
|
||||
"application": "出差申请单",
|
||||
"attachments": "其他附件",
|
||||
"note": "易耗品单",
|
||||
}
|
||||
|
||||
summary = {}
|
||||
@@ -259,11 +261,12 @@ def extract_invoices(
|
||||
- 出差事前申请单 -> 单独存储,不参与匹配
|
||||
|
||||
Returns:
|
||||
(payment_records, applications, groups):
|
||||
- payment_records: 支付记录列表(仅包含真实发票,不含申请单)
|
||||
- applications: 出差事前申请单列表(单独存储,不参与支付匹配)
|
||||
元组 (payment_records, applications, groups):
|
||||
- payment_records: 支付记录列表(每项含关联发票 _matched_invoices)
|
||||
- applications: 出差事前申请单列表
|
||||
- groups: 按文档类型分组的字典
|
||||
{'travel': [差旅发票], 'general': [普通发票], 'application': [出差事前申请单]}
|
||||
{'travel': [差旅发票], 'general': [普通发票], 'application': [出差事前申请单],
|
||||
'attachments': [其他附件]}
|
||||
|
||||
Raises:
|
||||
ExtractionError: 当所有文件提取均失败时抛出,携带失败文件列表和原始错误。
|
||||
@@ -280,13 +283,14 @@ def extract_invoices(
|
||||
all_files = _find_all_files(directory)
|
||||
if not all_files:
|
||||
log.warning("未找到支持的文件")
|
||||
return [], [], {"travel": [], "general": [], "application": []}
|
||||
return [], [], {"travel": [], "general": [], "application": [], "attachments": []}
|
||||
|
||||
log.info(f"发现 {len(all_files)} 个文件")
|
||||
|
||||
all_invoices = []
|
||||
all_cards = []
|
||||
applications = []
|
||||
attachments = []
|
||||
# 记录失败文件及其错误信息
|
||||
failed_files: list[tuple[str, str]] = []
|
||||
|
||||
@@ -318,6 +322,9 @@ def extract_invoices(
|
||||
elif inv_type == "payment":
|
||||
all_cards.append(result)
|
||||
log.info(f"[{inv_type}] 已解析: {file_path.name}")
|
||||
elif inv_type in ("attachments", "note"):
|
||||
attachments.append(result)
|
||||
log.info(f"[{inv_type}] 已解析: {file_path.name}")
|
||||
elif result.get("invoice_number"):
|
||||
all_invoices.append(result)
|
||||
log.info(f"[{inv_type}] 已解析: {file_path.name}")
|
||||
@@ -334,7 +341,9 @@ def extract_invoices(
|
||||
details=error_details,
|
||||
)
|
||||
|
||||
log.info(f"分类结果: 发票 {len(all_invoices)} 张, 支付记录 {len(all_cards)} 条, 申请单 {len(applications)} 份")
|
||||
log.info(
|
||||
f"分类结果: 发票 {len(all_invoices)} 张, 支付记录 {len(all_cards)} 条, 申请单 {len(applications)} 份, 附件 {len(attachments)} 个"
|
||||
)
|
||||
|
||||
if not all_invoices:
|
||||
log.warning("未成功解析任何发票")
|
||||
@@ -349,10 +358,12 @@ def extract_invoices(
|
||||
all_documents.extend(applications)
|
||||
|
||||
groups = classify_invoice_batch(all_documents)
|
||||
groups["attachments"] = attachments
|
||||
log.info(
|
||||
f"文档分类: 差旅发票 {len(groups['travel'])} 张, "
|
||||
f"普通发票 {len(groups['general'])} 张, "
|
||||
f"出差事前申请单 {len(groups['application'])} 份"
|
||||
f"出差事前申请单 {len(groups['application'])} 份, "
|
||||
f"附件 {len(groups['attachments'])} 个"
|
||||
)
|
||||
|
||||
return payment_records, applications, groups
|
||||
|
||||
Reference in New Issue
Block a user