Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add ID list for order filtering (#8554)

Marcin Gębalaa605021fc906
diff --git a/saleor/graphql/order/filters.py b/saleor/graphql/order/filters.py
index 132cb3f178..18ef6ae6b5 100644
--- a/saleor/graphql/order/filters.py
+++ b/saleor/graphql/order/filters.py
@@ -137,6 +137,13 @@ def filter_is_preorder(qs, _, values):
return qs
+def filter_order_ids(qs, _, values):
+ if values:
+ _, order_ids = resolve_global_ids_to_primary_keys(values, "Order")
+ qs = qs.filter(id__in=order_ids)
+ return qs
+
+
class DraftOrderFilter(MetadataFilterBase):
customer = django_filters.CharFilter(method=filter_customer)
created = ObjectTypeFilter(input_class=DateRangeInput, method=filter_created_range)
@@ -161,6 +168,7 @@ class OrderFilter(DraftOrderFilter):
method=filter_is_click_and_collect
)
is_preorder = django_filters.BooleanFilter(method=filter_is_preorder)
+ ids = GlobalIDMultipleChoiceFilter(method=filter_order_ids)
class Meta:
model = Order
diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.py
index b7b9ef82b4..c2695199e4 100644
--- a/saleor/graphql/order/tests/test_order.py
+++ b/saleor/graphql/order/tests/test_order.py
@@ -7329,6 +7329,47 @@ def test_order_query_with_filter_search_by_product_sku_order_line(
assert order_line.product_sku in lines
+def test_orders_query_with_filter_by_orders_id(
+ orders_query_with_filter,
+ staff_api_client,
+ order,
+ permission_manage_orders,
+ channel_USD,
+):
+
+ # given
+ orders = Order.objects.bulk_create(
+ [
+ Order(
+ token=str(uuid.uuid4()),
+ user_email="[email protected]",
+ status=OrderStatus.UNFULFILLED,
+ channel=channel_USD,
+ ),
+ Order(
+ token=str(uuid.uuid4()),
+ user_email="[email protected]",
+ status=OrderStatus.FULFILLED,
+ channel=channel_USD,
+ ),
+ ]
+ )
+ orders_ids = [graphene.Node.to_global_id("Order", order.pk) for order in orders]
+ variables = {"filter": {"ids": orders_ids}}
+
+ # when
+ response = staff_api_client.post_graphql(
+ orders_query_with_filter, variables, permissions=(permission_manage_orders,)
+ )
+ content = get_graphql_content(response)
+ edges = content["data"]["orders"]["edges"]
+ response_ids = [edge["node"]["id"] for edge in edges]
+
+ # then
+ assert content["data"]["orders"]["totalCount"] == 2
+ assert all(ids in response_ids for ids in orders_ids)
+
+
def test_order_query_with_filter_search_by_product_sku_multi_order_lines(
orders_query_with_filter,
staff_api_client,
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 7d69cbef4a..d5195db8dd 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -4378,6 +4378,7 @@ input OrderFilterInput {
channels: [ID]
isClickAndCollect: Boolean
isPreorder: Boolean
+ ids: [ID]
}
type OrderFulfill {