fix(fulfillment): 保持外部协作人工数据并支持转人工
This commit is contained in:
@@ -607,6 +607,36 @@ class TestFulfillmentCollabSync(_Base):
|
||||
assert synced.source_task_id == task.id
|
||||
assert synced.remark == "人工备注保留"
|
||||
|
||||
def test_manual_sync_preserves_existing_collab_account_and_role(self):
|
||||
task = self.task()
|
||||
task_account = self.account("task-account")
|
||||
manual_account = self.account("manual-account")
|
||||
task.account_id = task_account.id
|
||||
manual = DouyuExternalOrder(
|
||||
order_no=task.platform_order_id,
|
||||
account_id=manual_account.id,
|
||||
account_username=manual_account.username,
|
||||
bind_game_role="人工绑定角色",
|
||||
bind_game_channel="手工渠道",
|
||||
status="to_recharge",
|
||||
)
|
||||
self.session.add(manual)
|
||||
self.session.commit()
|
||||
|
||||
synced, action = collab.sync_platform_fulfillment_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
task,
|
||||
)
|
||||
|
||||
assert action == "updated"
|
||||
assert synced.id == manual.id
|
||||
assert synced.account_id == manual_account.id
|
||||
assert synced.account_username == manual_account.username
|
||||
assert synced.bind_game_role == "人工绑定角色"
|
||||
assert synced.bind_game_channel == "手工渠道"
|
||||
assert synced.status == "to_recharge"
|
||||
|
||||
def test_manual_sync_maps_only_safe_terminal_statuses(self):
|
||||
task = self._task_with_account()
|
||||
order, _ = collab.sync_platform_fulfillment_order(
|
||||
@@ -1460,6 +1490,48 @@ class TestBindingAndCompletion(_Base):
|
||||
assert exc_info.value.status_code == 409
|
||||
assert "来源订单已取消" in str(exc_info.value.detail)
|
||||
|
||||
def test_restore_rejects_active_external_collab(self, monkeypatch):
|
||||
task = self.task()
|
||||
service.cancel_task(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
reason="客服误点取消",
|
||||
)
|
||||
account = self.account("active-collab-account")
|
||||
self.session.add(
|
||||
DouyuExternalOrder(
|
||||
order_no=task.platform_order_id,
|
||||
source_type="platform_fulfillment",
|
||||
source_task_id=task.id,
|
||||
account_id=account.id,
|
||||
account_username=account.username,
|
||||
bind_game_role="人工已绑定",
|
||||
status="to_recharge",
|
||||
)
|
||||
)
|
||||
self.session.commit()
|
||||
monkeypatch.setattr(
|
||||
service,
|
||||
"lookup_pending_manual_fulfillment",
|
||||
lambda _item_id: {
|
||||
"order_status": "paid",
|
||||
"pay_status": "paid",
|
||||
"fulfillment_issue_code": "",
|
||||
},
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
service.restore_cancelled_task(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
reason="尝试恢复已人工处理订单",
|
||||
)
|
||||
|
||||
assert exc_info.value.status_code == 409
|
||||
assert "外部协作单已在人工处理" in str(exc_info.value.detail)
|
||||
|
||||
def test_restore_rejects_terminal_source_order(self, monkeypatch):
|
||||
task = self.task()
|
||||
service.cancel_task(
|
||||
@@ -1553,6 +1625,36 @@ class TestBindingAndCompletion(_Base):
|
||||
self.session.refresh(task)
|
||||
assert task.execution_status == "cancelled"
|
||||
|
||||
def test_release_to_manual_releases_lease_without_reallocating(self):
|
||||
task = self._allocated()
|
||||
account_id = task.account_id
|
||||
lease_id = task.lease_id
|
||||
|
||||
detail = service.release_task_to_manual(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
reason="以外部单协作人工处理为准",
|
||||
)
|
||||
|
||||
self.session.refresh(task)
|
||||
lease = self.session.query(AccountLease).filter_by(id=lease_id).one()
|
||||
assert detail["task"]["executionStatus"] == "manual_required"
|
||||
assert task.account_id is None
|
||||
assert task.lease_id is None
|
||||
assert task.next_allocate_at is None
|
||||
assert task.issue_code == "manual_required"
|
||||
assert task.last_error == "以外部单协作人工处理为准"
|
||||
assert lease.status == "released"
|
||||
assert lease.release_reason == "platform_fulfillment_manual"
|
||||
event = (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="released_to_manual")
|
||||
.one()
|
||||
)
|
||||
assert event.detail_json["releasedAccountId"] == account_id
|
||||
assert event.detail_json["releasedLeaseId"] == lease_id
|
||||
|
||||
def test_refresh_binding_maps_role_ready(self, monkeypatch):
|
||||
notified: list[int] = []
|
||||
monkeypatch.setattr(
|
||||
|
||||
Reference in New Issue
Block a user