清理废弃的ShippingCase相关代码与依赖,统一使用ShippingNotice直接关联客户数据。调整库存网关依赖规则,支持仅对库存满足或已人工放行的订单行生成发货Excel,实现滚动履约逻辑。
50 lines
2.4 KiB
Python
50 lines
2.4 KiB
Python
"""阶段七:重发版本替代与上传后撤销门禁。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from app import db
|
|
from app.core.errors import ConflictError
|
|
from app.models import ShippingFreightCancellation, ShippingNotice, User
|
|
from app.services.shipping_notice.freight_cancellation_service import complete_freight_cancellation
|
|
from app.services.shipping_notice.task_supersession_service import assert_task_not_supersession_blocked, establish_task_supersession
|
|
|
|
|
|
def _tasks(*, uploaded: bool) -> tuple[ShippingNotice, ShippingNotice, User]:
|
|
user = User(username=f'supersession-{uploaded}', email=f'supersession-{uploaded}@example.test', password_hash='x')
|
|
old = ShippingNotice(task_no=f'SN-SUP-OLD-{uploaded}', user_id=None, upload_status='uploaded' if uploaded else None, freight_ref_no='F-1' if uploaded else None)
|
|
db.session.add_all([user, old]); db.session.flush()
|
|
old.user_id = user.id
|
|
new = ShippingNotice(task_no=f'SN-SUP-NEW-{uploaded}', user_id=user.id, supersedes_task_id=old.id)
|
|
db.session.add(new); db.session.commit()
|
|
return old, new, user
|
|
|
|
|
|
def test_unuploaded_resend_voids_old_task_and_keeps_new_active(app):
|
|
"""关键断言:未上传重发立即使旧版失效,库存入口不能继续消费旧版本。"""
|
|
with app.app_context():
|
|
old, new, user = _tasks(uploaded=False)
|
|
establish_task_supersession(old_task=old, new_task=new, actor_id=user.id, reason='customer resend')
|
|
assert old.lifecycle_status == 'voided'
|
|
assert new.lifecycle_status == 'active'
|
|
|
|
|
|
def test_uploaded_resend_requires_external_cancellation_confirmation_before_new_can_continue(app):
|
|
"""关键断言:已上传旧版须登记外部撤销确认;不要求回执号或文件。"""
|
|
with app.app_context():
|
|
old, new, user = _tasks(uploaded=True)
|
|
establish_task_supersession(old_task=old, new_task=new, actor_id=user.id, reason='customer resend')
|
|
row = ShippingFreightCancellation.query.one()
|
|
assert new.lifecycle_status == 'blocked'
|
|
with pytest.raises(ConflictError):
|
|
assert_task_not_supersession_blocked(new)
|
|
complete_freight_cancellation(
|
|
cancellation_id=row.id,
|
|
actor_id=user.id,
|
|
note='已在货代平台确认撤销',
|
|
)
|
|
assert row.status == 'cancelled'
|
|
assert old.lifecycle_status == 'voided'
|
|
assert new.lifecycle_status == 'active'
|