Skip to content

Commit 910e2cd

Browse files
committed
fix: 어드민 주문 목록을 결제 시점에 따라 정렬하도록 수정
1 parent 99a2b60 commit 910e2cd

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

app/admin_api/test/shop/orders_api_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ def test_admin_list_returns_only_orders_with_payment_history_and_products(api_cl
4242
}
4343

4444

45+
@pytest.mark.django_db
46+
def test_admin_list_orders_by_first_paid_at_desc(api_client, order_factory):
47+
# 먼저 생성된 주문(= created_at 이 더 과거)이 더 최근에 결제되도록 구성.
48+
# 이렇게 해야 created_at 기본 정렬과 first_paid_at 정렬의 결과가 달라져 검증이 유효하다.
49+
older_order = order_factory(status="completed")
50+
newer_order = order_factory(status="completed")
51+
PaymentHistory.objects.filter(order=older_order).update(created_at=datetime(2026, 5, 2, tzinfo=timezone.utc))
52+
PaymentHistory.objects.filter(order=newer_order).update(created_at=datetime(2026, 5, 1, tzinfo=timezone.utc))
53+
54+
response = OrdersAdminApi(http_client=api_client).list()
55+
56+
assert response.status_code == HTTP_200_OK
57+
assert [row["id"] for row in response.json()["results"]] == [str(older_order.id), str(newer_order.id)]
58+
59+
4560
@pytest.mark.django_db
4661
def test_admin_list_filters_by_status_csv(api_client, order_factory):
4762
order_factory(status="completed")

app/admin_api/views/shop/orders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class OrderAdminViewSet(
8484
first_paid_at=_payment_history_created_at_subquery(latest=False),
8585
status_changed_at=_payment_history_created_at_subquery(latest=True),
8686
)
87-
.order_by("-created_at")
87+
.order_by(models.F("first_paid_at").desc(nulls_last=True), "-created_at")
8888
)
8989

9090
@extend_schema(

0 commit comments

Comments
 (0)