Files
syops/backend/tests/test_shipping_onhand_source_warehouse.py
hugoandCursor 39fe3c05f2 feat(freight-rpa): 库存/收料改名在手/入站,报表归属RPA,类名统一FreightRpa
把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与
枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa
持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀,
上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-19 10:46:06 +08:00

62 lines
2.4 KiB
Python

"""库存源仓库事实边界测试。"""
from types import SimpleNamespace
from app.models import ShippingNoticeLine
from app.services.shipping_notice.onhand_source_gate import resolve_inventory_source_warehouse_id
def test_fixed_source_warehouse_comes_from_source_configuration_not_order_task() -> None:
"""固定仓在 OT 不含仓库属性时仍由库存源配置确定。"""
task = SimpleNamespace(id=1, source_code='DUBLIN')
source = {
'source_code': 'DUBLIN',
'warehouse_resolution_mode': 'fixed',
'fixed_warehouse_id': ' DUB ',
}
assert resolve_inventory_source_warehouse_id(task, source=source) == 'DUB'
def test_dynamic_source_has_no_warehouse_before_verified_inventory_link() -> None:
"""动态仓不得从 OT 推测,须等待库存文件或 Link 的已验证事实。"""
task = SimpleNamespace(id=1, source_code='DYNAMIC')
source = {
'source_code': 'DYNAMIC',
'warehouse_resolution_mode': 'inventory_match',
'fixed_warehouse_id': None,
}
assert resolve_inventory_source_warehouse_id(task, source=source) is None
def test_shipping_notice_line_owns_confirmed_inventory_facts() -> None:
"""正式通知仓库、来源和文件必须是行级字段,而非通知单头或 OT 字段。"""
columns = ShippingNoticeLine.__table__.c
assert {'inventory_source_code', 'inventory_file_id', 'inventory_warehouse_id'} <= set(columns.keys())
def test_match_completed_requires_all_frozen_order_lines(monkeypatch) -> None:
"""单个 Match 成功不能让尚有未匹配 Snapshot 项次的订单通过满足性 Gate。"""
from app.services.shipping_notice import fulfillment_workflow as workflow
matched = SimpleNamespace(snapshot_line_id=101, match_result='matched', shortage_qty='0')
class Query:
def filter_by(self, **_kwargs):
return self
def all(self):
return [matched]
class MatchModel:
query = Query()
snapshot = SimpleNamespace(lines=[SimpleNamespace(id=101), SimpleNamespace(id=102)])
monkeypatch.setattr('app.models.ShippingNoticeLineOnhandMatch', MatchModel)
monkeypatch.setattr(workflow.db.session, 'get', lambda _model, _identifier: snapshot)
monkeypatch.setattr(workflow, '_released_snapshot_line_ids_for_task', lambda _task: set())
assert workflow.match_completed(SimpleNamespace(id=1, order_snapshot_id=10)) is False