fix(shipping-notice): 修复订单阶段投影与复核冻结门禁
This commit is contained in:
1 parent
9745bb78a7
commit
44c3bd0e80
8 files changed
+259
-17
No files matched your search
@@ -1788,7 +1788,12 @@ def _handle_recheck_freeze(
|
||||
gate: ShippingProcessGate,
|
||||
payload: dict[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
"""重新评估冻结就绪;有 Task+Extraction 时走标准 Gate 评估。"""
|
||||
"""
|
||||
重新评估冻结就绪;有 OT + Extraction 时走标准 Gate 评估。
|
||||
|
||||
核心逻辑:Execution.task_id → OT;Extraction 取自 OT.current_order_extraction_id
|
||||
(禁止读不存在的 order_extraction_id)。
|
||||
"""
|
||||
from app.models import ShippingOrderExtraction, ShippingNotice
|
||||
from app.services.shipping_notice.freeze_readiness_service import evaluate_freeze_readiness_gate
|
||||
|
||||
@@ -1813,8 +1818,9 @@ def _handle_recheck_freeze(
|
||||
}
|
||||
task = _resolve_order_task(execution)
|
||||
extraction = None
|
||||
if task is not None and task.order_extraction_id:
|
||||
extraction = ShippingOrderExtraction.query.get(int(task.order_extraction_id))
|
||||
extraction_id = getattr(task, 'current_order_extraction_id', None) if task is not None else None
|
||||
if extraction_id is not None:
|
||||
extraction = ShippingOrderExtraction.query.get(int(extraction_id))
|
||||
if task is None or extraction is None:
|
||||
return {
|
||||
'outcome': 'blocked_manual',
|
||||
|
||||
@@ -6,7 +6,8 @@ services/shipping_notice/processing_projection_invariants.py
|
||||
依赖:progress_audit_contract(15 阶 / 节点态 / 动作意图词典)、logging。
|
||||
逻辑:由 shipping_processing_projection 与 order_task_stage_machine 共用;不读写数据库;
|
||||
Notice→(status,stage) 领域映射供写/读两侧;Extraction Run 完成 ≠ 全流程 completed;
|
||||
Gate 要求复核时强制 waiting_review;download_excel 依赖 excel_ready;
|
||||
Gate 要求复核时仅在未越过 waiting_review 时强制该阶(后半段不得拉回);
|
||||
download_excel 依赖 excel_ready;
|
||||
stage_nodes 可表达 invalidated_from_stage 失效;
|
||||
Notice 号与建单前 stage 不一致时 fail-closed 清空履约动作并打结构化告警。
|
||||
"""
|
||||
@@ -509,7 +510,8 @@ def reconcile_processing_projection_facts(
|
||||
在投影输出前强制 status/stage/gate/action 不变量,并写入 stage_nodes。
|
||||
|
||||
核心逻辑:
|
||||
1. Gate open_order_review → status/stage = waiting_review;
|
||||
1. Gate open_order_review → 仅当 stage 未越过 waiting_review 时强制 waiting_review;
|
||||
后半段(order_creating+)不得被拉回订单复核;
|
||||
2. status=completed ⇒ stage=completed 且清空写动作与 current_gate;
|
||||
3. stage=freight_uploading 时剔除 open_order_review;
|
||||
4. Extraction 完成但 stage 未 completed 时不得保持 status=completed;
|
||||
@@ -598,12 +600,18 @@ def reconcile_processing_projection_facts(
|
||||
gate = None
|
||||
gate_action = None
|
||||
|
||||
# [BE-04] Gate 要求进入复核 ⇒ 进度必须停在 waiting_review(不得被 completed 误伤)。
|
||||
# [BE-04] Gate 要求进入复核 ⇒ 仅当处理阶段尚未越过 waiting_review 时停在该阶。
|
||||
# 已进入 order_creating / 库存 / Excel 等后半段时,不得被陈旧 open_order_review
|
||||
# 把批次中心拉回「订单复核」(与上方 completed 分支同理)。
|
||||
if gate_action == 'open_order_review' and status != 'completed':
|
||||
status = 'waiting_review' if status not in {'failed', 'cancelled'} else status
|
||||
stage = 'waiting_review'
|
||||
if isinstance(gate, dict):
|
||||
gate = {**gate, 'next_action_code': 'open_order_review'}
|
||||
if stage_idx is None or stage_idx <= waiting_idx:
|
||||
status = 'waiting_review' if status not in {'failed', 'cancelled'} else status
|
||||
stage = 'waiting_review'
|
||||
if isinstance(gate, dict):
|
||||
gate = {**gate, 'next_action_code': 'open_order_review'}
|
||||
else:
|
||||
gate = None
|
||||
gate_action = None
|
||||
|
||||
if stage == 'freight_uploading' and gate_action == 'open_order_review':
|
||||
gate = None
|
||||
|
||||
@@ -1501,7 +1501,8 @@ def _order_task_current_gate(
|
||||
|
||||
核心逻辑:优先开放 Review Case 上的真实 ProcessExecution;其次 OT 活跃 Execution
|
||||
(含尚未创建 Notice 的履约门禁,如库存满足性);无 Execution 时回退 Run·OT
|
||||
失败/waiting_review 合成摘要;处理中不造假门禁。
|
||||
失败/waiting_review 合成摘要——但 OT.stage 已越过 waiting_review 时禁止再合成
|
||||
open_order_review;处理中不造假门禁。
|
||||
|
||||
Args:
|
||||
run: Processing Run。
|
||||
@@ -1567,6 +1568,17 @@ def _order_task_current_gate(
|
||||
# 外层单独透传完整摘要;current_gate 保持轻量展示形状。
|
||||
'_process_gate_summary': summary,
|
||||
}
|
||||
# 开放 Case 无 Execution:仅当 OT 仍停在复核及以前才合成 open_order_review。
|
||||
# OT.stage 已进入 order_creating+ 时禁止伪造,避免 BE-04 拉回「订单复核」。
|
||||
if order_task is not None:
|
||||
from app.services.shipping_notice.processing_projection_invariants import (
|
||||
shipping_processing_stage_index,
|
||||
)
|
||||
ot_stage = str(getattr(order_task, 'stage', None) or '').strip().lower()
|
||||
ot_stage_idx = shipping_processing_stage_index(ot_stage)
|
||||
waiting_idx = shipping_processing_stage_index('waiting_review') or 8
|
||||
if ot_stage_idx is not None and ot_stage_idx > waiting_idx:
|
||||
return None
|
||||
return {
|
||||
'gate_code': 'order_freeze_readiness',
|
||||
'status': 'blocked',
|
||||
@@ -1607,6 +1619,16 @@ def _order_task_current_gate(
|
||||
'attempt_no': 0,
|
||||
}
|
||||
if status in {'review_required', 'waiting_review', 'pending_review'}:
|
||||
# OT.status 可能仍停在 waiting_review,但 stage 已推进到 order_creating+。
|
||||
# 禁止再合成 open_order_review,否则 BE-04 会把五阶段拉回「订单复核」。
|
||||
from app.services.shipping_notice.processing_projection_invariants import (
|
||||
shipping_processing_stage_index,
|
||||
)
|
||||
ot_stage = str(getattr(order_task, 'stage', None) or '').strip().lower()
|
||||
ot_stage_idx = shipping_processing_stage_index(ot_stage)
|
||||
waiting_idx = shipping_processing_stage_index('waiting_review') or 8
|
||||
if ot_stage_idx is not None and ot_stage_idx > waiting_idx:
|
||||
return None
|
||||
return {
|
||||
'gate_code': 'order_freeze_readiness',
|
||||
'status': 'blocked',
|
||||
|
||||
@@ -9,6 +9,8 @@ services/shipping_notice/ui_state.py
|
||||
order_review_workbench_projection、inventory_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 列),
|
||||
禁止仅靠 Gate 兜底把 order_freeze 误映射为订单复核;
|
||||
stage_context.preparation 以 Snapshot 行 + 当前 Match 投影(Notice 经 order_task_id→OT),
|
||||
行级拆 selected_source_code(CandidateSet 取数目标)与 source_code(Match 正式源);
|
||||
短缺行复用放行模板字段;匹配成功无短缺下发 can_fulfill_complete_line;
|
||||
@@ -106,10 +108,23 @@ _PAUSE_REASON_BY_POSITION: dict[str, tuple[str, str]] = {
|
||||
def _task_lifecycle(
|
||||
*, task: ShippingNotice, position: str | None, process_gate: dict[str, Any] | None,
|
||||
) -> dict[str, Any]:
|
||||
"""以共享裁决器投影正式任务生命周期;缺少正式事实时保持未分类。"""
|
||||
"""以共享裁决器投影正式任务生命周期;缺少正式事实时保持未分类。
|
||||
|
||||
核心逻辑:``processing_stage`` 与批次/工作台同源——优先实体 ``stage``,
|
||||
Notice 无 stage 列时经 ``order_task_id`` 读 OT.stage;再用正式 Gate 做
|
||||
**仅向前**抬升(与 reconcile BE-08 / sync_order_task_stage_for_notice 同表)。
|
||||
``order_freeze_readiness`` 不在抬升表中,故不能把 OT.stage=order_creating
|
||||
压回「订单复核」。
|
||||
"""
|
||||
del position # 生命周期不再由位置码推导。
|
||||
gate = (process_gate or {}).get('current_blocking_gate') or (process_gate or {}).get('current_gate')
|
||||
from app.services.shipping_notice.upload_attempt_service import has_verified_upload_success
|
||||
from app.services.shipping_notice.processing_projection_invariants import (
|
||||
shipping_processing_stage_index,
|
||||
)
|
||||
from app.services.shipping_notice.order_task_stage_machine import (
|
||||
_PROCESS_GATE_TO_PROCESSING_STAGE,
|
||||
)
|
||||
|
||||
# 有正式 Gate 或已验证上传时才开放五阶段入口;否则保持 unclassified(禁止旧 CP 冒充)。
|
||||
has_formal = bool(
|
||||
@@ -120,6 +135,24 @@ def _task_lifecycle(
|
||||
or process_gate.get('current_gate')
|
||||
)
|
||||
)
|
||||
# [STEP 1] Notice 无 stage 列;进度权威在 OT。
|
||||
processing_stage = str(getattr(task, 'stage', None) or '').strip() or None
|
||||
if not processing_stage:
|
||||
order_task = _resolve_order_task_for_gate_lookup(task)
|
||||
if order_task is not None:
|
||||
processing_stage = str(getattr(order_task, 'stage', None) or '').strip() or None
|
||||
# [STEP 2] Gate→15 阶仅向前抬升;禁止 freeze 等建单前 Gate 回拉后半段。
|
||||
gate_code = ''
|
||||
if isinstance(gate, dict):
|
||||
gate_code = str(gate.get('gate_code') or gate.get('code') or '').strip().lower()
|
||||
if not gate_code and isinstance(process_gate, dict):
|
||||
gate_code = str(process_gate.get('current_gate_code') or '').strip().lower()
|
||||
gate_as_stage = _PROCESS_GATE_TO_PROCESSING_STAGE.get(gate_code)
|
||||
if gate_as_stage:
|
||||
stage_idx = shipping_processing_stage_index(processing_stage)
|
||||
gate_idx = shipping_processing_stage_index(gate_as_stage)
|
||||
if stage_idx is None or (gate_idx is not None and gate_idx >= stage_idx):
|
||||
processing_stage = gate_as_stage
|
||||
return project_lifecycle(
|
||||
current_gate=gate if isinstance(gate, dict) else None,
|
||||
blocking_reason=(
|
||||
@@ -129,7 +162,7 @@ def _task_lifecycle(
|
||||
),
|
||||
has_candidate_context=has_formal or has_verified_upload_success(task),
|
||||
verified_upload_success=has_verified_upload_success(task),
|
||||
processing_stage=getattr(task, 'stage', None),
|
||||
processing_stage=processing_stage,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user