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>
This commit is contained in:
1 parent
ffc0d4a430
commit
39fe3c05f2
453 files changed
+17945
-8646
No files matched your search
@@ -1,11 +1,11 @@
|
||||
"""通用文件解析规则 purpose 字段测试(L0 纯单元 + DB 列校验 + 迁移往返)。
|
||||
|
||||
用途:验证 inventory_parsing_profile._validate_definition(purpose=...) 分支——
|
||||
用途:验证 onhand_parsing_profile._validate_definition(purpose=...) 分支——
|
||||
inbound 端点用定死领域字段(doc_no/material_code/quantity/movement_date 必填、
|
||||
不查库存字段目录、无 match_keys);onhand/outbound 维持既有库存字段目录 + match_keys
|
||||
校验(outbound 出站文件结构就位,暂无运行时消费方)。并用 app fixture 校验模型
|
||||
purpose 列默认 'onhand'、CHECK 约束三元枚举,以及 tt15 迁移 SQLite 真实往返。
|
||||
依赖:inventory_parsing_profile._validate_definition / save_draft(纯 + app SQLite)、
|
||||
依赖:onhand_parsing_profile._validate_definition / save_draft(纯 + app SQLite)、
|
||||
migrations/versions/tt15(batch_alter_table 改枚举)、app_ctx(根 conftest app
|
||||
fixture 上下文别名)。
|
||||
逻辑:_required_movement_field_ids 纯函数校验;模型列默认值/约束经 app fixture 校验;
|
||||
@@ -23,7 +23,7 @@ from alembic.migration import MigrationContext
|
||||
from alembic.operations import Operations
|
||||
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.shipping_notice.inventory_parsing_profile import _validate_definition, save_draft
|
||||
from app.services.shipping_notice.onhand_parsing_profile import _validate_definition, save_draft
|
||||
|
||||
pytestmark = pytest.mark.pure_unit
|
||||
|
||||
@@ -82,12 +82,12 @@ def test_inbound_definition_rejects_unknown_field():
|
||||
|
||||
|
||||
def test_purpose_enum_values():
|
||||
"""模型 purpose 列:default/server_default 均为 'onhand',CHECK 枚举恰为三元新枚举。"""
|
||||
from app.models.shipping_inventory_config import ShippingInventoryParsingProfile
|
||||
col = ShippingInventoryParsingProfile.__table__.columns["purpose"]
|
||||
"""模型 purpose 列:default/server_default 均为 'onhand',CHECK 名为批次 S 新约束,枚举恰为三元。"""
|
||||
from app.models.freight_rpa_config import FreightRpaParsingProfile
|
||||
col = FreightRpaParsingProfile.__table__.columns["purpose"]
|
||||
assert col.default.arg == "onhand" and col.server_default.arg == "onhand"
|
||||
check = next(c for c in ShippingInventoryParsingProfile.__table__.constraints
|
||||
if getattr(c, "name", "") == "ck_shipping_inventory_parsing_profiles_purpose")
|
||||
check = next(c for c in FreightRpaParsingProfile.__table__.constraints
|
||||
if getattr(c, "name", "") == "ck_freight_rpa_parsing_profiles_purpose")
|
||||
sql = str(getattr(check, "sqltext", check))
|
||||
for value in ("onhand", "inbound", "outbound"):
|
||||
assert value in sql
|
||||
@@ -98,9 +98,9 @@ def test_purpose_enum_values():
|
||||
def _sample_evidence(*, headers: list[str], sheet_name: str | None = None, file_format: str = 'xlsx') -> int:
|
||||
"""构造最小化样本结构证据,使 save_draft 遵循生产环境的表头绑定门禁。"""
|
||||
from app import db
|
||||
from app.models import ShippingInventoryStructureAnalysis
|
||||
from app.models import FreightRpaOnhandStructureAnalysis
|
||||
|
||||
item = ShippingInventoryStructureAnalysis(
|
||||
item = FreightRpaOnhandStructureAnalysis(
|
||||
source_kind='sample_upload', source_file_name='sample.xlsx', storage_path=None,
|
||||
file_checksum='c' * 64, file_format=file_format, analysis_status='ready',
|
||||
structure_json={'candidates': [{
|
||||
@@ -116,9 +116,9 @@ def _sample_evidence(*, headers: list[str], sheet_name: str | None = None, file_
|
||||
|
||||
def _catalog_mapping() -> dict[str, str]:
|
||||
"""以库存字段目录 ID 构造 onhand/outbound 用解析映射(目录分支端点)。"""
|
||||
from app.models import ShippingInventoryField
|
||||
from app.models import FreightRpaOnhandField
|
||||
|
||||
rows = {item.field_code: item for item in ShippingInventoryField.query.filter_by(status='active').all()}
|
||||
rows = {item.field_code: item for item in FreightRpaOnhandField.query.filter_by(status='active').all()}
|
||||
return {
|
||||
str(rows['part_number'].id): 'Supplier Sku',
|
||||
str(rows['reservation_id'].id): 'Reservation ID',
|
||||
@@ -127,7 +127,7 @@ def _catalog_mapping() -> dict[str, str]:
|
||||
|
||||
|
||||
def test_draft_accepts_outbound_and_rejects_legacy(app_ctx):
|
||||
"""save_draft purpose='outbound' 通过校验;purpose='movement' 报 SHIPPING.INVENTORY_PARSING_PROFILE_INVALID。"""
|
||||
"""save_draft purpose='outbound' 通过校验;purpose='movement' 报 SHIPPING.ONHAND_PARSING_PROFILE_INVALID。"""
|
||||
from app import db
|
||||
from app.models import ShippingOrderField
|
||||
|
||||
@@ -155,14 +155,14 @@ def test_draft_accepts_outbound_and_rejects_legacy(app_ctx):
|
||||
'definition': {'header_row_index': 1, 'field_mapping': _catalog_mapping(), 'match_keys': []},
|
||||
}, actor_id=None)
|
||||
# 关键断言:旧枚举 movement 已从白名单移除,fail-closed 报统一错误码。
|
||||
assert getattr(exc_info.value, 'code', '') == 'SHIPPING.INVENTORY_PARSING_PROFILE_INVALID'
|
||||
assert getattr(exc_info.value, 'code', '') == 'SHIPPING.ONHAND_PARSING_PROFILE_INVALID'
|
||||
|
||||
|
||||
def test_model_purpose_column_defaults_to_onhand(app):
|
||||
"""模型 purpose 列默认 'onhand'(存量 inventory 行由 tt15 数据迁移回填)。"""
|
||||
from app.models import ShippingInventoryParsingProfile
|
||||
from app.models import FreightRpaParsingProfile
|
||||
|
||||
existing = ShippingInventoryParsingProfile.query.filter_by(profile_code='TEST_RUNTIME').first()
|
||||
existing = FreightRpaParsingProfile.query.filter_by(profile_code='TEST_RUNTIME').first()
|
||||
assert existing is not None and existing.purpose == 'onhand'
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user