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:
hugoandCursor committed 2026-10-19 10:46:06 +08:00
1 parent ffc0d4a430
commit 39fe3c05f2
453 files changed
+17945 -8646

No files matched your search

+23 -23
View File
@@ -1,9 +1,9 @@
"""
tests/test_admin_shipping_inventory.py
用途:验证货代库存后台的只读快照/导出记录接口及管理员权限。
用途:验证货代 RPA 管理端只读快照/导出记录、配置目录与站点保存接口。
依赖:Flask 测试客户端、库存文件和排程运行模型。
逻辑:库存快照来自库存文件;没有库存文件的失败 RPA 运行也必须出现在导出记录中。
逻辑:请求打到 /api/admin/freight-rpa/;快照来自在手文件,失败排程即使没有文件也出现在导出记录中。
"""
from __future__ import annotations
@@ -12,8 +12,8 @@ from datetime import datetime
from pathlib import Path
from app import db
from app.models import ScheduleRun, ScheduleTask, ShippingInventoryFile, User
from app.models import ShippingInventorySource, ShippingRpaProfile
from app.models import ScheduleRun, ScheduleTask, FreightRpaOnhandReportFile, User
from app.models import FreightRpaSource, FreightRpaProfile
from app.services.shipping_notice.order_schema import service as order_schema_service
from tests.conftest import parse_api_data, parse_api_error
@@ -39,8 +39,8 @@ def test_inventory_snapshot_and_export_records_are_admin_only(app, client, tmp_p
_create_users()
snapshot_file = Path(tmp_path) / 'snapshot.xlsx'
snapshot_file.write_bytes(b'admin-snapshot')
file_record = ShippingInventoryFile(
inventory_file_no='SIF-ADMIN-READY', storage_path=str(snapshot_file), source_code='DBS_DUB',
file_record = FreightRpaOnhandReportFile(
onhand_file_no='SIF-ADMIN-READY', storage_path=str(snapshot_file), source_code='DBS_DUB',
warehouse_id='DUB', snapshot_status='ready', identity_status='verified',
exported_at=datetime(2026, 7, 17, 10, 0, 0), rpa_run_no='RUN-READY-01',
)
@@ -57,23 +57,23 @@ def test_inventory_snapshot_and_export_records_are_admin_only(app, client, tmp_p
))
db.session.commit()
for path in ('/api/admin/shipping-notice/snapshots', '/api/admin/shipping-notice/export-records'):
for path in ('/api/admin/freight-rpa/onhand/snapshots', '/api/admin/freight-rpa/onhand/export-records'):
forbidden = client.get(path, headers=_headers('inventory-user', 'user'))
assert forbidden.status_code == 403
assert parse_api_error(forbidden.get_json())['code'] == 'AUTH.FORBIDDEN'
snapshots = client.get('/api/admin/shipping-notice/snapshots', headers=_headers('inventory-admin', 'admin'))
snapshots = client.get('/api/admin/freight-rpa/onhand/snapshots', headers=_headers('inventory-admin', 'admin'))
assert snapshots.status_code == 200
snapshot_rows = parse_api_data(snapshots.get_json())
assert snapshot_rows[0]['inventory_file_no'] == 'SIF-ADMIN-READY'
assert 'storage_path' not in snapshot_rows[0]
assert snapshot_rows[0]['download_available'] is True
downloaded = client.get('/api/admin/shipping-notice/snapshots/1/download', headers=_headers('inventory-admin', 'admin'))
downloaded = client.get('/api/admin/freight-rpa/onhand/snapshots/1/download', headers=_headers('inventory-admin', 'admin'))
assert downloaded.status_code == 200
assert downloaded.data == b'admin-snapshot'
exports = client.get('/api/admin/shipping-notice/export-records', headers=_headers('inventory-admin', 'admin'))
exports = client.get('/api/admin/freight-rpa/onhand/export-records', headers=_headers('inventory-admin', 'admin'))
assert exports.status_code == 200
export_rows = parse_api_data(exports.get_json())
failed_row = next(item for item in export_rows if item['rpa_run_no'] == 'RUN-FAILED-01')
@@ -104,7 +104,7 @@ def test_inventory_configuration_catalog_is_admin_only_and_backend_controlled(ap
}], 'expected_lock_version': draft['lock_version']})
order_schema_service.publish(draft['id'], actor_id=None, expected_lock_version=saved['lock_version'])
path = '/api/admin/shipping-notice/configuration-catalog'
path = '/api/admin/freight-rpa/onhand/configuration-catalog'
forbidden = client.get(path, headers=_headers('inventory-user', 'user'))
assert forbidden.status_code == 403
@@ -128,8 +128,8 @@ def test_inventory_catalogs_remain_readable_before_order_schema_is_published(app
order_schema_service.initialize_schema({'display_name': '发货订单字段'}, actor_id=None)
for path in (
'/api/admin/shipping-notice/routing-fields',
'/api/admin/shipping-notice/configuration-catalog',
'/api/admin/freight-rpa/onhand/routing-fields',
'/api/admin/freight-rpa/onhand/configuration-catalog',
):
response = client.get(path, headers=_headers('inventory-admin', 'admin'))
assert response.status_code == 200
@@ -143,7 +143,7 @@ def test_inventory_source_api_saves_new_source_disabled_and_activation_reports_m
app.config['AUTH_JWT_REQUIRED'] = False
with app.app_context():
_create_users()
profile = ShippingRpaProfile(
profile = FreightRpaProfile(
profile_code='API_ACTIVATION_LOGIN', display_name='API Activation', connector_type='dbs',
login_url='https://example.invalid', login_config_json={'auth_mode': 'password'}, enabled=True,
)
@@ -162,7 +162,7 @@ def test_inventory_source_api_saves_new_source_disabled_and_activation_reports_m
},
'query_parameters_json': [],
}
created = client.post('/api/admin/shipping-notice/sources', json=payload, headers=_headers('inventory-admin', 'admin'))
created = client.post('/api/admin/freight-rpa/sources', json=payload, headers=_headers('inventory-admin', 'admin'))
assert created.status_code == 201
source = parse_api_data(created.get_json())
assert source['enabled'] is False
@@ -171,12 +171,12 @@ def test_inventory_source_api_saves_new_source_disabled_and_activation_reports_m
assert 'configuration_test' not in {item['code'] for item in source['activation']['checks']}
activation = client.post(
f"/api/admin/shipping-notice/sources/{source['id']}/activate",
f"/api/admin/freight-rpa/sources/{source['id']}/activate",
json={}, headers=_headers('inventory-admin', 'admin'),
)
assert activation.status_code == 409
error = parse_api_error(activation.get_json())
assert error['code'] == 'SHIPPING.INVENTORY_SOURCE_ACTIVATION_BLOCKED'
assert error['code'] == 'SHIPPING.ONHAND_SOURCE_ACTIVATION_BLOCKED'
assert error['details']['missing_requirements'] == ['parsing_profile', 'excel_template']
@@ -185,25 +185,25 @@ def test_latest_inventory_configuration_test_is_admin_only(app, client):
app.config['AUTH_JWT_REQUIRED'] = False
with app.app_context():
_create_users()
profile = ShippingRpaProfile(
profile = FreightRpaProfile(
profile_code='API_LATEST_TEST_LOGIN', display_name='Latest Test', connector_type='dbs',
login_url='https://example.invalid', login_config_json={'auth_mode': 'password'}, enabled=True,
)
db.session.add(profile)
source = ShippingInventorySource(
# s18 起站点行不再承载报表路径/查询条件;本用例只验证权限与空 envelope,无需配置行。
source = FreightRpaSource(
source_code='API_LATEST_TEST_SOURCE', display_name='Latest Test Source', connector_type='dbs',
rpa_profile=profile, warehouse_resolution_mode='fixed', fixed_warehouse_id='DUB',
report_path_json={'program_group': 'Bison', 'program_label': 'AWSBI', 'report_group': 'Inventory', 'report_name': 'On Hand'},
query_parameters_json=[], enabled=False,
enabled=False,
)
db.session.add(source)
db.session.commit()
source_id = source.id
forbidden = client.get(f'/api/admin/shipping-notice/sources/{source_id}/test-export/latest')
forbidden = client.get(f'/api/admin/freight-rpa/sources/{source_id}/test-export/latest')
assert forbidden.status_code in {401, 403}
response = client.get(
f'/api/admin/shipping-notice/sources/{source_id}/test-export/latest',
f'/api/admin/freight-rpa/sources/{source_id}/test-export/latest',
headers=_headers('inventory-admin', 'admin'),
)
assert response.status_code == 200