feat(freight-rpa): 增加出站报表配置与回调支持,重构相关服务

- 将 RPA 管理 API 扩展至出站报表配置,新增出站相关的回调接口。
- 重构 freight_rpa_report_config_service,支持入站与出站报表配置的管理。
- 更新 ORM 模型,增加出站报表相关的持久化模型。
- 统一命名规范,确保在手、入站与出站的概念一致性。
This commit is contained in:
hugo committed 2026-10-19 18:45:16 +08:00
1 parent 39fe3c05f2
commit 911afa0f73
152 files changed
+9861 -2984

No files matched your search

+39 -19
View File
@@ -1,9 +1,9 @@
"""通用文件解析规则 purpose 字段测试(L0 纯单元 + DB 列校验 + 迁移往返)。
用途:验证 onhand_parsing_profile._validate_definition(purpose=...) 分支——
inbound 端点用定死领域字段(doc_no/material_code/quantity/movement_date 必填、
不查库存字段目录、无 match_keys);onhand/outbound 维持既有库存字段目录 + match_keys
校验(outbound 出站文件结构就位,暂无运行时消费方)。并用 app fixture 校验模型
inbound/outbound 端点用定死领域字段(doc_no/material_code/quantity/movement_date 必填、
不查库存字段目录、无 match_keys);onhand 维持库存字段目录 + match_keys 校验。
并用 app fixture 校验模型
purpose 列默认 'onhand'、CHECK 约束三元枚举,以及 tt15 迁移 SQLite 真实往返。
依赖:onhand_parsing_profile._validate_definition / save_draft(纯 + app SQLite)、
migrations/versions/tt15(batch_alter_table 改枚举)、app_ctx(根 conftest app
@@ -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.onhand_parsing_profile import _validate_definition, save_draft
from app.services.freight_rpa.parsing_profile import _validate_definition, save_draft
pytestmark = pytest.mark.pure_unit
@@ -81,6 +81,36 @@ def test_inbound_definition_rejects_unknown_field():
_validate_definition(raw, purpose='inbound')
def test_outbound_definition_uses_movement_fields():
"""outbound 定义完整 → 走异动字段路径,match_keys 空。"""
definition = _validate_definition(_inbound_definition(), purpose='outbound')
assert definition['match_keys'] == []
assert definition['field_mapping']['doc_no'] == '单据编号'
def test_outbound_onhand_shaped_definition_rejected(app_ctx):
"""库存目录形态(含 match_keys)在 outbound 下应失败。"""
from app.models import FreightRpaOnhandField, ShippingOrderField
from app import db
rows = {item.field_code: item for item in FreightRpaOnhandField.query.filter_by(status='active').all()}
field_mapping = {
str(rows['part_number'].id): 'Supplier Sku',
str(rows['reservation_id'].id): 'Reservation ID',
str(rows['available_qty'].id): 'Qty Available',
}
order_field = ShippingOrderField(field_code='part_number', scope='line', value_type='string')
db.session.add(order_field)
db.session.flush()
raw = {
'header_row_index': 1,
'field_mapping': field_mapping,
'match_keys': [{'order_field_id': order_field.id, 'inventory_field_id': next(iter(field_mapping))}],
}
with pytest.raises(ValidationError):
_validate_definition(raw, purpose='outbound')
def test_purpose_enum_values():
"""模型 purpose 列:default/server_default 均为 'onhand',CHECK 名为批次 S 新约束,枚举恰为三元。"""
from app.models.freight_rpa_config import FreightRpaParsingProfile
@@ -128,25 +158,15 @@ def _catalog_mapping() -> dict[str, str]:
def test_draft_accepts_outbound_and_rejects_legacy(app_ctx):
"""save_draft purpose='outbound' 通过校验;purpose='movement' 报 SHIPPING.ONHAND_PARSING_PROFILE_INVALID。"""
from app import db
from app.models import ShippingOrderField
# 出站文件结构就位:outbound 走库存字段目录分支(与 onhand 同构),需行级订单匹配键。
order_field = ShippingOrderField(field_code='part_number', scope='line', value_type='string')
db.session.add(order_field)
db.session.flush()
headers = ['Supplier Sku', 'Reservation ID', 'Qty Available']
headers = [value for value in _inbound_definition()['field_mapping'].values()]
outbound = save_draft({
'profile_code': 'OUT_STD', 'display_name': '出站结构就位', 'purpose': 'outbound',
'file_format': 'xlsx', 'sample_analysis_id': _sample_evidence(headers=headers),
'definition': {
'header_row_index': 1,
'field_mapping': _catalog_mapping(),
'match_keys': [{'order_field_id': order_field.id, 'inventory_field_id': next(iter(_catalog_mapping()))}],
},
'profile_code': 'OUT_STD', 'display_name': '出站异动解析', 'purpose': 'outbound',
'file_format': 'xlsx', 'sample_analysis_id': _sample_evidence(headers=headers, sheet_name='Inbound'),
'definition': _inbound_definition(),
}, actor_id=None)
assert outbound['purpose'] == 'outbound'
assert outbound['definition']['match_keys'] == []
with pytest.raises(ValidationError) as exc_info:
save_draft({