fix(shipping-notice): 有效订单值视图贯通履约链并补全行结案豁免
- 新增 effective_order_view:冻结快照+人工修正按(行position×field_id)对位叠加,整行替换后行级叠加保守跳过 - 库存匹配(order_field_purposes)、Excel值(export)、通知行物化(notice_line_service.line_overrides)统一消费有效值 - 行结案close_unfulfillable端到端豁免:聚合/match_completed/整单建通知/滚动导出四处剔除结案行(含有库存结案行) - 结案决定落库后触发Gate重算(trigger=line_fulfillment_closed),对齐放行路径 - 兜底匹配分支切有效视图基线;全结案聚合口径与门禁一致(unfulfillable) - 预约门禁断言更新为有效视图契约;文档同步technical.md/funclist(含结案时序规约)
This commit is contained in:
1 parent
0333d713e0
commit
051f80e1e9
17 files changed
+2212
-43
No files matched your search
@@ -142,7 +142,10 @@ def _source_notice_for_order_facts(notice: ShippingNotice) -> ShippingNotice:
|
||||
|
||||
|
||||
def order_field_id_values(task: ShippingNotice) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
"""从 OT 冻结订单事实按稳定 field_id 返回 Header/Line 值。"""
|
||||
"""从 OT 冻结订单事实按稳定 field_id 返回 Header/Line 值。
|
||||
|
||||
库存匹配/Excel 消费方应改用 effective_order_view.effective_order_field_values 获取含冻结后修正的有效值。
|
||||
"""
|
||||
from app.services.shipping_notice.task_supersession_service import assert_task_not_supersession_blocked
|
||||
assert_task_not_supersession_blocked(task)
|
||||
owner = db.session.get(ShippingOrderTask, task.order_task_id) if getattr(task, 'order_task_id', None) else task
|
||||
@@ -779,7 +782,8 @@ def prepare_export_match_inputs(task: ShippingNotice) -> dict[str, Any]:
|
||||
snapshot = db.session.get(ShippingOrderSnapshot, snapshot_id) if snapshot_id else None
|
||||
if snapshot is None:
|
||||
raise ValueError('任务没有可用于导出的冻结订单快照')
|
||||
header_values, all_line_values = order_field_id_values(task)
|
||||
from app.services.shipping_notice.effective_order_view import effective_order_field_values
|
||||
header_values, all_line_values = effective_order_field_values(task)
|
||||
profile_definition = source.parsing_profile.definition_json if isinstance(source.parsing_profile.definition_json, dict) else {}
|
||||
match_keys = profile_definition.get('match_keys') if isinstance(profile_definition.get('match_keys'), list) else []
|
||||
line_inventory_fields = _inventory_fields_by_mode(mappings, 'line')
|
||||
@@ -814,6 +818,26 @@ def prepare_export_match_inputs(task: ShippingNotice) -> dict[str, Any]:
|
||||
for source_index, line in enumerate(snapshot.lines)
|
||||
if source_index in release_overrides_by_source_line
|
||||
}
|
||||
# [STEP 1] 已结案(close_unfulfillable)行不再有履约要求:即使预约仍有库存,
|
||||
# 也必须从滚动导出资格中剔除(与上方放行查询同源同口径:只认活动决定)。
|
||||
closed_snapshot_line_ids = set()
|
||||
if source_notice.id is not None:
|
||||
closed_rows = (
|
||||
ShippingOrderReviewLineDecision.query
|
||||
.join(ShippingOrderReviewCase, ShippingOrderReviewLineDecision.review_case_id == ShippingOrderReviewCase.id)
|
||||
.filter(
|
||||
ShippingOrderReviewCase.confirmed_task_id == int(source_notice.id),
|
||||
ShippingOrderReviewLineDecision.is_active.is_(True),
|
||||
ShippingOrderReviewLineDecision.decision_code == 'close_unfulfillable',
|
||||
)
|
||||
.all()
|
||||
)
|
||||
closed_snapshot_line_ids = {
|
||||
int(snapshot.lines[int(decision.line_index)].id)
|
||||
for decision in closed_rows
|
||||
if decision.line_index is not None
|
||||
and 0 <= int(decision.line_index) < len(snapshot.lines)
|
||||
}
|
||||
selected_snapshot_line_ids = {
|
||||
int(row.snapshot_line_id)
|
||||
for row in ShippingNoticeLine.query.filter_by(notice_id=int(task.id)).all()
|
||||
@@ -824,6 +848,7 @@ def prepare_export_match_inputs(task: ShippingNotice) -> dict[str, Any]:
|
||||
source_notice,
|
||||
released_snapshot_line_ids=released_snapshot_line_ids,
|
||||
selected_snapshot_line_ids=selected_snapshot_line_ids or None,
|
||||
closed_snapshot_line_ids=closed_snapshot_line_ids,
|
||||
)
|
||||
except ConflictError:
|
||||
raise
|
||||
|
||||
Reference in new issue
Block a user