feat(in-transit-transfer): 自动调拨联动收料就绪并分层来源错误
- 调度整合:退役 in_transit_receipt_file_job,收料归档收敛 shipping_receipt_rpa_archive,排程注册表统一 - 自动调拨 Job:调拨前确保各来源当日收料文件就绪(缺失自动触发收料 RPA),严格等量匹配后生成 ERP 调拨单 - worker 手动唤醒:排程工作台支持手动唤醒与 runs 透视,heartbeat 协议同步 - 收料缺失幸存 T2:parse_failed 状态落库(迁移 q4c5) - 来源错误分层与 stale 时钟换源:改挂 inventory_checked_at 库存查得时刻,展示阈值与执行门禁解耦(迁移 t5a6) - 新增 wecom_sender 企微通知:每非空 Run 汇总一条,通知失败不影响 ERP 结果 - 同步排程工作台/调拨卡片前端、chat/admin 文案四语言、RPA 脚本与测试全家
This commit is contained in:
1 parent
993e581135
commit
abf3d48927
144 files changed
+10161
-2132
No files matched your search
@@ -7,6 +7,113 @@ import hashlib
|
||||
import pytest
|
||||
|
||||
|
||||
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_receipt_rpa_finalize import (
|
||||
mark_receipt_unit_processing,
|
||||
report_receipt_batch_progress,
|
||||
)
|
||||
|
||||
with app.app_context():
|
||||
source = ShippingInventorySource.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-receipt-rpa', owner_user_id=1, cron_expr='0 8 * * *',
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
run = ScheduleRun(
|
||||
run_no='RUN-RECEIPT-LIVE', schedule_task_id=task.id, status='running',
|
||||
total_count=2, success_count=0, failed_count=0, skipped_count=0,
|
||||
response_summary_json={'awaiting_receipt_rpa': True},
|
||||
)
|
||||
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-live-progress',
|
||||
status='awaiting_rpa', config_snapshot_json={},
|
||||
)
|
||||
db.session.add(unit)
|
||||
db.session.commit()
|
||||
|
||||
marked = mark_receipt_unit_processing({
|
||||
'schema_version': 'shipping_receipt_rpa.v1',
|
||||
'callback_id': unit.callback_id,
|
||||
'status': 'processing',
|
||||
})
|
||||
assert marked['updated'] is True
|
||||
db.session.expire_all()
|
||||
assert db.session.get(ShippingReceiptRpaUnitRun, unit.id).status == 'processing'
|
||||
|
||||
progressed = report_receipt_batch_progress({
|
||||
'schema_version': 'shipping_receipt_rpa.v1',
|
||||
'schedule_run_id': run.id,
|
||||
'batch_run_no': run.run_no,
|
||||
'success_count': 1,
|
||||
'skipped_count': 0,
|
||||
'failed_count': 0,
|
||||
})
|
||||
assert progressed['updated'] is True
|
||||
db.session.expire_all()
|
||||
refreshed = db.session.get(ScheduleRun, run.id)
|
||||
assert int(refreshed.success_count or 0) == 1
|
||||
assert refreshed.response_summary_json['progress']['success_count'] == 1
|
||||
|
||||
|
||||
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
|
||||
|
||||
with app.app_context():
|
||||
source = ShippingInventorySource.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-receipt-rpa', owner_user_id=1, cron_expr='0 8 * * *',
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
run = ScheduleRun(
|
||||
run_no='RUN-RECEIPT-PROG', schedule_task_id=task.id, status='running',
|
||||
total_count=1, success_count=0, failed_count=0, skipped_count=0,
|
||||
response_summary_json={'awaiting_receipt_rpa': True},
|
||||
)
|
||||
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-progress',
|
||||
status='awaiting_rpa', config_snapshot_json={},
|
||||
)
|
||||
db.session.add(unit)
|
||||
db.session.commit()
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.receipt_report_storage._read_receipt_callback_file',
|
||||
lambda _path: b'receipt-bytes',
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.receipt_report_storage.file_asset_storage.upload_bytes',
|
||||
lambda **_kwargs: None,
|
||||
)
|
||||
payload = {
|
||||
'schema_version': 'shipping_receipt_rpa.v1',
|
||||
'callback_id': unit.callback_id,
|
||||
'status': 'success',
|
||||
'file_path': 'Z:/receipt.xlsx',
|
||||
'original_filename': 'receipt.xlsx',
|
||||
'sha256': hashlib.sha256(b'receipt-bytes').hexdigest(),
|
||||
}
|
||||
ingest_receipt_callback(payload)
|
||||
db.session.expire_all()
|
||||
refreshed = db.session.get(ScheduleRun, run.id)
|
||||
# [断言意图] success 后进度至少抬升 success_count;终态可能已 finalize 清 awaiting。
|
||||
assert int(refreshed.success_count or 0) >= 1
|
||||
|
||||
|
||||
def test_receipt_callback_archives_once_without_inventory_file(app, monkeypatch):
|
||||
"""同一 callback 重放只归档一条收料文件,绝不创建库存快照。"""
|
||||
from app import db
|
||||
@@ -105,3 +212,57 @@ def test_receipt_callback_rejects_file_outside_receipt_drop_root(app, tmp_path):
|
||||
|
||||
with pytest.raises(ValidationError, match='receipt callback file'):
|
||||
_read_receipt_callback_file(str(outside))
|
||||
|
||||
|
||||
def test_ingest_empty_persists_no_receipt_data(app):
|
||||
"""
|
||||
empty 回调须落库 no_receipt_data(对齐库存 no_inventory_data)。
|
||||
|
||||
[断言意图] 单元 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
|
||||
|
||||
with app.app_context():
|
||||
source = ShippingInventorySource.query.filter_by(source_code='DSV360_AWSDU').one()
|
||||
task = ScheduleTask(
|
||||
schedule_no='SCH-RECEIPT-EMPTY',
|
||||
name='Receipt empty',
|
||||
schedule_type='platform_job',
|
||||
platform_api_path='freight-receipt-rpa',
|
||||
owner_user_id=1,
|
||||
cron_expr='0 8 * * *',
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
run = ScheduleRun(run_no='RUN-RECEIPT-EMPTY', 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-empty',
|
||||
status='awaiting_rpa',
|
||||
config_snapshot_json={},
|
||||
)
|
||||
db.session.add(unit)
|
||||
db.session.commit()
|
||||
|
||||
result = ingest_receipt_callback({
|
||||
'schema_version': 'shipping_receipt_rpa.v1',
|
||||
'callback_id': unit.callback_id,
|
||||
'status': 'empty',
|
||||
'error_code': 'no_receipt_data',
|
||||
'error_message': 'no_receipt_data',
|
||||
})
|
||||
assert result['status'] == 'empty'
|
||||
db.session.expire_all()
|
||||
saved = db.session.get(ShippingReceiptRpaUnitRun, unit.id)
|
||||
assert saved is not None
|
||||
assert saved.status == 'empty'
|
||||
assert saved.error_code == 'no_receipt_data'
|
||||
assert saved.error_message == 'no_receipt_data'
|
||||
Reference in new issue
Block a user