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

@@ -7,17 +7,43 @@ import hashlib
import pytest
def _register_legacy_terminal_handler(unit):
"""注册测试用 inbound 事实处理函数,复刻拆分前的终态收尾(桥 + 证据同步 + finalize)。
核心逻辑:Task 6 起 ingest_inbound_callback 不再收 on_terminal 钩子,本文件
的桥接/进度断言改经 register_report_handler 注入留守的
inbound_report_storage._finish_inbound_callback_terminal(Task 7 将平移为
in_transit_transfer 的 handle_inbound_report);fact → 旧钩子实参逐字段换算,
行为与拆分前逐点一致。
"""
from app.services.freight_rpa.reports.dispatch import register_report_handler
from app.services.shipping_notice.inbound_report_storage import _finish_inbound_callback_terminal
def _handle(fact) -> None:
_finish_inbound_callback_terminal(
unit,
ok=fact.ok,
file_no=str(fact.file_id) if fact.file_id is not None else None,
file_sha256=fact.sha256,
error_code=fact.error_code,
error_message=fact.error_message,
)
register_report_handler("inbound", _handle)
return _handle
def test_receipt_unit_processing_and_batch_progress(app):
"""开始导出标记 processing;每笔完成后 batch-progress 抬升排程计数。"""
from app import db
from app.models import ScheduleRun, ScheduleTask, ShippingInventorySource, ShippingReceiptRpaUnitRun
from app.services.schedule.freight_inbound_rpa_finalize import (
from app.models import ScheduleRun, ScheduleTask, FreightRpaSource, FreightRpaInboundUnitRun
from app.services.schedule.freight_rpa_inbound_finalize import (
mark_receipt_unit_processing,
report_receipt_batch_progress,
)
with app.app_context():
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
task = ScheduleTask(
schedule_no='SCH-RECEIPT-LIVE', name='Receipt live progress', schedule_type='platform_job',
platform_api_path='freight-rpa-inbound', owner_user_id=1, cron_expr='0 8 * * *',
@@ -31,8 +57,8 @@ def test_receipt_unit_processing_and_batch_progress(app):
)
db.session.add(run)
db.session.flush()
unit = ShippingReceiptRpaUnitRun(
schedule_run_id=run.id, inventory_source_id=source.id, source_code=source.source_code,
unit = FreightRpaInboundUnitRun(
schedule_run_id=run.id, source_id=source.id, source_code=source.source_code,
connector_type='dbs', warehouse_id='AWSDU', callback_id='receipt-live-progress',
status='awaiting_rpa', config_snapshot_json={},
)
@@ -46,7 +72,7 @@ def test_receipt_unit_processing_and_batch_progress(app):
})
assert marked['updated'] is True
db.session.expire_all()
assert db.session.get(ShippingReceiptRpaUnitRun, unit.id).status == 'processing'
assert db.session.get(FreightRpaInboundUnitRun, unit.id).status == 'processing'
progressed = report_receipt_batch_progress({
'schema_version': 'freight_rpa.inbound.v1',
@@ -66,11 +92,11 @@ def test_receipt_unit_processing_and_batch_progress(app):
def test_receipt_callback_success_refreshes_schedule_progress(app, monkeypatch):
"""success 回调在 finalize 前须回写 ScheduleRun 进度计数(对齐 empty/failed)。"""
from app import db
from app.models import ScheduleRun, ScheduleTask, ShippingInventorySource, ShippingReceiptRpaUnitRun
from app.services.shipping_notice.receipt_report_storage import ingest_receipt_callback
from app.models import ScheduleRun, ScheduleTask, FreightRpaSource, FreightRpaInboundUnitRun
from app.services.shipping_notice.inbound_report_storage import ingest_receipt_callback
with app.app_context():
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
task = ScheduleTask(
schedule_no='SCH-RECEIPT-PROG', name='Receipt progress', schedule_type='platform_job',
platform_api_path='freight-rpa-inbound', owner_user_id=1, cron_expr='0 8 * * *',
@@ -84,8 +110,8 @@ def test_receipt_callback_success_refreshes_schedule_progress(app, monkeypatch):
)
db.session.add(run)
db.session.flush()
unit = ShippingReceiptRpaUnitRun(
schedule_run_id=run.id, inventory_source_id=source.id, source_code=source.source_code,
unit = FreightRpaInboundUnitRun(
schedule_run_id=run.id, source_id=source.id, source_code=source.source_code,
connector_type='dbs', warehouse_id='AWSDU', callback_id='receipt-callback-progress',
status='awaiting_rpa', config_snapshot_json={},
)
@@ -99,6 +125,7 @@ def test_receipt_callback_success_refreshes_schedule_progress(app, monkeypatch):
'app.services.freight_rpa.inbound.report_archive.file_asset_storage.upload_bytes',
lambda **_kwargs: None,
)
_register_legacy_terminal_handler(unit)
payload = {
'schema_version': 'freight_rpa.inbound.v1',
'callback_id': unit.callback_id,
@@ -117,39 +144,40 @@ def test_receipt_callback_success_refreshes_schedule_progress(app, monkeypatch):
def test_receipt_callback_archives_once_without_inventory_file(app, monkeypatch):
"""同一 callback 重放只归档一条收料文件,绝不创建库存快照。"""
from app import db
from app.models import ScheduleRun, ScheduleTask, ShippingInventoryFile, ShippingInventorySource, ShippingReceiptRpaUnitRun
from app.services.shipping_notice.receipt_report_storage import ingest_receipt_callback
from app.models import ScheduleRun, ScheduleTask, FreightRpaOnhandReportFile, FreightRpaSource, FreightRpaInboundUnitRun
from app.services.shipping_notice.inbound_report_storage import ingest_receipt_callback
with app.app_context():
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
task = ScheduleTask(schedule_no='SCH-RECEIPT-CB', name='Receipt callback', schedule_type='platform_job', platform_api_path='freight-rpa-inbound', owner_user_id=1, cron_expr='0 8 * * *')
db.session.add(task); db.session.flush()
run = ScheduleRun(run_no='RUN-RECEIPT-CB', schedule_task_id=task.id, status='running')
db.session.add(run); db.session.flush()
unit = ShippingReceiptRpaUnitRun(schedule_run_id=run.id, inventory_source_id=source.id, source_code=source.source_code, connector_type='dbs', warehouse_id='AWSDU', callback_id='receipt-callback-archive', status='awaiting_rpa', config_snapshot_json={})
unit = FreightRpaInboundUnitRun(schedule_run_id=run.id, source_id=source.id, source_code=source.source_code, connector_type='dbs', warehouse_id='AWSDU', callback_id='receipt-callback-archive', status='awaiting_rpa', config_snapshot_json={})
db.session.add(unit); db.session.commit()
monkeypatch.setattr('app.services.freight_rpa.inbound.report_archive._read_inbound_callback_file', lambda _path: b'receipt-bytes')
monkeypatch.setattr('app.services.freight_rpa.inbound.report_archive.file_asset_storage.upload_bytes', lambda **_kwargs: None)
_register_legacy_terminal_handler(unit)
payload = {'schema_version': 'freight_rpa.inbound.v1', 'callback_id': unit.callback_id, 'status': 'success', 'file_path': 'Z:/receipt.xlsx', 'original_filename': 'receipt.xlsx', 'sha256': hashlib.sha256(b'receipt-bytes').hexdigest()}
first = ingest_receipt_callback(payload)
second = ingest_receipt_callback(payload)
assert first['file_id'] == second['file_id']
assert ShippingInventoryFile.query.count() == 0
assert FreightRpaOnhandReportFile.query.count() == 0
def test_ingest_success_advances_transfer_waiting_job(app, monkeypatch):
"""收料回调 success 落归档后,必须推进调拨 waiting 来源任务(B3 接线)。"""
from app import db
from app.models import ScheduleRun, ScheduleTask, ShippingInventorySource, ShippingReceiptRpaUnitRun, TransferSourceJob, TransferRun
from app.services.shipping_notice.receipt_report_storage import ingest_receipt_callback
from app.models import ScheduleRun, ScheduleTask, FreightRpaSource, FreightRpaInboundUnitRun, TransferSourceJob, TransferRun
from app.services.shipping_notice.inbound_report_storage import ingest_receipt_callback
with app.app_context():
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
task = ScheduleTask(schedule_no='SCH-RECEIPT-CB2', name='Receipt callback 2', schedule_type='platform_job', platform_api_path='freight-rpa-inbound', owner_user_id=1, cron_expr='0 8 * * *')
db.session.add(task); db.session.flush()
run = ScheduleRun(run_no='RUN-RECEIPT-CB2', schedule_task_id=task.id, status='running')
db.session.add(run); db.session.flush()
unit = ShippingReceiptRpaUnitRun(schedule_run_id=run.id, inventory_source_id=source.id, source_code=source.source_code, connector_type='dbs', warehouse_id='AWSDU', callback_id='receipt-callback-bridge', status='awaiting_rpa', config_snapshot_json={})
unit = FreightRpaInboundUnitRun(schedule_run_id=run.id, source_id=source.id, source_code=source.source_code, connector_type='dbs', warehouse_id='AWSDU', callback_id='receipt-callback-bridge', status='awaiting_rpa', config_snapshot_json={})
db.session.add(unit)
transfer_run = TransferRun(run_no='RUN-BRIDGE-E2E', business_date='2026-09-17', status='preparing_files', trigger_type='manual')
db.session.add(transfer_run); db.session.flush()
@@ -157,6 +185,7 @@ def test_ingest_success_advances_transfer_waiting_job(app, monkeypatch):
db.session.add(job); db.session.commit()
monkeypatch.setattr('app.services.freight_rpa.inbound.report_archive._read_inbound_callback_file', lambda _path: b'receipt-bytes')
monkeypatch.setattr('app.services.freight_rpa.inbound.report_archive.file_asset_storage.upload_bytes', lambda **_kwargs: None)
_register_legacy_terminal_handler(unit)
payload = {'schema_version': 'freight_rpa.inbound.v1', 'callback_id': unit.callback_id, 'status': 'success', 'file_path': 'Z:/receipt.xlsx', 'original_filename': 'receipt.xlsx', 'sha256': hashlib.sha256(b'receipt-bytes').hexdigest()}
result = ingest_receipt_callback(payload)
@@ -170,21 +199,22 @@ def test_ingest_success_advances_transfer_waiting_job(app, monkeypatch):
def test_ingest_failed_advance_is_durable(app):
"""failed 回调推进调拨任务后必须已 commit——rollback 不得丢弃该推进(B3 持久性)。"""
from app import db
from app.models import ScheduleRun, ScheduleTask, ShippingInventorySource, ShippingReceiptRpaUnitRun, TransferSourceJob, TransferRun
from app.services.shipping_notice.receipt_report_storage import ingest_receipt_callback
from app.models import ScheduleRun, ScheduleTask, FreightRpaSource, FreightRpaInboundUnitRun, TransferSourceJob, TransferRun
from app.services.shipping_notice.inbound_report_storage import ingest_receipt_callback
with app.app_context():
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
task = ScheduleTask(schedule_no='SCH-RECEIPT-CB3', name='Receipt callback 3', schedule_type='platform_job', platform_api_path='freight-rpa-inbound', owner_user_id=1, cron_expr='0 8 * * *')
db.session.add(task); db.session.flush()
run = ScheduleRun(run_no='RUN-RECEIPT-CB3', schedule_task_id=task.id, status='running')
db.session.add(run); db.session.flush()
unit = ShippingReceiptRpaUnitRun(schedule_run_id=run.id, inventory_source_id=source.id, source_code=source.source_code, connector_type='dbs', warehouse_id='AWSDU', callback_id='receipt-callback-bridge-durable', status='awaiting_rpa', config_snapshot_json={})
unit = FreightRpaInboundUnitRun(schedule_run_id=run.id, source_id=source.id, source_code=source.source_code, connector_type='dbs', warehouse_id='AWSDU', callback_id='receipt-callback-bridge-durable', status='awaiting_rpa', config_snapshot_json={})
db.session.add(unit)
transfer_run = TransferRun(run_no='RUN-BRIDGE-E2E-FAIL', business_date='2026-09-17', status='preparing_files', trigger_type='manual')
db.session.add(transfer_run); db.session.flush()
job = TransferSourceJob(run_id=transfer_run.id, source_code=source.source_code, status='waiting_rpa_callback')
db.session.add(job); db.session.commit()
_register_legacy_terminal_handler(unit)
payload = {'schema_version': 'freight_rpa.inbound.v1', 'callback_id': unit.callback_id, 'status': 'failed', 'error_code': 'RPA_TEST_FAIL', 'error_message': 'boom'}
result = ingest_receipt_callback(payload)
@@ -221,11 +251,11 @@ def test_ingest_empty_persists_no_receipt_data(app):
[断言意图] 单元 status=empty 且 error_code/error_message 为 no_receipt_data,供管理端展示跳过原因。
"""
from app import db
from app.models import ScheduleRun, ScheduleTask, ShippingInventorySource, ShippingReceiptRpaUnitRun
from app.services.shipping_notice.receipt_report_storage import ingest_receipt_callback
from app.models import ScheduleRun, ScheduleTask, FreightRpaSource, FreightRpaInboundUnitRun
from app.services.shipping_notice.inbound_report_storage import ingest_receipt_callback
with app.app_context():
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
source = FreightRpaSource.query.filter_by(source_code='DSV360_AWSDU').one()
task = ScheduleTask(
schedule_no='SCH-RECEIPT-EMPTY',
name='Receipt empty',
@@ -239,9 +269,9 @@ def test_ingest_empty_persists_no_receipt_data(app):
run = ScheduleRun(run_no='RUN-RECEIPT-EMPTY', schedule_task_id=task.id, status='running')
db.session.add(run)
db.session.flush()
unit = ShippingReceiptRpaUnitRun(
unit = FreightRpaInboundUnitRun(
schedule_run_id=run.id,
inventory_source_id=source.id,
source_id=source.id,
source_code=source.source_code,
connector_type='dbs',
warehouse_id='AWSDU',
@@ -251,6 +281,7 @@ def test_ingest_empty_persists_no_receipt_data(app):
)
db.session.add(unit)
db.session.commit()
_register_legacy_terminal_handler(unit)
result = ingest_receipt_callback({
'schema_version': 'freight_rpa.inbound.v1',
@@ -261,7 +292,7 @@ def test_ingest_empty_persists_no_receipt_data(app):
})
assert result['status'] == 'empty'
db.session.expire_all()
saved = db.session.get(ShippingReceiptRpaUnitRun, unit.id)
saved = db.session.get(FreightRpaInboundUnitRun, unit.id)
assert saved is not None
assert saved.status == 'empty'
assert saved.error_code == 'no_receipt_data'