feat(schedule): 增加库存源选项描述字段与站点ID支持

This commit is contained in:
hugo committed 2026-07-10 00:48:27 +08:00
1 parent f4e74f7b07
commit 8b1efbedb9
37 files changed
+8488 -4126

No files matched your search

+5 -1
View File
@@ -39,7 +39,11 @@ def _shipping_inventory_sources_options() -> list[dict[str, Any]]:
{
"label": source.get("display_name") or source.get("source_code"),
"value": source.get("source_code"),
"description": f"{source.get('site')} · {source.get('warehouse_id')}",
"description": (
f"{source.get('source_type')} · "
f"{source.get('site_id') or '-'} · "
f"{source.get('warehouse_id')}"
),
}
for source in list_inventory_sources()
]
@@ -28,6 +28,7 @@ FinalizeScheduleRunResult = dict[str, Any]
_INVENTORY_RPA_HEADER_ORDER = [
"source_code",
"site_id",
"warehouse_id",
"display_name",
"inventory_file_no",
@@ -36,6 +37,7 @@ _INVENTORY_RPA_HEADER_ORDER = [
]
_INVENTORY_RPA_HEADER_LABELS = {
"source_code": "库存源",
"site_id": "站点",
"warehouse_id": "仓库",
"display_name": "名称",
"inventory_file_no": "库存快照号",
@@ -139,6 +141,7 @@ def _build_finalize_details(
base = pending_by_key.get(key, {})
details.append({
"source_code": code or item.get("source_code"),
"site_id": item.get("site_id") or base.get("site_id"),
"warehouse_id": wh or base.get("warehouse_id"),
"display_name": base.get("display_name"),
"inventory_file_no": item.get("inventory_file_no"),
@@ -155,6 +158,7 @@ def _build_finalize_details(
base = pending_by_key.get(key, {})
details.append({
"source_code": code or item.get("source_code"),
"site_id": item.get("site_id") or base.get("site_id"),
"warehouse_id": wh or base.get("warehouse_id"),
"display_name": base.get("display_name"),
"inventory_file_no": "",
@@ -166,6 +170,7 @@ def _build_finalize_details(
continue
details.append({
"source_code": base.get("source_code"),
"site_id": base.get("site_id"),
"warehouse_id": base.get("warehouse_id"),
"display_name": base.get("display_name"),
"inventory_file_no": "",
@@ -52,9 +52,9 @@ def _normalize_filter_tokens(raw: Any) -> set[str]:
def _source_identity_tokens(source: dict[str, Any]) -> set[str]:
"""收集库存源可用于匹配的标识集合(source_code / warehouse_id / match_aliases)。"""
"""收集库存源可用于匹配的标识集合(source_code / site_id / warehouse_id / match_aliases)。"""
tokens: set[str] = set()
for key in ("source_code", "warehouse_id", "warehouse_code"):
for key in ("source_code", "site_id", "warehouse_id"):
value = str(source.get(key) or "").strip().upper()
if value:
tokens.add(value)
@@ -68,12 +68,14 @@ def _source_identity_tokens(source: dict[str, Any]) -> set[str]:
def _extract_wanted_tokens(body_template: dict[str, Any]) -> set[str]:
"""
从 api_body_template 提取筛选 token。
推荐键:source_codes;兼容:source_code / warehouse_ids / warehouse_id / match_aliases。
推荐键:source_codes;兼容:source_code / site_ids / site_id / warehouse_ids / warehouse_id / match_aliases。
"""
wanted: set[str] = set()
for key in (
"source_codes",
"source_code",
"site_ids",
"site_id",
"warehouse_ids",
"warehouse_id",
"match_aliases",
@@ -103,7 +105,7 @@ def _resolve_filter_payload(task: ScheduleTask) -> dict[str, Any] | None:
def _filter_sources(task: ScheduleTask) -> list[dict[str, Any]]:
"""
读取 enabled 库存源;job_params / api_body_template 可限定子集。
核心逻辑:无筛选则导出全部启用源;有筛选时按 source_code / warehouse_id / match_aliases 命中。
核心逻辑:无筛选则导出全部启用源;有筛选时按 source_code / site_id / warehouse_id / match_aliases 命中。
"""
enabled = list_inventory_sources()
body_template = _resolve_filter_payload(task)
@@ -164,6 +166,7 @@ def run_shipping_inventory_rpa_schedule(task: ScheduleTask, run: ScheduleRun) ->
details = [
{
"source_code": item.get("source_code"),
"site_id": item.get("site_id"),
"warehouse_id": item.get("warehouse_id"),
"display_name": item.get("display_name"),
}