feat(shipping-notice): 通知准备履约字段就地编辑并修复缺口复核入口
- 编辑闸门翻转为状态制:Excel 生成前+无活动 Attempt 即可编辑,原因不强制(审计自动记录操作人与变更) - 修复 Decimal 字段人工编辑无法持久化(单字段+整行替换两路径) - 预约注册与核验比对改读有效订单值视图,消除编辑后重匹配 RESERVATION_MISMATCH 阻断 - 通知准备值列改读有效视图:保存即显新值,匹配结果列保持最近一轮事实 - 行编辑入口为更多操作列编辑按钮;编辑态替换为保存/取消;库存源行内改选随保存统一提交 - 展示态动作收纳进更多菜单(Teleport 浮层,防表格 overflow 裁剪) - 修复缺口复核投影键错位(has_shortage 恒 False 致入口隐藏)并补齐行级结案入口 - 缺口放行改行内补录条(菜单放行或缺 N 项徽标展开,确认放行/取消收起),放行原因可选 - i18n 四语言;technical.md/funclist.md 语义文档同步
This commit is contained in:
1 parent
4d879dd8ea
commit
eed1068ae3
29 files changed
+1981
-218
No files matched your search
@@ -508,6 +508,26 @@ def load_current_match_facts_by_task(task_id: int | None) -> dict[int, dict[str,
|
||||
return out
|
||||
|
||||
|
||||
def load_current_match_facts_by_line_index(task_id: int | None) -> dict[int, dict[str, Any]]:
|
||||
"""按 line_index 索引当前匹配事实(Case 履约投影专用)。
|
||||
|
||||
核心逻辑:与 load_current_match_facts_by_task 同一查询;Case 草稿行只有
|
||||
_line_index 没有 snapshot_line_id,必须按行号索引才能关联上事实。
|
||||
"""
|
||||
if task_id is None:
|
||||
return {}
|
||||
rows = (
|
||||
ShippingNoticeLineInventoryMatch.query
|
||||
.filter_by(task_id=int(task_id), is_current=True)
|
||||
.all()
|
||||
)
|
||||
return {
|
||||
int(row.line_index): serialize_match_fact(row)
|
||||
for row in rows
|
||||
if row.line_index is not None
|
||||
}
|
||||
|
||||
|
||||
def aggregate_match_status_for_task(task_id: int | None) -> str | None:
|
||||
"""根据当前行级 Match 聚合任务匹配状态,禁止读取 OT/Notice 缓存字段。"""
|
||||
facts = list(load_current_match_facts_by_task(task_id).values())
|
||||
|
||||
@@ -771,7 +771,6 @@ def project_review_case_line_decisions(
|
||||
"""
|
||||
from app.services.shipping_notice.line_inventory_match_projection import (
|
||||
line_auto_fulfill_enabled,
|
||||
load_current_match_facts_by_task,
|
||||
project_line_inventory_view,
|
||||
)
|
||||
from app.services.shipping_notice.order_review_workbench_projection import (
|
||||
@@ -818,7 +817,11 @@ def project_review_case_line_decisions(
|
||||
'status': 'resolving',
|
||||
'source': 'inventory_source_clue',
|
||||
}
|
||||
match_facts = load_current_match_facts_by_task(formal_ot.get('task_id'))
|
||||
# [BE-键修复] Case 草稿行只有 _line_index;补一条按行号索引的事实通道。
|
||||
from app.services.shipping_notice.line_inventory_match_projection import (
|
||||
load_current_match_facts_by_line_index,
|
||||
)
|
||||
match_facts_by_line = load_current_match_facts_by_line_index(formal_ot.get('task_id'))
|
||||
labels = dict(source_labels or {})
|
||||
if not labels:
|
||||
draft = getattr(case, 'current_draft', None)
|
||||
@@ -843,7 +846,12 @@ def project_review_case_line_decisions(
|
||||
decision = by_key.get(key)
|
||||
# 正式 OT 的库存数量以当前行匹配事实为准;草稿 validation_result 只保留
|
||||
# 解析阶段投影,不能因为其中没有 available_qty 就错误阻断人工出单。
|
||||
fact = match_facts.get(key)
|
||||
# [BE-键修复] 草稿行只有 _line_index;旧实现误用 draft_line_id 查 snapshot_line_id 键,恒 miss。
|
||||
line_index = draft_line.get('_line_index')
|
||||
fact = (
|
||||
match_facts_by_line.get(int(line_index))
|
||||
if line_index is not None else None
|
||||
)
|
||||
fact_detail = dict((fact or {}).get('detail_json') or {}) if isinstance(fact, dict) else {}
|
||||
fulfill_proj = dict(proj)
|
||||
if isinstance(fact, dict):
|
||||
@@ -1091,7 +1099,7 @@ def decide_review_line_fulfillment(
|
||||
case_no: Case 编号。
|
||||
draft_line_id: 草稿行键。
|
||||
decision_code: 决定码。
|
||||
reason: 关闭/重开/短缺放行必填原因。
|
||||
reason: 关闭/重开必填原因;短缺放行可选(人工放行事实由审计链记录)。
|
||||
release_field_values: 短缺放行时模板行级库存字段的人工补录值。
|
||||
expected_draft_version: 可选草稿乐观锁。
|
||||
actor_is_admin: 是否管理员(重开授权)。
|
||||
@@ -1106,7 +1114,9 @@ def decide_review_line_fulfillment(
|
||||
code='SHIPPING.REVIEW_LINE_DECISION_INVALID',
|
||||
details={'decision_code': code},
|
||||
)
|
||||
if code in {DECISION_CLOSE, DECISION_REOPEN, DECISION_RELEASE_SHORTAGE} and not str(reason or '').strip():
|
||||
# [BE-放行免因] 短缺放行不强制原因:人工放行事实已由审计链完整记录
|
||||
# (操作人 + 时间 + 决定快照 release_field_values);结案/重开仍要求原因。
|
||||
if code in {DECISION_CLOSE, DECISION_REOPEN} and not str(reason or '').strip():
|
||||
raise ValidationError(
|
||||
'Reason is required',
|
||||
code='SHIPPING.REVIEW_LINE_DECISION_REASON_REQUIRED',
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
services/shipping_notice/reservation_service.py
|
||||
|
||||
用途:管理冻结订单预约单的注册、库存核验轮次和滚动制单占用。
|
||||
依赖:ShippingOrderSnapshot、履约 ORM、统一 AppError。
|
||||
逻辑:每轮核验追加记录;只有本轮全部满足的预约单可被同一事务选择并绑定到一个新 Artifact。
|
||||
依赖:ShippingOrderSnapshot、effective_order_view(有效订单值视图)、履约 ORM、统一 AppError。
|
||||
逻辑:预约身份按「冻结快照 + 冻结后已接受人工修正」的有效值注册;每轮核验追加记录;
|
||||
只有本轮全部满足的预约单可被同一事务选择并绑定到一个新 Artifact。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -40,17 +41,37 @@ def _decimal(value: Any) -> Decimal:
|
||||
|
||||
|
||||
def ensure_task_reservations(task: ShippingOrderTask) -> list[ShippingReservation]:
|
||||
"""由冻结 Snapshot 注册全局预约号;同 PO 的变更只能作为人工修订候选。"""
|
||||
"""
|
||||
由有效订单视图(冻结快照 + 已接受人工修正)注册全局预约号;同 PO 的料号/数量
|
||||
变更按同一 OT 确认修订自动接替,跨任务或已占用预约仍走人工复核/锁定拒绝。
|
||||
|
||||
核心逻辑:预约身份(预约号/料号/数量)以 effective_line_facts_for_notice 的有效值为准;
|
||||
否则就地编辑料号/数量后,重匹配写入的有效值与按冻结列注册的预约不一致,
|
||||
核验比对必抛 RESERVATION_MISMATCH 使核验轮次无法创建、任务卡死。
|
||||
行集替换等无法按行对位的场景(ValueError)保守回退冻结快照列,
|
||||
由行集有效视图特性统一承接。
|
||||
"""
|
||||
snapshot = db.session.get(ShippingOrderSnapshot, task.order_snapshot_id) if task.order_snapshot_id else None
|
||||
if snapshot is None:
|
||||
raise ValidationError('Frozen order snapshot is required', code='SHIPPING.ORDER_SNAPSHOT_REQUIRED')
|
||||
po_number = normalize_po_number(snapshot.customer_po_number).upper()
|
||||
# [BE-有效视图] 延迟导入避免与 export 的模块级循环依赖(export 反向惰性引用本模块)。
|
||||
from app.services.shipping_notice.effective_order_view import effective_line_facts_for_notice
|
||||
try:
|
||||
effective_facts = effective_line_facts_for_notice(task)
|
||||
except ValueError:
|
||||
effective_facts = {}
|
||||
registered: list[ShippingReservation] = []
|
||||
seen: set[str] = set()
|
||||
for line in snapshot.lines:
|
||||
reservation_id = validated_reservation_id(line.reservation_id)
|
||||
part_number = str(line.part_number or '').strip()
|
||||
if not reservation_id or not part_number or line.qty is None:
|
||||
eff = effective_facts.get(int(line.id)) or {}
|
||||
# 有效事实优先,None(无规则映射/值非法)回退冻结快照列。
|
||||
effective_reservation_id = eff.get('reservation_id') if eff.get('reservation_id') is not None else line.reservation_id
|
||||
effective_part_number = eff.get('part_number') if eff.get('part_number') is not None else line.part_number
|
||||
effective_qty = eff.get('qty') if eff.get('qty') is not None else line.qty
|
||||
reservation_id = validated_reservation_id(effective_reservation_id)
|
||||
part_number = str(effective_part_number or '').strip()
|
||||
if not reservation_id or not part_number or effective_qty is None:
|
||||
raise ValidationError('Reservation id, part number and quantity are required', code='SHIPPING.RESERVATION_INVALID')
|
||||
if reservation_id in seen:
|
||||
raise ConflictError('Reservation is duplicated in the frozen order', code='SHIPPING.RESERVATION_DUPLICATED_IN_ORDER')
|
||||
@@ -59,7 +80,7 @@ def ensure_task_reservations(task: ShippingOrderTask) -> list[ShippingReservatio
|
||||
if row is None:
|
||||
row = ShippingReservation(
|
||||
task_id=task.id, snapshot_line_id=line.id, reservation_id=reservation_id,
|
||||
po_number_normalized=po_number, part_number=part_number, required_qty=_decimal(line.qty), status='pending',
|
||||
po_number_normalized=po_number, part_number=part_number, required_qty=_decimal(effective_qty), status='pending',
|
||||
)
|
||||
db.session.add(row)
|
||||
elif not po_number:
|
||||
@@ -77,15 +98,16 @@ def ensure_task_reservations(task: ShippingOrderTask) -> list[ShippingReservatio
|
||||
row.task_id != task.id
|
||||
or row.snapshot_line_id != line.id
|
||||
or row.part_number != part_number
|
||||
or row.required_qty != _decimal(line.qty)
|
||||
or row.required_qty != _decimal(effective_qty)
|
||||
):
|
||||
if row.current_artifact_id is not None or row.status in {'artifact_reserved', 'uploaded'}:
|
||||
raise ConflictError('Reservation cannot be revised after export or upload', code='SHIPPING.RESERVATION_REVISION_LOCKED')
|
||||
if row.part_number != part_number or row.required_qty != _decimal(line.qty):
|
||||
if row.part_number != part_number or row.required_qty != _decimal(effective_qty):
|
||||
# 同一 OT 的确认修订复用该 OT(仅 bump order_data_version/progress_version),
|
||||
# Reservation 与审计事件仍指向该 OT,不新建任务;跨任务变更须人工复核。
|
||||
# [BE-有效视图] 编辑料号/数量后的差异在此自动完成接替,核验得以继续。
|
||||
if row.task_id == task.id:
|
||||
_transfer_confirmed_revision(row, task=task, line=line, part_number=part_number)
|
||||
_transfer_confirmed_revision(row, task=task, line=line, part_number=part_number, qty=effective_qty)
|
||||
registered.append(row)
|
||||
continue
|
||||
raise ConflictError(
|
||||
@@ -95,7 +117,7 @@ def ensure_task_reservations(task: ShippingOrderTask) -> list[ShippingReservatio
|
||||
'reservation_id': reservation_id,
|
||||
'registered_task_id': row.task_id,
|
||||
'previous': {'part_number': row.part_number, 'qty': str(row.required_qty)},
|
||||
'proposed': {'part_number': part_number, 'qty': str(_decimal(line.qty))},
|
||||
'proposed': {'part_number': part_number, 'qty': str(_decimal(effective_qty))},
|
||||
},
|
||||
)
|
||||
raise ConflictError('Reservation is already registered by another order version', code='SHIPPING.RESERVATION_ALREADY_REGISTERED')
|
||||
@@ -120,12 +142,20 @@ def _transfer_confirmed_revision(
|
||||
*, task: ShippingOrderTask,
|
||||
line: Any,
|
||||
part_number: str,
|
||||
qty: Any | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
同一 OT 的已确认修订:复用该 OT(版本 bump),接替未履约 Reservation,并落 OT 级审计。
|
||||
|
||||
核心逻辑:修订不新建任务行;仅递增 ``order_data_version`` / ``progress_version``,
|
||||
Reservation 与 ShippingTaskEvent 均保持指向该 OT,避免写入 Notice id 造成错误外键。
|
||||
|
||||
Args:
|
||||
reservation: 待接替的未履约预约单。
|
||||
task: 当前归属 OT(或可解析到 OT 的任务)。
|
||||
line: 预约对应的冻结快照行(修订后 snapshot_line_id 仍指向该行)。
|
||||
part_number: 有效料号(已 strip)。
|
||||
qty: 有效数量;缺省时回退冻结行数量 ``line.qty``(供既有调用方兼容)。
|
||||
"""
|
||||
owner = _owner_task(task)
|
||||
previous = {
|
||||
@@ -140,7 +170,8 @@ def _transfer_confirmed_revision(
|
||||
reservation.task_id = owner.id
|
||||
reservation.snapshot_line_id = line.id
|
||||
reservation.part_number = part_number
|
||||
reservation.required_qty = _decimal(line.qty)
|
||||
# [BE-有效视图] 数量以有效值为准;行集替换等回退场景沿用冻结行数量。
|
||||
reservation.required_qty = _decimal(qty if qty is not None else line.qty)
|
||||
reservation.status = 'pending'
|
||||
reservation.current_artifact_id = None
|
||||
details = {
|
||||
@@ -175,11 +206,13 @@ def record_inventory_verification(
|
||||
reservation_id = validated_reservation_id(item.get('reservation_id'))
|
||||
part_number = str(item.get('part_number') or '').strip()
|
||||
reservation = by_key.get(reservation_id)
|
||||
if reservation is None or reservation.part_number != part_number:
|
||||
# [BE-有效视图] 料号比对两侧归一化(strip + upper):匹配结果与注册值可能仅存在
|
||||
# 大小写/空白差异,直接比较会造成假阳性 RESERVATION_MISMATCH 阻断核验。
|
||||
if reservation is None or str(reservation.part_number or '').strip().upper() != str(part_number or '').strip().upper():
|
||||
raise ValidationError('Inventory result does not map to a frozen reservation', code='SHIPPING.RESERVATION_MISMATCH')
|
||||
required = _decimal(item.get('required_qty'))
|
||||
# The frozen order is the quantity authority. A reduced or duplicate result
|
||||
# must not turn an insufficient reservation into an exportable line.
|
||||
# [BE-有效视图] 数量权威是按有效订单值视图注册的预约值(非冻结快照列);
|
||||
# 缩量/重复的核验结果不得把短缺行升级为可导出行。
|
||||
if reservation_id in seen_reservation_ids or required != reservation.required_qty:
|
||||
raise ValidationError('Inventory result quantity is inconsistent with the frozen reservation', code='SHIPPING.RESERVATION_MISMATCH')
|
||||
seen_reservation_ids.add(reservation_id)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
"""
|
||||
services/shipping_notice/schema_edit_policy.py
|
||||
|
||||
用途:正式任务字段编辑策略(Schema 显式放行;无策略默认只读;Excel ready 硬冻结)。
|
||||
用途:正式任务字段编辑策略(状态制:无策略默认可写;显式 editable=False 反向锁;Excel ready 硬冻结)。
|
||||
依赖:task_order_field_editor(锁定 Schema)、ShippingExportArtifact、ConflictError;
|
||||
被 task_workflow / 复核 formal patch / 投影 formal_editable_field_ids 引用。
|
||||
逻辑:默认 editable_after_task_creation=False;仅 Schema editable=True 可写;
|
||||
Excel ready = ready Artifact 匹配路径 + 可选 order_data_version 指纹;
|
||||
change_effect 供 task_workflow 下游失效编排消费。不考虑 legacy 白名单兼容绕过。
|
||||
逻辑:默认 editable_after_task_creation=True(建单后 Excel 生成前可编辑);
|
||||
仅 Schema 显式 editable=False 反向关闭;Excel ready = ready Artifact 匹配路径 +
|
||||
可选 order_data_version 指纹;change_effect 供 task_workflow 下游失效编排消费。
|
||||
不考虑 legacy 白名单兼容绕过。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -18,8 +19,8 @@ from app.core.errors import ConflictError
|
||||
if TYPE_CHECKING:
|
||||
from app.models import ShippingNotice
|
||||
|
||||
# 默认:创建正式任务后字段不可编辑。
|
||||
DEFAULT_EDITABLE_AFTER_TASK_CREATION: Final[bool] = False
|
||||
# 默认:建单后 Excel 生成前字段可编辑(状态制);个别字段需要锁定时在 Schema 配置 editable=false 反向关闭。
|
||||
DEFAULT_EDITABLE_AFTER_TASK_CREATION: Final[bool] = True
|
||||
|
||||
# 允许的 change_effect。
|
||||
ALLOWED_CHANGE_EFFECTS: Final[frozenset[str]] = frozenset({
|
||||
@@ -36,7 +37,7 @@ _AUDIT_VALUE_MAX_CHARS: Final[int] = 256
|
||||
|
||||
def field_task_edit_policy(field_config: dict[str, Any] | None) -> dict[str, Any]:
|
||||
"""
|
||||
读取 Schema 字段上的 task_edit_policy;缺省返回安全只读策略。
|
||||
读取 Schema 字段上的 task_edit_policy;无策略时按状态制默认(Excel ready 前可写)。
|
||||
|
||||
Args:
|
||||
field_config: Schema 单字段配置。
|
||||
@@ -46,7 +47,8 @@ def field_task_edit_policy(field_config: dict[str, Any] | None) -> dict[str, Any
|
||||
"""
|
||||
raw = field_config.get('task_edit_policy') if isinstance(field_config, dict) else None
|
||||
policy = dict(raw) if isinstance(raw, dict) else {}
|
||||
editable = bool(policy.get('editable')) if policy else False
|
||||
# 无策略时初始化为全局默认开关;显式 editable=false 的反向锁优先于默认值。
|
||||
editable = bool(policy.get('editable')) if policy else DEFAULT_EDITABLE_AFTER_TASK_CREATION
|
||||
if not DEFAULT_EDITABLE_AFTER_TASK_CREATION and 'editable' not in policy:
|
||||
editable = False
|
||||
effect = str(policy.get('change_effect') or 'none').strip() or 'none'
|
||||
@@ -98,7 +100,8 @@ def is_field_editable_for_formal_task(
|
||||
"""
|
||||
判断正式任务下该字段是否可编辑。
|
||||
|
||||
核心逻辑:Excel ready 时一律不可编辑;否则必须 Schema 显式 editable=True;
|
||||
核心逻辑:Excel ready 时一律不可编辑;否则按状态制默认可写,
|
||||
仅 Schema 显式 editable=False 反向关闭;
|
||||
若 editable_until=excel_ready 且 Excel 已就绪则关闭(与全局冻结一致)。
|
||||
|
||||
Args:
|
||||
@@ -182,7 +185,7 @@ def is_formal_field_code_editable(
|
||||
"""
|
||||
判断正式任务下 field_code 是否允许写入。
|
||||
|
||||
核心逻辑:仅 Schema 显式 editable=True 且未 Excel 冻结时放行;无 legacy 白名单。
|
||||
核心逻辑:未 Excel 冻结时按状态制默认放行,仅 Schema 显式 editable=False 反向关闭;无 legacy 白名单。
|
||||
|
||||
Args:
|
||||
task: 目标 ShippingNotice。
|
||||
|
||||
@@ -9,6 +9,7 @@ services/shipping_notice/task_order_field_editor.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from decimal import Decimal, InvalidOperation
|
||||
from typing import Any
|
||||
|
||||
@@ -177,6 +178,19 @@ def _normalized_value(value: Any, config: dict[str, Any]) -> Any:
|
||||
return str(value).strip()
|
||||
|
||||
|
||||
def _json_value(value: Any) -> Any:
|
||||
"""把人工输入转为 JSON 列可序列化形状;与 order_schema.runtime._json_value 对齐。
|
||||
|
||||
核心逻辑:Decimal → format(normalize, 'f') 字符串(保留精度且 json.dumps 可序列化),
|
||||
date → isoformat;其余原样。类型化列(value_decimal 等)仍保存原生值。
|
||||
"""
|
||||
if isinstance(value, Decimal):
|
||||
return format(value.normalize(), 'f')
|
||||
if isinstance(value, date):
|
||||
return value.isoformat()
|
||||
return value
|
||||
|
||||
|
||||
def _field_value_columns(value: Any, value_type: str) -> dict[str, Any]:
|
||||
"""生成唯一 FieldValue 的类型化列,JSON 值始终作为下游读取的统一入口。"""
|
||||
return {
|
||||
@@ -185,7 +199,7 @@ def _field_value_columns(value: Any, value_type: str) -> dict[str, Any]:
|
||||
'value_integer': value if value_type == 'integer' else None,
|
||||
'value_date': value if value_type == 'date' else None,
|
||||
'value_boolean': value if value_type == 'boolean' else None,
|
||||
'value_json': value,
|
||||
'value_json': _json_value(value),
|
||||
}
|
||||
|
||||
|
||||
@@ -222,7 +236,7 @@ def replace_current_line_field_value(*, task: ShippingNotice, position: int, fie
|
||||
raise ConflictError('Order field decision is unavailable', code='SHIPPING.ORDER_FIELD_EDIT_BLOCKED')
|
||||
# 人工复核后的值成为当前决策真相,保留原 Observation 与冲突审计链。
|
||||
decision.decision_status = 'accepted'
|
||||
decision.resolved_value_json = normalized
|
||||
decision.resolved_value_json = _json_value(normalized)
|
||||
columns = _field_value_columns(normalized, str(config.get('value_type') or 'string'))
|
||||
if field_value is None:
|
||||
field_value = ShippingOrderFieldValue(
|
||||
@@ -264,7 +278,7 @@ def replace_current_header_field_value(*, task: ShippingNotice, field_code: str,
|
||||
if decision is None:
|
||||
raise ConflictError('Order header decision is unavailable', code='SHIPPING.ORDER_FIELD_EDIT_BLOCKED')
|
||||
decision.decision_status = 'accepted'
|
||||
decision.resolved_value_json = normalized
|
||||
decision.resolved_value_json = _json_value(normalized)
|
||||
columns = _field_value_columns(normalized, str(config.get('value_type') or 'string'))
|
||||
if field_value is None:
|
||||
db.session.add(ShippingOrderFieldValue(
|
||||
@@ -349,7 +363,7 @@ def replace_current_line_fields(*, task: ShippingNotice, lines: list[dict[str, A
|
||||
line_id=line.id,
|
||||
field_id=str(config['field_id']),
|
||||
decision_status='accepted' if value is not None else 'missing',
|
||||
resolved_value_json=value,
|
||||
resolved_value_json=_json_value(value),
|
||||
supporting_observation_ids_json=[],
|
||||
reason_code='human_line_set' if value is not None else 'missing',
|
||||
)
|
||||
|
||||
@@ -920,7 +920,8 @@ def _commit_notice_edit(
|
||||
reviewed_by_id = review_context.get('reviewed_by_id')
|
||||
evidence_ref = str(review_context.get('evidence_ref') or '')
|
||||
reason = str(review_context.get('reason') or '')
|
||||
if not reviewed_by_id or not evidence_ref or not reason:
|
||||
# 仅操作人身份是审计底线;reason/evidence_ref 已由 _prepare_review_context 哨兵兜底。
|
||||
if not reviewed_by_id:
|
||||
raise ConflictError('Review evidence is required', code='SHIPPING.ORDER_REVIEW_EVIDENCE_REQUIRED')
|
||||
# [STEP 1] 人工编辑后的业务值拥有最终优先级,但仍必须通过同一流程字段契约。
|
||||
order_task = _resolve_order_task_for_notice(task)
|
||||
@@ -1029,7 +1030,7 @@ def _commit_notice_edit(
|
||||
|
||||
|
||||
def _prepare_review_context(task: ShippingNotice, payload: dict[str, Any]) -> tuple[dict[str, Any] | None, dict[str, Any] | None]:
|
||||
"""校验正式编辑的操作者、证据和原因;Excel ready 后拒绝写入。"""
|
||||
"""校验正式编辑的操作者身份;reason/evidence 可缺省并落哨兵值;Excel ready 后拒绝写入。"""
|
||||
from app.services.shipping_notice.schema_edit_policy import assert_formal_task_not_excel_frozen
|
||||
|
||||
try:
|
||||
@@ -1050,14 +1051,18 @@ def _prepare_review_context(task: ShippingNotice, payload: dict[str, Any]) -> tu
|
||||
actor_id = int(payload.get('reviewed_by_id'))
|
||||
except (TypeError, ValueError):
|
||||
return None, tool_response(status='failed', task=task, message='缺少复核人员', data={'error_code': 'SHIPPING.ORDER_REVIEW_EVIDENCE_REQUIRED'})
|
||||
reason = str(payload.get('reason') or payload.get('comment') or '').strip()
|
||||
if not reason:
|
||||
return None, tool_response(status='failed', task=task, message='人工纠错必须提供证据和原因', data={'error_code': 'SHIPPING.ORDER_REVIEW_EVIDENCE_REQUIRED'})
|
||||
# 快捷就地编辑不强制填写原因/证据:审计链自动记录 old→new + 操作人 + 时间;
|
||||
# 提供了证据时仍走原校验。哨兵值满足 shipping_order_review_events 的 NOT NULL 列。
|
||||
reason = str(payload.get('reason') or payload.get('comment') or '').strip() or 'quick_field_edit'
|
||||
from app.services.shipping_notice.review_evidence_service import validate_review_evidence
|
||||
try:
|
||||
evidence_ref = validate_review_evidence(task=task, evidence=payload.get('evidence'), reason=reason)
|
||||
except ValidationError as exc:
|
||||
return None, tool_response(status='failed', task=task, message='人工纠错证据无效', data={'error_code': exc.code})
|
||||
evidence = payload.get('evidence') or None
|
||||
if evidence is not None:
|
||||
try:
|
||||
evidence_ref = validate_review_evidence(task=task, evidence=evidence, reason=reason)
|
||||
except ValidationError as exc:
|
||||
return None, tool_response(status='failed', task=task, message='人工纠错证据无效', data={'error_code': exc.code})
|
||||
else:
|
||||
evidence_ref = 'inline:match-table'
|
||||
return {'reviewed_by_id': actor_id, 'evidence_ref': evidence_ref, 'reason': reason}, None
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ services/shipping_notice/ui_state.py
|
||||
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),
|
||||
stage_context.preparation 值列(预约号/料号/需求数量)有效值优先(快照 + 已接受修正,
|
||||
经 effective_line_facts_for_notice),无有效值时回退快照列;匹配结果列仍以 Snapshot 行
|
||||
+ 当前 Match 投影诚实反映最近一轮(Notice 经 order_task_id→OT),
|
||||
行级拆 selected_source_code(CandidateSet 取数目标)与 source_code(Match 正式源);
|
||||
短缺行复用放行模板字段;匹配成功无短缺下发 can_fulfill_complete_line;
|
||||
下发 source_options 与 capabilities(阶段能力,供右卡点击 stageCapabilityBypass);
|
||||
@@ -830,6 +832,7 @@ def _build_stage_context(
|
||||
_shortage_release_required_fields,
|
||||
)
|
||||
from app.services.shipping_notice.upload_attempt_service import latest_export_artifact
|
||||
from app.services.shipping_notice.effective_order_view import effective_line_facts_for_notice
|
||||
|
||||
facts = stp_facts if isinstance(stp_facts, dict) else {}
|
||||
# [STEP 1] Snapshot/Match/Candidate 归属 OT;Notice 详情入口必须经 order_task_id 解析,
|
||||
@@ -846,6 +849,19 @@ def _build_stage_context(
|
||||
if snapshot is not None else []
|
||||
)
|
||||
match_by_snapshot_line_id = load_current_match_facts_by_task(getattr(order_task, 'id', None))
|
||||
# [BE-有效视图] 值列消费有效订单值(快照 + 已接受修正):保存即显新值,
|
||||
# 匹配结果列仍读当前匹配事实,诚实反映最近一轮匹配结论。
|
||||
# 全循环只算一次,行内按 snapshot_line_id 取用;无冻结快照(如未绑定 OT 的 Notice)
|
||||
# 保持空映射,行级回退快照列。有效视图解析失败(如历史/合成数据缺 Schema 版本)
|
||||
# 与 ODM 投影同款降级:不阻断工作台渲染,值列退回快照列(此时有效值=快照值)。
|
||||
effective_facts: dict[int, dict[str, Any]] = {}
|
||||
if order_task is not None and getattr(order_task, 'order_snapshot_id', None):
|
||||
try:
|
||||
effective_facts = effective_line_facts_for_notice(order_task)
|
||||
except Exception: # 遗留/合成快照缺 Schema 版本等:回退冻结列展示
|
||||
from flask import current_app
|
||||
current_app.logger.warning('effective order view resolution failed; falling back to frozen columns', exc_info=True)
|
||||
effective_facts = {}
|
||||
# [STEP] 与 Case 投影同源:库存 RPA 运行态只查一次 Attempt(请求内 memo),再传入各行纯函数。
|
||||
inventory_rpa_running = inventory_rpa_is_running(order_task)
|
||||
candidate_codes_by_line_no: dict[int, list[str]] = {}
|
||||
@@ -869,17 +885,38 @@ def _build_stage_context(
|
||||
for snapshot_line in snapshot_lines:
|
||||
qty_text = str(snapshot_line.qty) if snapshot_line.qty is not None else None
|
||||
line_no = int(snapshot_line.line_no) if snapshot_line.line_no is not None else None
|
||||
# [BE-有效视图] 冻结订单行值列有效值优先(预约号/料号/需求数量):行内按
|
||||
# snapshot_line_id 取有效事实,取不到(None)时回退冻结快照列;键名与前端
|
||||
# 契约稳定不动(shipping.api.types.ts ShippingOrderFrozenLine)。
|
||||
eff = effective_facts.get(int(snapshot_line.id)) or {}
|
||||
frozen_order_lines.append({
|
||||
'snapshot_line_id': int(snapshot_line.id),
|
||||
'line_no': line_no,
|
||||
'reservation_id': snapshot_line.reservation_id,
|
||||
'part_number': snapshot_line.part_number,
|
||||
'required_qty': qty_text,
|
||||
'reservation_id': eff.get('reservation_id') if eff.get('reservation_id') is not None else snapshot_line.reservation_id,
|
||||
'part_number': eff.get('part_number') if eff.get('part_number') is not None else snapshot_line.part_number,
|
||||
'required_qty': str(eff['qty']) if eff.get('qty') is not None else qty_text,
|
||||
})
|
||||
fact = match_by_snapshot_line_id.get(int(snapshot_line.id))
|
||||
required_qty = (fact or {}).get('required_qty')
|
||||
# [BE-有效视图] 需求数量:有效事实 → 匹配事实 → 快照列(Decimal 需 str 化)。
|
||||
required_qty = (
|
||||
str(eff['qty'])
|
||||
if eff.get('qty') is not None
|
||||
else (fact or {}).get('required_qty')
|
||||
)
|
||||
if required_qty is None:
|
||||
required_qty = qty_text
|
||||
# [BE-有效视图] 预约号/料号:有效事实 → 匹配事实 → 快照列;保存修正后即使
|
||||
# 匹配事实未刷新,prep 覆盖合并也立即显示新值。
|
||||
reservation_id_value = (
|
||||
eff.get('reservation_id')
|
||||
if eff.get('reservation_id') is not None
|
||||
else (fact or {}).get('reservation_id') or snapshot_line.reservation_id
|
||||
)
|
||||
part_number_value = (
|
||||
eff.get('part_number')
|
||||
if eff.get('part_number') is not None
|
||||
else (fact or {}).get('part_number') or snapshot_line.part_number
|
||||
)
|
||||
inv_view = project_line_inventory_view(
|
||||
has_formal_ot=has_formal_ot,
|
||||
fact=fact,
|
||||
@@ -934,8 +971,8 @@ def _build_stage_context(
|
||||
field_id_by_code,
|
||||
'customer_po_line_no',
|
||||
),
|
||||
'reservation_id': (fact or {}).get('reservation_id') or snapshot_line.reservation_id,
|
||||
'part_number': (fact or {}).get('part_number') or snapshot_line.part_number,
|
||||
'reservation_id': reservation_id_value,
|
||||
'part_number': part_number_value,
|
||||
'required_qty': required_qty,
|
||||
'available_qty': inv_view.get('available_qty'),
|
||||
'shortage_qty': inv_view.get('shortage_qty'),
|
||||
|
||||
Reference in new issue
Block a user