Merge branch 'dev' into runny827
feat(training): 新增精益培训视频与周任务管理 # Conflicts: # backend/app/models/__init__.py
This commit is contained in:
1 parent
85d27e9ffa
commit
91b7233872
812 files changed
+73763
-18908
No files matched your search
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
backend/app/services/voucher_check/excel_rows.py
|
||||
|
||||
用途:把批次明细转换为通用 Excel 导出行与表头。
|
||||
依赖:无。
|
||||
逻辑:runner 返回 details;schedule excel_service / register_schedule_header 使用本模块表头。
|
||||
用途:把按 invoice 聚合的检核结果转为排程 Excel 行与表头。
|
||||
依赖:aggregator 单元格文案。
|
||||
逻辑:一行一张 invoice;六类必检列为有/缺件/未检核;资料所属期间与执行时间单独成列以兼容现有排程导出。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -12,82 +12,57 @@ from typing import Any
|
||||
|
||||
VOUCHER_CHECK_HEADER_ORDER = [
|
||||
"period",
|
||||
"scope_code",
|
||||
"executed_at",
|
||||
"invoice_no",
|
||||
"invoice_date",
|
||||
"result",
|
||||
"folder_exists",
|
||||
"folder_path",
|
||||
"matched_files",
|
||||
"missing_materials",
|
||||
"material_fingerprint",
|
||||
"checked_at",
|
||||
"error_code",
|
||||
"error_message",
|
||||
"po_order",
|
||||
"customs_pack",
|
||||
"sales_release",
|
||||
"tax_invoice",
|
||||
"customs_declaration",
|
||||
"bill_of_lading",
|
||||
"status",
|
||||
]
|
||||
|
||||
VOUCHER_CHECK_HEADER_LABELS = {
|
||||
"period": "检核月份",
|
||||
"scope_code": "账套",
|
||||
"invoice_no": "发票号",
|
||||
"invoice_date": "发票日期",
|
||||
"result": "结论",
|
||||
"folder_exists": "发票目录是否存在",
|
||||
"folder_path": "共享盘相对路径",
|
||||
"matched_files": "已找到材料",
|
||||
"missing_materials": "缺失材料",
|
||||
"material_fingerprint": "目录元数据指纹",
|
||||
"checked_at": "实际检核时间",
|
||||
"error_code": "技术错误码",
|
||||
"error_message": "技术错误摘要",
|
||||
"period": "资料所属期间",
|
||||
"executed_at": "执行时间",
|
||||
"invoice_no": "invoice",
|
||||
"po_order": "PO订单",
|
||||
"customs_pack": "报关资料",
|
||||
"sales_release": "销货放行申请单",
|
||||
"tax_invoice": "发票",
|
||||
"customs_declaration": "报关单",
|
||||
"bill_of_lading": "提单",
|
||||
"status": "状态",
|
||||
}
|
||||
|
||||
_RESULT_LABELS = {
|
||||
"complete": "齐全",
|
||||
"missing": "缺资料",
|
||||
"skipped": "跳过",
|
||||
"technical_error": "技术异常",
|
||||
}
|
||||
_RULE_COLUMNS = (
|
||||
"po_order",
|
||||
"customs_pack",
|
||||
"sales_release",
|
||||
"tax_invoice",
|
||||
"customs_declaration",
|
||||
"bill_of_lading",
|
||||
)
|
||||
|
||||
|
||||
def _fmt_matched(matched: dict[str, Any] | None) -> str:
|
||||
if not matched:
|
||||
return ""
|
||||
return "; ".join(f"{k}={v}" for k, v in matched.items())
|
||||
|
||||
|
||||
def _fmt_missing(missing: list[dict[str, Any]] | None) -> str:
|
||||
if not missing:
|
||||
return ""
|
||||
parts = []
|
||||
for item in missing:
|
||||
name = item.get("name") or item.get("code") or ""
|
||||
code = item.get("code") or ""
|
||||
parts.append(f"{name}({code})" if code and name != code else str(name or code))
|
||||
return "; ".join(parts)
|
||||
|
||||
|
||||
def to_excel_detail_row(item: dict[str, Any], *, period: str, scope_code: str) -> dict[str, Any]:
|
||||
def to_excel_invoice_row(
|
||||
item: dict[str, Any],
|
||||
*,
|
||||
period: str,
|
||||
executed_at: str,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
将内存结果行转为 Excel details 行。
|
||||
将聚合后的 invoice 行转为排程 Excel details。
|
||||
核心逻辑:cells 按 rule_code 取值;缺列填未检核。
|
||||
"""
|
||||
result = str(item.get("result") or "")
|
||||
checked_at = item.get("checked_at")
|
||||
invoice_date = item.get("invoice_date")
|
||||
return {
|
||||
cells = item.get("cells") or {}
|
||||
row = {
|
||||
"period": period,
|
||||
"scope_code": scope_code,
|
||||
"executed_at": executed_at,
|
||||
"invoice_no": item.get("invoice_no"),
|
||||
"invoice_date": invoice_date.isoformat() if hasattr(invoice_date, "isoformat") else invoice_date,
|
||||
"result": _RESULT_LABELS.get(result, result),
|
||||
"folder_exists": "是" if item.get("folder_exists") else "否",
|
||||
"folder_path": item.get("folder_path") or "",
|
||||
"matched_files": _fmt_matched(item.get("matched_files")),
|
||||
"missing_materials": _fmt_missing(item.get("missing_materials")),
|
||||
"material_fingerprint": item.get("material_fingerprint") or "",
|
||||
"checked_at": checked_at.isoformat(sep=" ", timespec="seconds")
|
||||
if hasattr(checked_at, "isoformat")
|
||||
else (checked_at or ""),
|
||||
"error_code": item.get("error_code") or "",
|
||||
"error_message": item.get("error_message") or "",
|
||||
"status": item.get("status") or "",
|
||||
}
|
||||
for code in _RULE_COLUMNS:
|
||||
row[code] = cells.get(code) or "未检核"
|
||||
return row
|
||||
Reference in new issue
Block a user