feat(shipping-notice): 实现滚动履约功能,优化发货通知流程与代码清理

清理废弃的ShippingCase相关代码与依赖,统一使用ShippingNotice直接关联客户数据。调整库存网关依赖规则,支持仅对库存满足或已人工放行的订单行生成发货Excel,实现滚动履约逻辑。
This commit is contained in:
hugo committed 2026-08-26 02:47:07 +08:00
1 parent 7cfd5d167e
commit 1e5aedb9ed
235 files changed
+11394 -9613

No files matched your search

@@ -19,6 +19,7 @@ from app.services.shipping_notice.query_service import (
resolve_task_from_payload,
serialize_task,
task_export_error_message,
list_freight_notice_groups_for_task,
)
from app.services.shipping_notice.user_facing_status import TOOL_TASK_DATA_OMIT
@@ -300,6 +301,116 @@ def test_serialize_task_summary_enriches_todo_and_can_handle(app):
assert "can_handle" not in no_viewer
def test_serialize_task_summary_projects_only_current_notice_line_facts(app):
"""同 PO 的多个 business_no 必须各自投影本通知的项次、料号、数量和库存。"""
with app.app_context():
from app import db
from app.models import ShippingNoticeLine, ShippingNoticeLineInventoryMatch
from app.services.shipping_notice.query_service import serialize_task_summary
first = ShippingNotice(task_no='SN-NOTICE-1', business_no='WVC26082301', source_type='manual', user_id=11)
second = ShippingNotice(task_no='SN-NOTICE-2', business_no='WVC26082302', source_type='manual', user_id=11)
db.session.add_all([first, second]); db.session.flush()
db.session.add_all([
ShippingNoticeLine(
notice_id=first.id, position=1, line_key='LINE-1', part_number='PART-FIRST',
reservation_id='RES-1', required_qty='12', field_values_json={'line_no': '00010'},
),
ShippingNoticeLine(
notice_id=second.id, position=1, line_key='LINE-2', part_number='PART-SECOND',
reservation_id='RES-2', required_qty='8', field_values_json={'line_no': '00020'},
),
ShippingNoticeLineInventoryMatch(
task_id=first.id, line_key='LINE-1', match_result='matched', inventory_status='ready',
available_qty='20', shortage_qty='0', is_current=True,
),
ShippingNoticeLineInventoryMatch(
task_id=second.id, line_key='LINE-2', match_result='matched', inventory_status='ready',
available_qty='9', shortage_qty='0', is_current=True,
),
])
db.session.commit()
data = serialize_task_summary(first, viewer_user_id=11)
assert data['business_no'] == 'WVC26082301'
assert data['notice_line_summary'] == [{
'line_no': '00010', 'part_number': 'PART-FIRST', 'customer_part_number': None,
'reservation_id': 'RES-1', 'shipment_qty': '12.00000000', 'available_qty': '20',
'shortage_qty': '0', 'inventory_status': 'ready',
}]
def test_freight_notice_groups_split_same_po_by_business_no_and_owner(app):
"""货代上传聚合必须按同 PO 的 business_no 拆组,并排除无业务号及他人 Notice。"""
with app.app_context():
from app import db
from app.models import ShippingNoticeLine
from app.services.shipping_notice import query_service
def with_po(task_no, business_no, user_id):
return ShippingNotice(task_no=task_no, business_no=business_no, source_type='manual', user_id=user_id)
first = with_po('SN-GROUP-1', 'WYC26082401', 11)
second = with_po('SN-GROUP-2', 'WYC26082402', 11)
no_business = with_po('SN-GROUP-3', None, 11)
other = with_po('SN-GROUP-4', 'WYC26082499', 99)
db.session.add_all([first, second, no_business, other]); db.session.flush()
db.session.add_all([
ShippingNoticeLine(notice_id=first.id, position=1, line_key='G1', part_number='PART-A', reservation_id='R1', required_qty='2', field_values_json={'line_no': '00010'}),
ShippingNoticeLine(notice_id=second.id, position=1, line_key='G2', part_number='PART-B', reservation_id='R2', required_qty='3', field_values_json={'line_no': '00020'}),
])
db.session.commit()
original_header_reader = query_service.current_header_field_values_or_empty
# customer_po_number 是当前动态 Schema 的正式 PO 字段;聚合必须不依赖旧兼容投影。
query_service.current_header_field_values_or_empty = lambda _task: {'customer_po_number': 'PO-GROUP'}
try:
result = list_freight_notice_groups_for_task(first, user_id=11)
finally:
query_service.current_header_field_values_or_empty = original_header_reader
assert result['po_number'] == 'PO-GROUP'
assert [item['business_no'] for item in result['items']] == ['WYC26082401', 'WYC26082402']
# 单条菜单必须消费服务端授权投影,前端不得按上传状态自行猜测可执行动作。
assert 'available_actions' in result['items'][0]
assert result['items'][0]['lines'][0]['part_number'] == 'PART-A'
assert result['items'][1]['lines'][0]['part_number'] == 'PART-B'
def test_freight_notice_groups_reads_frozen_snapshot_po_when_extraction_projection_is_unavailable(app):
"""当前 Extraction 不可读时,货代上传聚合仍必须以冻结快照中的客户 PO 对齐同一发货批次。"""
with app.app_context():
from app import db
from app.models import ShippingOrderSnapshot
from app.services.shipping_notice import query_service
first = ShippingNotice(task_no='SN-GROUP-SNAPSHOT-1', business_no='WYC26082411', source_type='manual', user_id=11)
second = ShippingNotice(task_no='SN-GROUP-SNAPSHOT-2', business_no='WYC26082412', source_type='manual', user_id=11)
db.session.add_all([first, second]); db.session.flush()
for task in (first, second):
snapshot = ShippingOrderSnapshot(
task_id=task.id,
extraction_id=task.id,
schema_version_id=1,
order_data_version=1,
header_values_json={},
customer_po_number='ZNB-16754796',
)
db.session.add(snapshot); db.session.flush()
task.order_snapshot_id = snapshot.id
db.session.commit()
original_header_reader = query_service.current_header_field_values_or_empty
query_service.current_header_field_values_or_empty = lambda _task: {}
try:
result = list_freight_notice_groups_for_task(first, user_id=11)
finally:
query_service.current_header_field_values_or_empty = original_header_reader
assert result['po_number'] == '16754796'
assert [item['business_no'] for item in result['items']] == ['WYC26082411', 'WYC26082412']
def test_list_my_todos_and_count_buckets(app):
"""list_my_todos 按 bucket 分类;count 徽标与 pending 一致。"""
with app.app_context():
@@ -458,8 +569,8 @@ def test_list_my_todos_only_returns_stream_current_case_when_legacy_case_is_stil
assert original.case_no not in review_case_nos
def test_open_review_case_without_current_candidate_has_no_lifecycle_entry(app):
"""历史空 Review Case 可以处置,但不能被待办页默认授权进入订单生命周期。"""
def test_open_review_case_without_current_candidate_enters_intake_parse(app):
"""无当前 Candidate 的开放 Case 仅授权接收解析入口,不授权订单复核。"""
with app.app_context():
from app import db
from app.services.shipping_notice.order_review_service import ensure_run_review_cases
@@ -476,7 +587,8 @@ def test_open_review_case_without_current_candidate_has_no_lifecycle_entry(app):
pending = list_my_todos(user.id, bucket='pending', page=1, page_size=50)
hit = next(item for item in pending['items'] if item.get('review_case_no') == case.case_no)
assert hit['ui_state']['lifecycle_stage'] is None
assert hit['ui_state']['lifecycle_stage'] == 'intake_parse'
assert hit['ui_state']['intake_parse_authorized'] is True
assert hit['ui_state']['lifecycle_entries'] == []
@@ -681,7 +793,6 @@ def test_todo_category_lightweight_matches_orm_and_count(app):
row = SimpleNamespace(
review_status=task.review_status,
pending_human_reason=task.pending_human_reason,
shipping_case_id=task.shipping_case_id,
customer_resolution_status=task.customer_resolution_status,
order_snapshot_id=task.order_snapshot_id,
current_order_extraction_id=task.current_order_extraction_id,