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,16 +1,16 @@
|
||||
"""
|
||||
收料报表配置管理接口测试。
|
||||
|
||||
用途:验证站点内独立收料配置的权限、DBS/Crane 规则及不可影响库存配置的边界。
|
||||
用途:验证站点内独立入站报表配置的权限、DBS/Crane 规则及不可影响在手配置的边界。
|
||||
依赖:Flask 管理 API、库存站点测试种子、货代统一审计事件。
|
||||
逻辑:配置保存只更新 shipping_receipt_report_configs,并留存前后快照审计。
|
||||
逻辑:请求打到 /api/admin/freight-rpa/sources/<id>/inbound-report-config;保存只更新入站配置并留存前后快照审计。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from app.models import ShippingAuditEvent, ShippingInventorySource, User
|
||||
from app.models import ShippingAuditEvent, FreightRpaSource, User
|
||||
from tests.conftest import parse_api_data, parse_api_error
|
||||
|
||||
|
||||
@@ -49,21 +49,23 @@ def test_admin_saves_independent_dbs_receipt_config_and_audit(app, client):
|
||||
app.config['AUTH_JWT_REQUIRED'] = False
|
||||
with app.app_context():
|
||||
_create_users()
|
||||
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
source_id = source.id
|
||||
# s18 起在手报表路径/查询条件归 onhand_report_config 配置行,站点行不再承载。
|
||||
onhand_config = source.onhand_report_config
|
||||
inventory_before = {
|
||||
'path': dict(source.report_path_json), 'parameters': list(source.query_parameters_json),
|
||||
'path': dict(onhand_config.report_path_json), 'parameters': list(onhand_config.query_parameters_json),
|
||||
'config_version': source.config_version,
|
||||
}
|
||||
|
||||
forbidden = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{source_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{source_id}/inbound-report-config',
|
||||
json=_dbs_payload(), headers=_headers('receipt-user', 'user'),
|
||||
)
|
||||
assert forbidden.status_code == 403
|
||||
|
||||
response = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{source_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{source_id}/inbound-report-config',
|
||||
json=_dbs_payload(), headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
assert response.status_code == 200
|
||||
@@ -74,13 +76,14 @@ def test_admin_saves_independent_dbs_receipt_config_and_audit(app, client):
|
||||
assert config['report_path_json']['report_group'] == 'Inbound'
|
||||
|
||||
with app.app_context():
|
||||
source = ShippingInventorySource.query.get(source_id)
|
||||
# 关键断言:收料配置不会借由站点抽屉保存改写库存 RPA 定义。
|
||||
assert source.report_path_json == inventory_before['path']
|
||||
assert source.query_parameters_json == inventory_before['parameters']
|
||||
source = FreightRpaSource.query.get(source_id)
|
||||
# 关键断言:收料配置不会借由站点抽屉保存改写库存 RPA 定义(s18 起读配置行)。
|
||||
onhand_config = source.onhand_report_config
|
||||
assert onhand_config.report_path_json == inventory_before['path']
|
||||
assert onhand_config.query_parameters_json == inventory_before['parameters']
|
||||
assert source.config_version == inventory_before['config_version']
|
||||
audit = ShippingAuditEvent.query.filter_by(
|
||||
event_type='shipping_receipt_report_config_saved', aggregate_id=str(source_id),
|
||||
event_type='shipping_inbound_report_config_saved', aggregate_id=str(source_id),
|
||||
).one()
|
||||
assert audit.before_snapshot_json is None
|
||||
assert audit.after_snapshot_json['query_parameters_json'][0]['values'] == ['AWSDU', 'AWSDU-02']
|
||||
@@ -91,17 +94,18 @@ def test_receipt_config_rejects_date_selector_and_invalid_connector_rules(app, c
|
||||
app.config['AUTH_JWT_REQUIRED'] = False
|
||||
with app.app_context():
|
||||
_create_users()
|
||||
dbs = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
dbs = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
dbs_id = dbs.id
|
||||
from app import db
|
||||
crane_profile = dbs.rpa_profile.__class__(
|
||||
profile_code='CRANE_RECEIPT_CFG', display_name='Crane Receipt', connector_type='crane',
|
||||
login_url='https://crane.example.invalid', login_config_json={'auth_mode': 'password'},
|
||||
)
|
||||
crane_source = ShippingInventorySource(
|
||||
# s18 起站点行不再承载报表路径/查询条件;收料配置测试无需在手配置行。
|
||||
crane_source = FreightRpaSource(
|
||||
source_code='CRANE_RECEIPT_CFG', display_name='Crane Receipt', connector_type='crane',
|
||||
rpa_profile=crane_profile, warehouse_resolution_mode='fixed', fixed_warehouse_id='CRANE',
|
||||
report_path_json={}, query_parameters_json=[], enabled=False,
|
||||
enabled=False,
|
||||
)
|
||||
db.session.add(crane_source)
|
||||
db.session.commit()
|
||||
@@ -110,7 +114,7 @@ def test_receipt_config_rejects_date_selector_and_invalid_connector_rules(app, c
|
||||
invalid_date = _dbs_payload()
|
||||
invalid_date['query_parameters_json'] = [{'name': 'Report Date', 'mode': 'single', 'values': ['2026-08-19'], 'required': False, 'select_all': False}]
|
||||
response = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{dbs_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{dbs_id}/inbound-report-config',
|
||||
json=invalid_date, headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
assert response.status_code == 400
|
||||
@@ -119,7 +123,7 @@ def test_receipt_config_rejects_date_selector_and_invalid_connector_rules(app, c
|
||||
invalid_selector = _dbs_payload()
|
||||
invalid_selector['query_parameters_json'] = [{'name': 'Owner', 'mode': 'single', 'values': [], 'selector': '#owner'}]
|
||||
response = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{dbs_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{dbs_id}/inbound-report-config',
|
||||
json=invalid_selector, headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
assert response.status_code == 400
|
||||
@@ -129,7 +133,7 @@ def test_receipt_config_rejects_date_selector_and_invalid_connector_rules(app, c
|
||||
missing_warehouse = _dbs_payload()
|
||||
missing_warehouse['query_parameters_json'] = [{'name': 'Owner', 'mode': 'single', 'values': ['AWS'], 'required': False, 'select_all': False}]
|
||||
response = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{dbs_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{dbs_id}/inbound-report-config',
|
||||
json=missing_warehouse, headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
assert response.status_code == 200
|
||||
@@ -139,7 +143,7 @@ def test_receipt_config_rejects_date_selector_and_invalid_connector_rules(app, c
|
||||
empty_warehouse = _dbs_payload()
|
||||
empty_warehouse['query_parameters_json'] = [{'name': 'Warehouse', 'mode': 'multi_text', 'values': [], 'required': False, 'select_all': False}]
|
||||
response = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{dbs_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{dbs_id}/inbound-report-config',
|
||||
json=empty_warehouse, headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
assert response.status_code == 200
|
||||
@@ -151,7 +155,7 @@ def test_receipt_config_rejects_date_selector_and_invalid_connector_rules(app, c
|
||||
'query_parameters_json': [],
|
||||
}
|
||||
response = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{crane_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{crane_id}/inbound-report-config',
|
||||
json=invalid_crane, headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
assert response.status_code == 400
|
||||
@@ -161,9 +165,9 @@ def test_receipt_config_rejects_date_selector_and_invalid_connector_rules(app, c
|
||||
def _create_parsing_profile(profile_code: str, *, status: str, purpose: str):
|
||||
"""创建入站/在手解析 Profile 种子;定义仅用于绑定校验,不参与解析。"""
|
||||
from app import db
|
||||
from app.models import ShippingInventoryParsingProfile
|
||||
from app.models import FreightRpaParsingProfile
|
||||
|
||||
profile = ShippingInventoryParsingProfile(
|
||||
profile = FreightRpaParsingProfile(
|
||||
purpose=purpose, profile_code=profile_code, display_name=f'{profile_code} 规则',
|
||||
version=1, status=status, file_format='xlsx',
|
||||
definition_json={'sheet_name': 'Movement', 'header_row_index': 1,
|
||||
@@ -181,14 +185,14 @@ def test_receipt_config_binds_published_inbound_profile(app, client):
|
||||
app.config['AUTH_JWT_REQUIRED'] = False
|
||||
with app.app_context():
|
||||
_create_users()
|
||||
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
source_id = source.id
|
||||
profile = _create_parsing_profile('CRANE_MOVE_STD', status='published', purpose='inbound')
|
||||
profile_id = profile.id
|
||||
|
||||
payload = {**_dbs_payload(), 'parsing_profile_id': profile_id}
|
||||
response = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{source_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{source_id}/inbound-report-config',
|
||||
json=payload, headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
assert response.status_code == 200
|
||||
@@ -200,7 +204,7 @@ def test_receipt_config_binds_published_inbound_profile(app, client):
|
||||
|
||||
from app.models import ShippingAuditEvent
|
||||
audit = ShippingAuditEvent.query.filter_by(
|
||||
event_type='shipping_receipt_report_config_saved', aggregate_id=str(source_id),
|
||||
event_type='shipping_inbound_report_config_saved', aggregate_id=str(source_id),
|
||||
).order_by(ShippingAuditEvent.id.desc()).first()
|
||||
assert audit.metadata_json['parsing_profile_id'] == profile_id
|
||||
|
||||
@@ -210,7 +214,7 @@ def test_receipt_config_rejects_draft_or_non_inbound_profile(app, client):
|
||||
app.config['AUTH_JWT_REQUIRED'] = False
|
||||
with app.app_context():
|
||||
_create_users()
|
||||
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
source_id = source.id
|
||||
draft = _create_parsing_profile('MOVE_DRAFT', status='draft', purpose='inbound')
|
||||
onhand_profile = _create_parsing_profile('INV_PUBLISHED', status='published', purpose='onhand')
|
||||
@@ -218,7 +222,7 @@ def test_receipt_config_rejects_draft_or_non_inbound_profile(app, client):
|
||||
|
||||
for profile_id in cases:
|
||||
response = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{source_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{source_id}/inbound-report-config',
|
||||
json={**_dbs_payload(), 'parsing_profile_id': profile_id},
|
||||
headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
@@ -232,20 +236,20 @@ def test_receipt_config_empty_profile_id_unbinds(app, client):
|
||||
app.config['AUTH_JWT_REQUIRED'] = False
|
||||
with app.app_context():
|
||||
_create_users()
|
||||
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
source_id = source.id
|
||||
profile = _create_parsing_profile('MOVE_UNBIND', status='published', purpose='inbound')
|
||||
profile_id = profile.id
|
||||
|
||||
bound = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{source_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{source_id}/inbound-report-config',
|
||||
json={**_dbs_payload(), 'parsing_profile_id': profile_id},
|
||||
headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
assert bound.status_code == 200
|
||||
|
||||
unbound = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{source_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{source_id}/inbound-report-config',
|
||||
json={**_dbs_payload(), 'parsing_profile_id': None},
|
||||
headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
@@ -260,15 +264,16 @@ def test_crane_receipt_config_rejects_query_parameters(app, client):
|
||||
with app.app_context():
|
||||
_create_users()
|
||||
from app import db
|
||||
dbs = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
dbs = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
crane_profile = dbs.rpa_profile.__class__(
|
||||
profile_code='CRANE_RECEIPT_DEFAULT_CFG', display_name='Crane Receipt Defaults', connector_type='crane',
|
||||
login_url='https://crane.example.invalid', login_config_json={'auth_mode': 'password'},
|
||||
)
|
||||
crane_source = ShippingInventorySource(
|
||||
# s18 起站点行不再承载报表路径/查询条件;收料配置测试无需在手配置行。
|
||||
crane_source = FreightRpaSource(
|
||||
source_code='CRANE_RECEIPT_DEFAULT_CFG', display_name='Crane Receipt Defaults', connector_type='crane',
|
||||
rpa_profile=crane_profile, warehouse_resolution_mode='fixed', fixed_warehouse_id='CRANE',
|
||||
report_path_json={}, query_parameters_json=[], enabled=False,
|
||||
enabled=False,
|
||||
)
|
||||
db.session.add(crane_source)
|
||||
db.session.commit()
|
||||
@@ -279,7 +284,7 @@ def test_crane_receipt_config_rejects_query_parameters(app, client):
|
||||
'query_parameters_json': [],
|
||||
}
|
||||
response = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{crane_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{crane_id}/inbound-report-config',
|
||||
json=default_query, headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
assert response.status_code == 200
|
||||
@@ -289,7 +294,7 @@ def test_crane_receipt_config_rejects_query_parameters(app, client):
|
||||
{'name': 'material', 'mode': 'single', 'values': ['PN-01'], 'required': False, 'select_all': False},
|
||||
]}
|
||||
rejected = client.put(
|
||||
f'/api/admin/shipping-notice/sources/{crane_id}/receipt-report-config',
|
||||
f'/api/admin/freight-rpa/sources/{crane_id}/inbound-report-config',
|
||||
json=configured, headers=_headers('receipt-admin', 'admin'),
|
||||
)
|
||||
assert rejected.status_code == 400
|
||||
@@ -299,22 +304,22 @@ def test_crane_receipt_config_rejects_query_parameters(app, client):
|
||||
def test_retire_rejects_profile_bound_by_receipt_report_config(app):
|
||||
"""绑定收料报表配置的 published 解析 Profile 退役必须被拒(退役守卫补查)。
|
||||
|
||||
背景:retire 此前只核查库存源(ShippingInventorySource)绑定,遗漏了
|
||||
收料报表配置(ShippingReceiptReportConfig.parsing_profile_id)——入站文件
|
||||
背景:retire 此前只核查库存源(FreightRpaSource)绑定,遗漏了
|
||||
收料报表配置(FreightRpaInboundReportConfig.parsing_profile_id)——入站文件
|
||||
解析链会因规则退役静默失去规则。守卫补查后两者任一绑定都返回
|
||||
SHIPPING.INVENTORY_PARSING_PROFILE_RETIRE_BLOCKED。
|
||||
SHIPPING.ONHAND_PARSING_PROFILE_RETIRE_BLOCKED。
|
||||
"""
|
||||
from app import db
|
||||
from app.models import ShippingReceiptReportConfig
|
||||
from app.services.shipping_notice import inventory_parsing_profile
|
||||
from app.models import FreightRpaInboundReportConfig
|
||||
from app.services.shipping_notice import onhand_parsing_profile
|
||||
|
||||
app.config['AUTH_JWT_REQUIRED'] = False
|
||||
with app.app_context():
|
||||
_create_users()
|
||||
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
profile = _create_parsing_profile('MOVE_RETIRE_GUARD', status='published', purpose='inbound')
|
||||
db.session.add(ShippingReceiptReportConfig(
|
||||
inventory_source_id=source.id, parsing_profile_id=profile.id,
|
||||
db.session.add(FreightRpaInboundReportConfig(
|
||||
source_id=source.id, parsing_profile_id=profile.id,
|
||||
report_path_json={}, query_parameters_json=[],
|
||||
))
|
||||
db.session.commit()
|
||||
@@ -322,8 +327,8 @@ def test_retire_rejects_profile_bound_by_receipt_report_config(app):
|
||||
|
||||
# 关键断言:仅绑定收料配置(无库存源绑定)也必须拒绝退役,沿用既有错误码。
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
inventory_parsing_profile.retire(profile_id)
|
||||
assert getattr(exc_info.value, 'code', '') == 'SHIPPING.INVENTORY_PARSING_PROFILE_RETIRE_BLOCKED'
|
||||
onhand_parsing_profile.retire(profile_id)
|
||||
assert getattr(exc_info.value, 'code', '') == 'SHIPPING.ONHAND_PARSING_PROFILE_RETIRE_BLOCKED'
|
||||
|
||||
# 关键断言:被拒后 Profile 状态保持 published,不得被半退役。
|
||||
assert ShippingReceiptReportConfig.query.filter_by(parsing_profile_id=profile_id).count() == 1
|
||||
assert FreightRpaInboundReportConfig.query.filter_by(parsing_profile_id=profile_id).count() == 1
|
||||
Reference in new issue
Block a user