- 退役 erp_adapter/gateway_adapter:外部查询/写经 capability_client 走集成连接器,端点凭据与并发超时由客户端实例管理 - 域能力代码注册 capabilities:入参出参 Schema、幂等语义与读写标志随域代码版本化,组合根 create_app 幂等注册 - 新增调拨业务类型 transfer_type(在途仓至HUB/HUB维修出/HUB间)冻结枚举,迁移落 CheckConstraint 数据库兜底 - 外部仓库映射新增 in_transit_warehouse_code 拨出库位来源,管理端库存映射页同步维护 - 单据命名外部化:erp_* 字段与索引改称 external_*,单据号格式交由连接器映射,测试数据同步换牌 - 收料归档文件可用性判定收敛 receipt_file_gate 单一事实来源(当天抓取/保留期/清理态) - 同步 chat 调拨卡片、useChatTransfer、e2e、全套服务/API/Job 测试与域文档
79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
"""在途调拨 DTO 序列化(API 与 Chat Action 共用)。
|
|
|
|
用途:将领域 DTO 转为前端稳定 JSON(预检摘要/明细/来源进度/执行结果)。
|
|
依赖:contracts、execution_service。
|
|
逻辑:单一序列化来源,避免 API 与 Chat Action 各自实现导致契约漂移。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from app.services.in_transit_transfer.execution_service import serialize_run_result
|
|
|
|
|
|
def serialize_summary(summary) -> dict[str, Any]:
|
|
"""预检摘要序列化。"""
|
|
return {
|
|
"precheck_id": summary.precheck_id,
|
|
"status": summary.status,
|
|
"business_date": summary.business_date,
|
|
"eligible_receipt_date_to": summary.eligible_receipt_date_to,
|
|
"expires_at": summary.expires_at,
|
|
"counts": {
|
|
"file_invoice_count": summary.counts.file_invoice_count,
|
|
"not_matured_count": summary.counts.not_matured_count,
|
|
"prechecked_count": summary.counts.prechecked_count,
|
|
"executable_count": summary.counts.executable_count,
|
|
"blocked_count": summary.counts.blocked_count,
|
|
},
|
|
"estimated_transfer_quantity": summary.estimated_transfer_quantity,
|
|
"estimated_external_write_count": summary.estimated_external_write_count,
|
|
"precheck_hash": summary.precheck_hash,
|
|
}
|
|
|
|
|
|
def serialize_item(item) -> dict[str, Any]:
|
|
"""明细项序列化(决策 6 十列字段)。"""
|
|
return {
|
|
"source_code": item.source_code,
|
|
"material_no": item.material_no,
|
|
"material_name": item.material_name,
|
|
"specification": item.specification,
|
|
"invoice_no": item.invoice_no,
|
|
"lot_no": item.lot_no,
|
|
"receipt_date": item.receipt_date,
|
|
"from_warehouse": item.from_warehouse,
|
|
"from_quantity": str(item.from_quantity) if item.from_quantity is not None else None,
|
|
"to_warehouse": item.to_warehouse,
|
|
"to_quantity": str(item.to_quantity),
|
|
"result": item.result,
|
|
"reason": item.reason,
|
|
"raw_lines": [
|
|
{"sheet": line.sheet, "row_no": line.row_no, "file_version": line.file_version}
|
|
for line in item.raw_lines
|
|
],
|
|
}
|
|
|
|
|
|
def serialize_source(source) -> dict[str, Any]:
|
|
"""来源进度序列化。"""
|
|
return {
|
|
"source_code": source.source_code,
|
|
"stage": source.stage,
|
|
"file_no": source.file_no,
|
|
"file_version": source.file_version,
|
|
"checksum": source.checksum,
|
|
"error_code": source.error_code,
|
|
"error_message": source.error_message,
|
|
}
|
|
|
|
|
|
def serialize_precheck_detail(detail: dict[str, Any]) -> dict[str, Any]:
|
|
"""预检恢复详情(summary + items + sources)。"""
|
|
return {
|
|
"summary": serialize_summary(detail["summary"]),
|
|
"items": [serialize_item(item) for item in detail["items"]],
|
|
"sources": [serialize_source(source) for source in detail["sources"]],
|
|
}
|