diff --git a/tests/test_platform_fulfillment.py b/tests/test_platform_fulfillment.py index eff2a97..a1ac7c7 100644 --- a/tests/test_platform_fulfillment.py +++ b/tests/test_platform_fulfillment.py @@ -1098,6 +1098,22 @@ class TestSnapshotSync(_Base): assert service.list_tasks(self.session, flow_version=2)["pagination"]["total"] == 0 assert service.list_tasks(self.session, flow_version=1)["pagination"]["total"] == 1 + def test_legacy_task_is_frozen_against_snapshot_transitions(self): + task = self.task() + task.flow_version = 1 + self.session.commit() + + service.sync_order_snapshot( + self.session, + {"data": self.snapshot(orderStatus="refunded", douyuFulfillmentEnabled=False)}, + ) + + self.session.refresh(task) + assert task.flow_version == 1 + assert task.execution_status == "ready" + assert task.issue_code == "" + assert task.source_snapshot_json["orderStatus"] == "refunded" + def test_snapshot_after_clean_cutover_creates_clean_task(self): self.mapping() setting = self.session.get(PlatformFulfillmentSetting, 1) diff --git a/web/backend/services/platform_fulfillment/order_sync.py b/web/backend/services/platform_fulfillment/order_sync.py index 9a2c5f2..4019dc6 100644 --- a/web/backend/services/platform_fulfillment/order_sync.py +++ b/web/backend/services/platform_fulfillment/order_sync.py @@ -21,6 +21,7 @@ from ..external_order_source import ( ) from .common import ( AUTO_SYNC_INTERVAL_SECONDS, + FLOW_VERSION_LEGACY, SCOPE_ELITE, TARGET_PLATFORM, _flow_version_for_order, @@ -158,6 +159,10 @@ def _upsert_order_snapshot( .first() ) created = task is None + if task is not None and task.flow_version == FLOW_VERSION_LEGACY: + # 历史任务冻结:只保留来源快照,不参与任何自动状态迁移。 + task.source_snapshot_json = _jsonable(snapshot) + return task, created, False if task is None: task = PlatformFulfillmentTask( source_system="order_site",