feat(shipping-notice): 添加货代履约策略管理功能,支持策略创建、发布及版本控制,增强订单冻结和预约管理逻辑
This commit is contained in:
1 parent
abd8fc1e16
commit
d62f5107b2
82 files changed
+4914
-514
No files matched your search
@@ -20,6 +20,7 @@ from app.models import (
|
||||
ShippingNoticeCandidate,
|
||||
ShippingNoticeDocument,
|
||||
ShippingNoticeIntake,
|
||||
ShippingOrderSnapshot,
|
||||
ShippingTask,
|
||||
)
|
||||
from app.services.shipping_notice.business_fingerprint import (
|
||||
@@ -28,6 +29,7 @@ from app.services.shipping_notice.business_fingerprint import (
|
||||
build_business_fingerprint,
|
||||
build_content_fingerprint,
|
||||
)
|
||||
from app.services.shipping_notice.reservation_id import validated_reservation_id
|
||||
|
||||
# 与 state_machine 主路径对齐的活跃/完成/关闭态(禁止 needs_review/matching/export_ready 等非主状态)
|
||||
_ACTIVE_PROCESS_STATUSES = frozenset(
|
||||
@@ -82,6 +84,36 @@ def _match_payload(task: ShippingTask, *, match_type: str, matched_fields: list[
|
||||
}
|
||||
|
||||
|
||||
def _reservation_differences(task: ShippingTask, summary: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
"""比较候选与目标冻结订单的同 Reservation 行,供人工修订确认前展示。"""
|
||||
snapshot = db.session.get(ShippingOrderSnapshot, task.order_snapshot_id) if task.order_snapshot_id else None
|
||||
if snapshot is None:
|
||||
return []
|
||||
proposed = {
|
||||
validated_reservation_id(str(line.get('reservation_id') or '')): line
|
||||
for line in summary.get('lines') or []
|
||||
if isinstance(line, dict) and validated_reservation_id(str(line.get('reservation_id') or ''))
|
||||
}
|
||||
differences: list[dict[str, Any]] = []
|
||||
for line in snapshot.lines:
|
||||
reservation_id = validated_reservation_id(line.reservation_id)
|
||||
candidate_line = proposed.get(reservation_id)
|
||||
if not reservation_id or candidate_line is None:
|
||||
continue
|
||||
previous = {'part_number': str(line.part_number or '').strip(), 'qty': str(line.qty)}
|
||||
proposed_value = {
|
||||
'part_number': str(candidate_line.get('part_number') or '').strip(),
|
||||
'qty': str(candidate_line.get('qty') or '').strip(),
|
||||
}
|
||||
if previous != proposed_value:
|
||||
differences.append({
|
||||
'reservation_id': reservation_id,
|
||||
'previous': previous,
|
||||
'proposed': proposed_value,
|
||||
})
|
||||
return differences
|
||||
|
||||
|
||||
def _allowed_actions_for(
|
||||
*,
|
||||
status: str,
|
||||
@@ -245,6 +277,10 @@ def detect_duplicates_for_intake(
|
||||
}
|
||||
if strength == 'unavailable' and status == 'none':
|
||||
blocking = False
|
||||
for match in matches:
|
||||
task = db.session.query(ShippingTask).filter_by(task_no=match['task_no']).one_or_none()
|
||||
if task is not None:
|
||||
match['reservation_differences'] = _reservation_differences(task, summary)
|
||||
|
||||
return {
|
||||
'status': status,
|
||||
@@ -569,6 +605,10 @@ def detect_duplicates_for_candidate(
|
||||
}
|
||||
if strength == 'unavailable' and status == 'none':
|
||||
blocking = False
|
||||
for match in matches:
|
||||
task = db.session.query(ShippingTask).filter_by(task_no=match['task_no']).one_or_none()
|
||||
if task is not None:
|
||||
match['reservation_differences'] = _reservation_differences(task, summary)
|
||||
|
||||
return {
|
||||
'status': status,
|
||||
|
||||
Reference in new issue
Block a user