- 编辑闸门翻转为状态制:Excel 生成前+无活动 Attempt 即可编辑,原因不强制(审计自动记录操作人与变更) - 修复 Decimal 字段人工编辑无法持久化(单字段+整行替换两路径) - 预约注册与核验比对改读有效订单值视图,消除编辑后重匹配 RESERVATION_MISMATCH 阻断 - 通知准备值列改读有效视图:保存即显新值,匹配结果列保持最近一轮事实 - 行编辑入口为更多操作列编辑按钮;编辑态替换为保存/取消;库存源行内改选随保存统一提交 - 展示态动作收纳进更多菜单(Teleport 浮层,防表格 overflow 裁剪) - 修复缺口复核投影键错位(has_shortage 恒 False 致入口隐藏)并补齐行级结案入口 - 缺口放行改行内补录条(菜单放行或缺 N 项徽标展开,确认放行/取消收起),放行原因可选 - i18n 四语言;technical.md/funclist.md 语义文档同步
160 lines
7.8 KiB
Python
160 lines
7.8 KiB
Python
"""
|
|
tests/test_reservation_effective_view.py
|
|
|
|
用途:验证预约注册与核验比对消费「冻结快照 + 已接受人工修正」的有效订单值视图
|
|
(修复编辑料号/数量后核验必抛 SHIPPING.RESERVATION_MISMATCH 的阻断缺陷)。
|
|
依赖:pytest、reservation_service、task_order_field_editor、test_effective_order_view 夹具。
|
|
逻辑:先按冻结值注册预约 → 就地编辑料号/数量 → 再次 ensure 应走同 OT 确认修订
|
|
(transfer,自动接替未履约预约)而非抛错;核验比对按归一化料号匹配有效值。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from decimal import Decimal
|
|
|
|
import pytest
|
|
|
|
from app import db
|
|
from app.core.errors import ConflictError, ValidationError
|
|
from app.models import (
|
|
ShippingOrderFieldDecision,
|
|
ShippingOrderFieldValue,
|
|
ShippingOrderLine,
|
|
ShippingReservation,
|
|
)
|
|
from app.services.shipping_notice.reservation_service import (
|
|
ensure_task_reservations,
|
|
record_inventory_verification,
|
|
)
|
|
from app.services.shipping_notice.task_order_field_editor import replace_current_line_field_value
|
|
from tests.test_effective_order_view import _seed_frozen_order
|
|
|
|
|
|
# 预约层契约只接受 5/10 位纯数字预约号(validated_reservation_id);夹具的 'RSV-*'
|
|
# 为占位值,须补成契约内值才能驱动预约注册,同时补 PO 以支撑二次注册的归属校验。
|
|
_NUMERIC_RESERVATION_IDS = ('1234567890', '2234567890')
|
|
|
|
|
|
def _seed_frozen_order_for_reservations():
|
|
"""复用有效视图夹具并补齐预约层契约值:纯数字预约号 + 单头 PO。"""
|
|
fixture = _seed_frozen_order()
|
|
for snap_line, reservation_id in zip(fixture.snap_lines, _NUMERIC_RESERVATION_IDS):
|
|
snap_line.reservation_id = reservation_id
|
|
fixture.snapshot.customer_po_number = 'PO-0001'
|
|
order_lines = ShippingOrderLine.query.filter_by(
|
|
extraction_id=fixture.extraction.id,
|
|
).order_by(ShippingOrderLine.position).all()
|
|
for line, reservation_id in zip(order_lines, _NUMERIC_RESERVATION_IDS):
|
|
for item in ShippingOrderFieldValue.query.filter_by(
|
|
extraction_id=fixture.extraction.id, line_id=line.id, field_id='f-rsv',
|
|
).all():
|
|
item.value_text = reservation_id
|
|
item.value_json = reservation_id
|
|
for item in ShippingOrderFieldDecision.query.filter_by(
|
|
extraction_id=fixture.extraction.id, line_id=line.id, field_id='f-rsv',
|
|
).all():
|
|
item.resolved_value_json = reservation_id
|
|
db.session.flush()
|
|
return fixture
|
|
|
|
|
|
def _registered_reservation(fixture, index: int = 0) -> ShippingReservation:
|
|
"""按夹具第 index 行的预约号取全局预约注册行。"""
|
|
return ShippingReservation.query.filter_by(
|
|
task_id=fixture.order.id, reservation_id=_NUMERIC_RESERVATION_IDS[index],
|
|
).one()
|
|
|
|
|
|
def test_ensure_task_reservations_follows_effective_values(app):
|
|
"""预约注册必须消费有效值:编辑料号后再次 ensure 应自动修订(transfer)而非校验失败。"""
|
|
with app.app_context():
|
|
fixture = _seed_frozen_order_for_reservations()
|
|
# 第一次注册:按冻结值(带尾巴的旧料号)建预约。
|
|
ensure_task_reservations(fixture.order)
|
|
reservation = _registered_reservation(fixture)
|
|
# 断言:初始注册值为冻结快照列原值。
|
|
assert reservation.part_number == 'D4-A08AR12000002-'
|
|
# 就地编辑第 0 行料号为正确值。
|
|
replace_current_line_field_value(
|
|
task=fixture.order, position=0, field_code='part_number', value='D4-A08AR12000002',
|
|
)
|
|
# 第二次 ensure(重匹配核验前的真实调用时序):必须成功且预约更新为有效值。
|
|
ensure_task_reservations(fixture.order)
|
|
db.session.refresh(reservation)
|
|
# 断言:预约料号已随有效值修订,状态回 pending(可重新核验)。
|
|
assert reservation.part_number == 'D4-A08AR12000002'
|
|
assert reservation.status == 'pending'
|
|
# 断言:修订走同 OT 确认修订路径,落 reservation_revision_confirmed 审计事件。
|
|
assert any(
|
|
event.event_type == 'reservation_revision_confirmed'
|
|
for event in fixture.order.events
|
|
)
|
|
|
|
|
|
def test_ensure_task_reservations_revises_required_qty_from_effective_value(app):
|
|
"""编辑数量后再次 ensure 必须按有效数量修订预约,而非保持冻结数量。"""
|
|
with app.app_context():
|
|
fixture = _seed_frozen_order_for_reservations()
|
|
ensure_task_reservations(fixture.order)
|
|
reservation = _registered_reservation(fixture)
|
|
# 断言:初始注册数量为冻结值 10。
|
|
assert reservation.required_qty == Decimal('10')
|
|
replace_current_line_field_value(
|
|
task=fixture.order, position=0, field_code='qty', value='15',
|
|
)
|
|
ensure_task_reservations(fixture.order)
|
|
db.session.refresh(reservation)
|
|
# 断言:需求数量已随有效值修订为 15,且版本在原 OT 上递增(不新建任务)。
|
|
# order_data_version 经历两次 bump:编辑器写修正 +1,确认修订接替 +1。
|
|
assert reservation.required_qty == Decimal('15')
|
|
assert reservation.status == 'pending'
|
|
assert fixture.order.order_data_version == 3
|
|
assert fixture.order.progress_version == 2
|
|
|
|
|
|
def test_record_inventory_verification_maps_effective_part_number(app):
|
|
"""编辑料号后的库存核验必须能按有效料号(归一化后)映射预约,不再抛 RESERVATION_MISMATCH。"""
|
|
with app.app_context():
|
|
fixture = _seed_frozen_order_for_reservations()
|
|
ensure_task_reservations(fixture.order)
|
|
replace_current_line_field_value(
|
|
task=fixture.order, position=0, field_code='part_number', value='D4-A08AR12000002',
|
|
)
|
|
# 模拟重匹配写入的有效值事实:第 0 行料号带大小写/空白差异(归一化后应相等)。
|
|
verification = record_inventory_verification(
|
|
fixture.order, inventory_snapshot_id=None, source_config_version='v1',
|
|
line_results=[
|
|
{
|
|
'reservation_id': '1234567890', 'part_number': ' d4-a08ar12000002 ',
|
|
'required_qty': Decimal('10'), 'available_qty': Decimal('10'), 'line_status': 'ok',
|
|
},
|
|
{
|
|
'reservation_id': '2234567890', 'part_number': 'D4-B07BR07000001',
|
|
'required_qty': Decimal('10'), 'available_qty': Decimal('10'), 'line_status': 'ok',
|
|
},
|
|
],
|
|
)
|
|
# 断言:核验轮次成功创建,修订后的预约按有效值完整满足并转 available。
|
|
assert verification.lines[0].status == 'available'
|
|
assert verification.result_json['available_count'] == 2
|
|
|
|
|
|
def test_locked_reservation_still_rejects_effective_revision(app):
|
|
"""已占用/已上传的预约不受有效值自动修订影响:保留 RESERVATION_REVISION_LOCKED 拒绝。"""
|
|
with app.app_context():
|
|
fixture = _seed_frozen_order_for_reservations()
|
|
ensure_task_reservations(fixture.order)
|
|
reservation = _registered_reservation(fixture)
|
|
reservation.status = 'artifact_reserved'
|
|
db.session.flush()
|
|
replace_current_line_field_value(
|
|
task=fixture.order, position=0, field_code='part_number', value='D4-A08AR12000002',
|
|
)
|
|
# 断言:带 Artifact 锁的预约不得自动修订,必须走人工复核。
|
|
with pytest.raises(ConflictError) as locked:
|
|
ensure_task_reservations(fixture.order)
|
|
assert locked.value.code == 'SHIPPING.RESERVATION_REVISION_LOCKED'
|
|
db.session.refresh(reservation)
|
|
# 断言:预约料号保持注册原值,未被静默改写。
|
|
assert reservation.part_number == 'D4-A08AR12000002-'
|