- 新增 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(含结案时序规约)
66 lines
2.9 KiB
Python
66 lines
2.9 KiB
Python
"""
|
|
tests/test_line_closure_export.py
|
|
|
|
用途:验证滚动导出资格对已结案行的剔除(含"有库存的结案行也不导出"边缘场景)。
|
|
依赖:pytest、reservation_service、fulfillment_workflow、核验/预约模型、行级履约决定。
|
|
逻辑:两行均有可用预约,结案其一后,导出资格集合只保留未结案行。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from decimal import Decimal
|
|
|
|
from app import db
|
|
from app.models import (
|
|
ShippingInventoryVerification,
|
|
ShippingInventoryVerificationLine,
|
|
ShippingReservation,
|
|
)
|
|
from app.services.shipping_notice.fulfillment_workflow import exportable_snapshot_line_ids
|
|
from app.services.shipping_notice.reservation_service import current_available_snapshot_line_ids
|
|
from tests.test_effective_order_view import _seed_frozen_order
|
|
from tests.test_line_closure_fulfillment import _seed_close_decision
|
|
|
|
|
|
def _seed_available_reservations(fixture):
|
|
"""两行各建一条 available 预约 + 一轮 completed 核验。"""
|
|
verification = ShippingInventoryVerification(task_id=fixture.order.id, status='completed')
|
|
db.session.add(verification)
|
|
db.session.flush()
|
|
for index, snap_line in enumerate(fixture.snap_lines):
|
|
reservation = ShippingReservation(
|
|
task_id=fixture.order.id, snapshot_line_id=snap_line.id,
|
|
reservation_id=f'RSV-CLOSE-{index}', po_number_normalized='PO-CLOSE',
|
|
part_number=snap_line.part_number, required_qty=Decimal('10'), status='available',
|
|
)
|
|
db.session.add(reservation)
|
|
db.session.flush()
|
|
db.session.add(ShippingInventoryVerificationLine(
|
|
verification_id=verification.id, reservation_id=reservation.id,
|
|
required_qty=Decimal('10'), available_qty=Decimal('10'), status='available',
|
|
))
|
|
db.session.flush()
|
|
|
|
|
|
def test_closed_line_with_inventory_is_not_exportable(app):
|
|
"""结案行即使库存充足、核验 available 也不得进入导出资格集合。"""
|
|
with app.app_context():
|
|
fixture = _seed_frozen_order()
|
|
_seed_available_reservations(fixture)
|
|
_seed_close_decision(fixture, 1)
|
|
_verification, available = current_available_snapshot_line_ids(
|
|
fixture.order, closed_snapshot_line_ids={int(fixture.snap_lines[1].id)},
|
|
)
|
|
# 断言:仅未结案的第 0 行可导出。
|
|
assert available == {int(fixture.snap_lines[0].id)}
|
|
|
|
|
|
def test_exportable_snapshot_line_ids_excludes_closed(app):
|
|
"""滚动导出入口(exportable_snapshot_line_ids)自动剔除结案行。"""
|
|
with app.app_context():
|
|
fixture = _seed_frozen_order()
|
|
_seed_available_reservations(fixture)
|
|
_seed_close_decision(fixture, 1)
|
|
# 断言:导出集合不含结案行(该行预约仍 available,验证 closed 过滤优先)。
|
|
assert exportable_snapshot_line_ids(fixture.order) == {int(fixture.snap_lines[0].id)}
|