""" backend/app/services/voucher_check/excel_rows.py 用途:把按 invoice 聚合的检核结果转为排程 Excel 行与表头。 依赖:aggregator 单元格文案。 逻辑:一行一张 invoice;六类必检列为有/缺件/未检核;资料所属期间与执行时间单独成列以兼容现有排程导出。 """ from __future__ import annotations from typing import Any VOUCHER_CHECK_HEADER_ORDER = [ "period", "executed_at", "invoice_no", "po_order", "customs_pack", "sales_release", "tax_invoice", "customs_declaration", "bill_of_lading", "status", ] VOUCHER_CHECK_HEADER_LABELS = { "period": "资料所属期间", "executed_at": "执行时间", "invoice_no": "invoice", "po_order": "PO订单", "customs_pack": "报关资料", "sales_release": "销货放行申请单", "tax_invoice": "发票", "customs_declaration": "报关单", "bill_of_lading": "提单", "status": "状态", } _RULE_COLUMNS = ( "po_order", "customs_pack", "sales_release", "tax_invoice", "customs_declaration", "bill_of_lading", ) def to_excel_invoice_row( item: dict[str, Any], *, period: str, executed_at: str, ) -> dict[str, Any]: """ 将聚合后的 invoice 行转为排程 Excel details。 核心逻辑:cells 按 rule_code 取值;缺列填未检核。 """ cells = item.get("cells") or {} row = { "period": period, "executed_at": executed_at, "invoice_no": item.get("invoice_no"), "status": item.get("status") or "", } for code in _RULE_COLUMNS: row[code] = cells.get(code) or "未检核" return row