feat(freight-rpa): 库存/收料改名在手/入站,报表归属RPA,类名统一FreightRpa

把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与
枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa
持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀,
上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-10-19 10:46:06 +08:00
1 parent ffc0d4a430
commit 39fe3c05f2
453 files changed
+17945 -8646

No files matched your search

@@ -4,9 +4,9 @@ services/shipping_notice/ui_state.py
用途:发货通知任务 UI 状态读模型,作为通知摘要、人工复核与任务工作台的统一状态来源。
依赖:models.ShippingNotice/ShippingOrderTask/ShippingProcessExecution、state_machine(UserMode/位置回退)、
query_service、constants.POSITION_*、process_gate_contract.derive_*/STAGE_CAPABILITY_DEFINITIONS、
process_gate_projection、line_inventory_match_projection、inventory_candidate_projection、
process_gate_projection、line_onhand_match_projection、onhand_candidate_projection、
order_review_fulfillment_decision_service(短缺放行模板字段)、
order_review_workbench_projection、inventory_source_repository(preparation.source_options)。
order_review_workbench_projection、onhand_source_repository(preparation.source_options)。
逻辑:优先 Gate 位置/用户模式投影 summary/entry_surface(flat position + user_mode);
Gate 摘要经 Notice.order_task_id→OT 查 Execution(禁止用 Notice.id);
五阶段 processing_stage 同样经 Notice→OT.stage(Notice 无 stage 列),
@@ -56,7 +56,7 @@ from app.services.shipping_notice.constants import (
RS_PARSE_REVIEW,
RS_SHORTAGE_REVIEW,
)
from app.services.shipping_notice.inventory_source_gate import is_inventory_source_stable
from app.services.shipping_notice.onhand_source_gate import is_inventory_source_stable
from app.services.shipping_notice.lifecycle_projection import (
LIFECYCLE_STAGES,
project_lifecycle,
@@ -90,7 +90,7 @@ _REVIEW_ENTRY_POSITIONS = {
}
_NEXT_AUTO_STEP_BY_POSITION: dict[str, str] = {
POSITION_INVENTORY_PENDING: "ensure_inventory",
POSITION_INVENTORY_PENDING: "ensure_onhand",
POSITION_ORDER_FREEZE: "freeze_order",
POSITION_READY_MATCH: "match_inventory",
POSITION_READY_EXPORT: "generate_excel",
@@ -407,12 +407,12 @@ def _derived_entry_surface(
if user_mode in {'must_human', 'wait_manual_upload'}:
return 'task_workbench'
if code in {
'inventory_preparation',
'inventory_matching',
'inventory_sufficiency',
'onhand_preparation',
'onhand_matching',
'onhand_sufficiency',
'excel_readiness',
'artifact_generation',
'inventory_source_routing',
'onhand_source_routing',
'order_freeze_readiness',
}:
return 'task_workbench'
@@ -467,11 +467,11 @@ def _build_stp_facts(task: ShippingNotice) -> dict[str, Any] | None:
"""
from app import db
from app.models import ShippingOrderTask
from app.services.shipping_notice.inventory_candidate_projection import (
from app.services.shipping_notice.onhand_candidate_projection import (
project_inventory_candidate_facts,
)
from app.services.shipping_notice.stp_inventory_freeze import task_frozen_inventory_source_codes
from app.services.shipping_notice.stp_line_inventory_match import multi_source_recovery_source_codes
from app.services.shipping_notice.stp_onhand_freeze import task_frozen_onhand_source_codes
from app.services.shipping_notice.stp_line_onhand_match import multi_source_recovery_source_codes
from app.services.shipping_notice.stp_progress_contract import STP_FACTS_ALLOWED_KEYS
owner = task
@@ -488,7 +488,7 @@ def _build_stp_facts(task: ShippingNotice) -> dict[str, Any] | None:
)
status = 'candidates_frozen' if candidate_projection.get('current_set') else ''
method = 'candidate_set' if candidate_projection.get('current_set') else ''
frozen_codes = list(candidate_projection.get('candidate_source_codes') or []) or task_frozen_inventory_source_codes(owner)
frozen_codes = list(candidate_projection.get('candidate_source_codes') or []) or task_frozen_onhand_source_codes(owner)
has_stp = (
status in {'candidates_frozen', 'resolved'}
or method.startswith('stp')
@@ -503,7 +503,7 @@ def _build_stp_facts(task: ShippingNotice) -> dict[str, Any] | None:
compact_resolutions: list[dict[str, Any]] = []
resolution_source = list(candidate_projection.get('line_resolutions') or [])
if not resolution_source and getattr(owner, 'id', None) is not None:
from app.models import ShippingNoticeLineInventoryMatch
from app.models import ShippingNoticeLineOnhandMatch
resolution_source = [{
'line_index': row.line_index,
@@ -511,7 +511,7 @@ def _build_stp_facts(task: ShippingNotice) -> dict[str, Any] | None:
'disposition': row.match_result,
'effective_reservation_id': row.reservation_id,
'part_number': row.part_number,
'resolved_inventory_source_code': row.inventory_source_code,
'resolved_inventory_source_code': row.source_code,
'inventory_file_no': row.matched_file_no,
'inventory_row_index': row.matched_row_index,
'match_attempt_id': row.match_attempt_id,
@@ -519,9 +519,9 @@ def _build_stp_facts(task: ShippingNotice) -> dict[str, Any] | None:
'matched_qty': row.matched_qty or row.available_qty,
'shortage_qty': row.shortage_qty,
'inventory_row_ref': dict(row.detail_json or {}).get('inventory_row_ref'),
} for row in ShippingNoticeLineInventoryMatch.query.filter_by(
} for row in ShippingNoticeLineOnhandMatch.query.filter_by(
task_id=int(owner.id), is_current=True,
).order_by(ShippingNoticeLineInventoryMatch.line_no, ShippingNoticeLineInventoryMatch.id).all()]
).order_by(ShippingNoticeLineOnhandMatch.line_no, ShippingNoticeLineOnhandMatch.id).all()]
for item in resolution_source:
disposition = str(item.get('disposition') or 'unknown')
counts[disposition] = counts.get(disposition, 0) + 1
@@ -778,19 +778,19 @@ def _stage_capabilities_for_task(
}
if source_locked:
cap.update(disabled('excel_locked'))
elif code == 'retry_inventory_preparation':
elif code == 'retry_onhand_preparation':
# 重抓:候选源或失败源任一在场即可重试(库存文件未准备时通常走候选源)。
retry_available = has_candidates or bool(failed_codes)
cap['enabled'] = retry_available
cap['disabled_reason'] = None if retry_available else 'no_candidates'
elif code == 'override_line_inventory_source':
elif code == 'override_line_onhand_source':
cap['enabled'] = has_candidates
cap['disabled_reason'] = None if has_candidates else 'no_candidates'
elif code == 'reload_inventory_result':
elif code == 'reload_onhand_result':
has_prior = bool(resolved_codes)
cap['enabled'] = has_prior
cap['disabled_reason'] = None if has_prior else 'no_prior_result'
elif code == 'retry_inventory_matching':
elif code == 'retry_onhand_matching':
cap['enabled'] = has_match_result
cap['disabled_reason'] = None if has_match_result else 'no_match_result'
result.append(cap)
@@ -814,15 +814,15 @@ def _build_stage_context(
preparation.source_options 下发全部已启用库存源,供 Excel 未锁定时行级覆写下拉;
preparation.capabilities 由 `_stage_capabilities_for_task` 追加(点击 bypass,不进右卡渲染);
Excel/上传 Attempt 仍按入参实体(Notice 或 OT)查询;
inventory_rpa_is_running 在行循环外算一次(请求级 memo),禁止逐行查 RPA Attempt。
onhand_rpa_is_running 在行循环外算一次(请求级 memo),禁止逐行查 RPA Attempt。
"""
from app import db
from app.models import ShippingOrderSnapshot, ShippingOrderSnapshotLine, ShippingOrderTask
from app.models.shipping_excel_template import ShippingExportArtifact
from app.models.shipping_fulfillment import ShippingUploadAttempt
from app.core.errors import ConflictError
from app.services.shipping_notice.inventory_candidate_projection import get_active_candidate_lines
from app.services.shipping_notice.line_inventory_match_projection import (
from app.services.shipping_notice.onhand_candidate_projection import get_active_candidate_lines
from app.services.shipping_notice.line_onhand_match_projection import (
inventory_rpa_is_running,
load_current_match_facts_by_task,
project_line_inventory_view,
@@ -1014,27 +1014,27 @@ def _build_stage_context(
inventory_sources: list[dict[str, Any]] = []
latest_preparation = None
if getattr(order_task, 'id', None):
from app.models.shipping_inventory_preparation import ShippingInventoryPreparationAttempt
from app.models.shipping_onhand_preparation import ShippingOnhandPreparationAttempt
latest_preparation = (
ShippingInventoryPreparationAttempt.query
ShippingOnhandPreparationAttempt.query
.filter_by(task_id=int(order_task.id))
.filter(ShippingInventoryPreparationAttempt.status != 'superseded')
.order_by(ShippingInventoryPreparationAttempt.attempt_no.desc())
.filter(ShippingOnhandPreparationAttempt.status != 'superseded')
.order_by(ShippingOnhandPreparationAttempt.attempt_no.desc())
.first()
)
from app.services.shipping_notice.inventory_file_store import resolve_task_inventory_download
from app.services.shipping_notice.onhand_file_store import resolve_task_inventory_download
downloadable_inventory = resolve_task_inventory_download(order_task)
for source_attempt in (getattr(latest_preparation, 'source_attempts', None) or []):
inventory_sources.append({
'source_code': source_attempt.source_code,
'status': source_attempt.status,
'inventory_file_id': source_attempt.inventory_file_id,
'inventory_file_id': source_attempt.onhand_file_id,
})
# [STEP] 人工覆写库存源:下发全部已启用源,供前端行级下拉(override_line_inventory_source)。
from app.services.shipping_notice.inventory_source_repository import list_database_inventory_sources
from app.services.shipping_notice.onhand_source_repository import list_database_inventory_sources
source_options = [
{
@@ -1352,7 +1352,7 @@ def _process_gate_user_summary_for_task(task: ShippingNotice) -> dict[str, Any]
核心逻辑:先把 Notice 解析到 order_task_id 对应的 OT,再优先读
active_process_execution_id,回退按 OT.id 取最新非 superseded Execution;
套用 apply_post_ot_gate_rules,使 inventory_preparation 等系统等待
套用 apply_post_ot_gate_rules,使 onhand_preparation 等系统等待
不进入 current_blocking_gate。货代上传聚合的 available_actions 依赖此路径。
同一 HTTP 请求内按 task 主键 memo,避免 build_task_ui_state / resolve 等路径重复查库。