fix(fulfillment): 取消商品限时兑换未开始对提前选号绑定的限制
This commit is contained in:
@@ -1695,8 +1695,8 @@ class TestAccountSelection(_Base):
|
||||
assert detail["task"]["executionStatus"] == "allocated"
|
||||
assert detail["task"]["exchangeStatus"] == "waiting_release"
|
||||
|
||||
def test_direct_sale_still_blocks_when_commodity_not_open(self):
|
||||
self.account("direct-future", availability="not_open")
|
||||
def test_direct_sale_allows_allocation_and_advance_binding_when_not_open(self):
|
||||
account = self.account("direct-future", availability="not_open")
|
||||
task = self.task()
|
||||
task.sale_mode = "direct"
|
||||
self.session.commit()
|
||||
@@ -1707,8 +1707,9 @@ class TestAccountSelection(_Base):
|
||||
current=self.admin,
|
||||
)
|
||||
|
||||
assert detail["task"]["account"] is None
|
||||
assert detail["task"]["executionStatus"] == "ready"
|
||||
assert detail["task"]["account"]["id"] == account.id
|
||||
assert detail["task"]["executionStatus"] == "allocated"
|
||||
assert detail["task"]["exchangeStatus"] == "waiting_release"
|
||||
assert detail["task"]["issueCode"] == "commodity_not_open"
|
||||
|
||||
def test_capability_pool_includes_future_not_open_for_presale_only(self):
|
||||
@@ -7141,3 +7142,154 @@ class TestAllocationPolicyAndSameRoleReuse(_Base):
|
||||
assert t3.execution_status == "bound"
|
||||
assert t3.issue_code != "customer_role_bound_elsewhere"
|
||||
assert t3_old_lease.status == "released"
|
||||
|
||||
def test_bundle_missing_co_eligibility_not_masked_by_offer_before(self):
|
||||
partial = self.account("partial-before", points=8000, capability=False)
|
||||
self._add_commodity_state(partial, TRIO_BAG412, eligibility="eligible")
|
||||
self._add_commodity_state(partial, TRIO_BAG413, eligibility="eligible")
|
||||
self._add_commodity_state(partial, TRIO_BAG414, eligibility="limited")
|
||||
partial_row = (
|
||||
self.session.query(AccountCommodityState)
|
||||
.filter_by(account_id=partial.id, commodity_id=TRIO_BAG412)
|
||||
.one()
|
||||
)
|
||||
partial_row.offer_state = "before"
|
||||
partial_row.availability = "not_open"
|
||||
partial_row.available_from = NOW + timedelta(days=3)
|
||||
|
||||
expired = self.account("expired-trio", points=8000, capability=False)
|
||||
for cid in (TRIO_BAG412, TRIO_BAG413, TRIO_BAG414):
|
||||
self._add_commodity_state(expired, cid, eligibility="eligible")
|
||||
row = (
|
||||
self.session.query(AccountCommodityState)
|
||||
.filter_by(account_id=expired.id, commodity_id=cid)
|
||||
.one()
|
||||
)
|
||||
row.valid_until = NOW - timedelta(minutes=10)
|
||||
|
||||
task = self._create_commodity_task(
|
||||
commodity_id=TRIO_BAG412,
|
||||
order_suffix="trio-before-gap",
|
||||
role_name="联合缺口玩家",
|
||||
)
|
||||
task.sale_mode = "presale"
|
||||
self.session.commit()
|
||||
|
||||
detail = service.allocate_task(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
)
|
||||
|
||||
assert detail["task"]["account"] is None
|
||||
assert detail["task"]["executionStatus"] == "ready"
|
||||
assert detail["task"]["issueCode"] == "bundle_co_eligibility_missing"
|
||||
queued = (
|
||||
self.session.query(AccountWorkItem)
|
||||
.filter(
|
||||
AccountWorkItem.account_id == expired.id,
|
||||
AccountWorkItem.work_type == WORK_STOREHOME_SYNC,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
assert queued
|
||||
|
||||
def test_reallocate_same_role_respects_bundle_requirements_and_before_open(self):
|
||||
acc_partial = self.account("rebind-partial", points=24000, capability=False)
|
||||
self._add_commodity_state(acc_partial, TRIO_BAG412, eligibility="eligible")
|
||||
self._add_commodity_state(acc_partial, TRIO_BAG413, eligibility="eligible")
|
||||
self._add_commodity_state(acc_partial, TRIO_BAG414, eligibility="limited")
|
||||
|
||||
acc_full = self.account("rebind-full", points=24000, capability=False)
|
||||
for cid in (TRIO_BAG412, TRIO_BAG413, TRIO_BAG414):
|
||||
self._add_commodity_state(acc_full, cid, eligibility="eligible")
|
||||
row = (
|
||||
self.session.query(AccountCommodityState)
|
||||
.filter_by(account_id=acc_full.id, commodity_id=cid)
|
||||
.one()
|
||||
)
|
||||
row.offer_state = "before"
|
||||
row.availability = "not_open"
|
||||
row.available_from = NOW + timedelta(days=3)
|
||||
|
||||
acc_other = self.account("rebind-other", points=24000, capability=False)
|
||||
self._add_commodity_state(acc_other, TRIO_BAG414, eligibility="eligible")
|
||||
self._add_commodity_state(acc_other, TRIO_BAG412, eligibility="eligible")
|
||||
self._add_commodity_state(acc_other, TRIO_BAG413, eligibility="eligible")
|
||||
|
||||
t_partial = self._create_commodity_task(
|
||||
commodity_id=TRIO_BAG412,
|
||||
order_suffix="rebind-partial",
|
||||
role_name="玩家甲",
|
||||
)
|
||||
t_partial.account_id = acc_partial.id
|
||||
t_partial.binding_status = "bound"
|
||||
t_partial.execution_status = "bound"
|
||||
|
||||
lease_partial = AccountLease(
|
||||
account_id=acc_partial.id,
|
||||
holder_user_id=self.admin_id,
|
||||
purpose="platform_fulfillment",
|
||||
batch_id=f"pf:{t_partial.id}",
|
||||
status="active",
|
||||
expires_at=NOW + timedelta(days=7),
|
||||
)
|
||||
self.session.add(lease_partial)
|
||||
self.session.flush()
|
||||
t_partial.lease_id = lease_partial.id
|
||||
|
||||
t_full = self._create_commodity_task(
|
||||
commodity_id=TRIO_BAG412,
|
||||
order_suffix="rebind-full",
|
||||
role_name="玩家乙",
|
||||
)
|
||||
lease_full = AccountLease(
|
||||
account_id=acc_full.id,
|
||||
holder_user_id=self.admin_id,
|
||||
purpose="platform_fulfillment",
|
||||
batch_id=f"pf:{t_full.id}",
|
||||
status="active",
|
||||
expires_at=NOW + timedelta(days=7),
|
||||
)
|
||||
self.session.add(lease_full)
|
||||
self.session.flush()
|
||||
t_full.account_id = acc_full.id
|
||||
t_full.lease_id = lease_full.id
|
||||
t_full.binding_status = "bound"
|
||||
t_full.execution_status = "bound"
|
||||
|
||||
t_target_partial = self._create_commodity_task(
|
||||
commodity_id=TRIO_BAG414,
|
||||
order_suffix="rebind-target-partial",
|
||||
role_name="玩家甲",
|
||||
)
|
||||
t_target_partial.sale_mode = "direct"
|
||||
t_target_partial.account_id = acc_other.id
|
||||
|
||||
t_target = self._create_commodity_task(
|
||||
commodity_id=TRIO_BAG414,
|
||||
order_suffix="rebind-target",
|
||||
role_name="玩家乙",
|
||||
)
|
||||
t_target.sale_mode = "direct"
|
||||
t_target.account_id = acc_other.id
|
||||
self.session.commit()
|
||||
|
||||
assert not service.allocation.try_reallocate_task_to_same_role(
|
||||
self.session,
|
||||
task=t_target_partial,
|
||||
current=self.admin,
|
||||
role_name="玩家甲",
|
||||
preferred_account_id=acc_partial.id,
|
||||
)
|
||||
assert service.allocation.try_reallocate_task_to_same_role(
|
||||
self.session,
|
||||
task=t_target,
|
||||
current=self.admin,
|
||||
role_name="玩家乙",
|
||||
preferred_account_id=acc_full.id,
|
||||
)
|
||||
self.session.refresh(t_target)
|
||||
assert t_target.account_id == acc_full.id
|
||||
assert t_target.binding_status == "bound"
|
||||
assert t_target.exchange_status == "waiting_release"
|
||||
|
||||
Reference in New Issue
Block a user