Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extend `user.orders` with where option (#18872)
Iga Karbowiakd7231794def8
diff --git a/saleor/graphql/account/filters.py b/saleor/graphql/account/filters.pyindex 57af7916d4..f1bf4e9927 100644--- a/saleor/graphql/account/filters.py+++ b/saleor/graphql/account/filters.py@@ -36,7 +36,6 @@ from ..utils.filters import (filter_where_by_value_field,filter_where_range_field_with_conditions,)-from . import types as account_typesfrom .enums import CountryCodeEnum, StaffMemberStatus@@ -251,20 +250,28 @@ class CustomerWhereInput(WhereInputObjectType):class PermissionGroupFilter(django_filters.FilterSet):search = django_filters.CharFilter(method=filter_search)- ids = GlobalIDMultipleChoiceFilter(method=filter_by_id(account_types.Group))+ ids = GlobalIDMultipleChoiceFilter(method="filter_ids")++ @staticmethod+ def filter_ids(qs, _, value):+ from . import types as account_types++ return filter_by_id(account_types.Group)(qs, _, value)class StaffUserFilter(django_filters.FilterSet):status = EnumFilter(input_class=StaffMemberStatus, method=filter_staff_status)search = django_filters.CharFilter(method=filter_user_search)- ids = GlobalIDMultipleChoiceFilter(- method=filter_by_id(- account_types.User,- )- )+ ids = GlobalIDMultipleChoiceFilter(method="filter_ids")# TODO - Figure out after permission types# department = ObjectTypeFilterclass Meta:model = Userfields = ["status", "search"]++ @staticmethod+ def filter_ids(qs, _, value):+ from . import types as account_types++ return filter_by_id(account_types.User)(qs, _, value)diff --git a/saleor/graphql/account/tests/queries/test_me.py b/saleor/graphql/account/tests/queries/test_me.pyindex cbddc8e867..0a9947e151 100644--- a/saleor/graphql/account/tests/queries/test_me.py+++ b/saleor/graphql/account/tests/queries/test_me.py@@ -8,7 +8,7 @@ from django.utils import timezonefrom .....checkout.calculations import _fetch_checkout_prices_if_expiredfrom .....checkout.fetch import fetch_checkout_linesfrom .....order import OrderStatus-from .....order.models import FulfillmentStatus+from .....order.models import FulfillmentStatus, Orderfrom .....payment.interface import (ListStoredPaymentMethodsRequestData,PaymentGateway,@@ -727,3 +727,135 @@ def test_me_orders_pagination_has_previous_page(user_api_client, order_list):page_info = content["data"]["me"]["orders"]["pageInfo"]assert page_info["hasPreviousPage"] is Trueassert page_info["hasNextPage"] is True+++ME_ORDERS_WHERE_QUERY = """+ query Me($where: CustomerOrderWhereInput!) {+ me {+ orders(first: 10, where: $where) {+ totalCount+ edges {+ node {+ id+ number+ }+ }+ }+ }+ }+"""+++def test_me_orders_where_filter_by_ids(user_api_client, order_list):+ # given+ user = user_api_client.user+ for order in order_list:+ order.user = user+ Order.objects.bulk_update(order_list, ["user"])++ target_orders = order_list[:2]+ ids = [graphene.Node.to_global_id("Order", order.pk) for order in target_orders]+ variables = {"where": {"ids": ids}}++ # when+ response = user_api_client.post_graphql(ME_ORDERS_WHERE_QUERY, variables)++ # then+ content = get_graphql_content(response)+ orders_data = content["data"]["me"]["orders"]+ assert orders_data["totalCount"] == 2+ returned_ids = {edge["node"]["id"] for edge in orders_data["edges"]}+ assert returned_ids == {+ graphene.Node.to_global_id("Order", o.pk) for o in target_orders+ }+++def test_me_orders_where_filter_by_status(user_api_client, order_list):+ # given+ user = user_api_client.user+ order_list[0].user = user+ order_list[0].status = OrderStatus.UNCONFIRMED+ order_list[1].user = user+ order_list[1].status = OrderStatus.UNFULFILLED+ order_list[2].user = user+ order_list[2].status = OrderStatus.UNFULFILLED+ Order.objects.bulk_update(order_list, ["user", "status"])++ variables = {"where": {"status": {"eq": OrderStatus.UNCONFIRMED.upper()}}}++ # when+ response = user_api_client.post_graphql(ME_ORDERS_WHERE_QUERY, variables)++ # then+ content = get_graphql_content(response)+ orders_data = content["data"]["me"]["orders"]+ assert orders_data["totalCount"] == 1+ assert orders_data["edges"][0]["node"]["id"] == graphene.Node.to_global_id(+ "Order", order_list[0].pk+ )+++def test_me_orders_where_filter_excludes_draft_orders(user_api_client, order_list):+ # given - owner has a draft order and a non-draft order+ user = user_api_client.user+ order_list[0].user = user+ order_list[0].status = OrderStatus.UNFULFILLED+ order_list[1].user = user+ order_list[1].status = OrderStatus.DRAFT+ Order.objects.bulk_update(order_list[:2], ["user", "status"])++ # when - user queries their own orders with no filter+ variables = {"where": {}}++ # then - draft order is excluded for the owner+ response = user_api_client.post_graphql(ME_ORDERS_WHERE_QUERY, variables)+ content = get_graphql_content(response)+ orders_data = content["data"]["me"]["orders"]+ returned_ids = {edge["node"]["id"] for edge in orders_data["edges"]}+ assert graphene.Node.to_global_id("Order", order_list[0].pk) in returned_ids+ assert graphene.Node.to_global_id("Order", order_list[1].pk) not in returned_ids+++def test_me_orders_where_filter_by_number(user_api_client, order_list):+ # given+ user = user_api_client.user+ for order in order_list:+ order.user = user+ Order.objects.bulk_update(order_list, ["user"])++ target_order = order_list[0]+ variables = {"where": {"number": {"eq": str(target_order.number)}}}++ # when+ response = user_api_client.post_graphql(ME_ORDERS_WHERE_QUERY, variables)++ # then+ content = get_graphql_content(response)+ orders_data = content["data"]["me"]["orders"]+ assert orders_data["totalCount"] == 1+ assert orders_data["edges"][0]["node"]["number"] == str(target_order.number)+++def test_me_orders_where_filter_by_metadata(user_api_client, order_list):+ # given+ user = user_api_client.user+ order_list[0].user = user+ order_list[0].metadata = {"key": "value"}+ order_list[1].user = user+ order_list[1].metadata = {"key": "other_value"}+ order_list[2].user = user+ order_list[2].metadata = {}+ Order.objects.bulk_update(order_list, ["user", "metadata"])++ variables = {"where": {"metadata": {"key": "key", "value": {"eq": "value"}}}}++ # when+ response = user_api_client.post_graphql(ME_ORDERS_WHERE_QUERY, variables)++ # then+ content = get_graphql_content(response)+ orders_data = content["data"]["me"]["orders"]+ assert orders_data["totalCount"] == 1+ assert orders_data["edges"][0]["node"]["id"] == graphene.Node.to_global_id(+ "Order", order_list[0].pk+ )diff --git a/saleor/graphql/account/tests/queries/test_user.py b/saleor/graphql/account/tests/queries/test_user.pyindex a5debda57c..26d7b292cf 100644--- a/saleor/graphql/account/tests/queries/test_user.py+++ b/saleor/graphql/account/tests/queries/test_user.py@@ -1346,3 +1346,114 @@ def test_query_customer_stored_payment_methods(content = get_graphql_content(response)assert content["data"]["user"]["storedPaymentMethods"] == []+++USER_ORDERS_WHERE_QUERY = """+ query User($id: ID!, $where: CustomerOrderWhereInput!) {+ user(id: $id) {+ orders(first: 10, where: $where) {+ totalCount+ edges {+ node {+ id+ number+ }+ }+ }+ }+ }+"""+++def test_user_orders_where_filter_by_status_staff(+ staff_api_client,+ customer_user,+ order_list,+ permission_group_manage_orders,+ permission_manage_users,+):+ # given+ permission_group_manage_orders.user_set.add(staff_api_client.user)+ permission_group_manage_orders.permissions.add(permission_manage_users)++ order_list[0].user = customer_user+ order_list[0].status = OrderStatus.UNCONFIRMED+ order_list[1].user = customer_user+ order_list[1].status = OrderStatus.UNFULFILLED+ order_list[2].user = customer_user+ order_list[2].status = OrderStatus.UNFULFILLED+ Order.objects.bulk_update(order_list, ["user", "status"])++ user_id = graphene.Node.to_global_id("User", customer_user.pk)+ variables = {+ "id": user_id,+ "where": {"status": {"eq": OrderStatus.UNCONFIRMED.upper()}},+ }++ # when+ response = staff_api_client.post_graphql(USER_ORDERS_WHERE_QUERY, variables)++ # then+ content = get_graphql_content(response)+ orders_data = content["data"]["user"]["orders"]+ assert orders_data["totalCount"] == 1+ assert orders_data["edges"][0]["node"]["id"] == graphene.Node.to_global_id(+ "Order", order_list[0].pk+ )+++def test_user_orders_where_filter_staff_sees_draft_orders(+ staff_api_client,+ customer_user,+ order_list,+ permission_group_manage_orders,+ permission_manage_users,+):+ # given - staff with MANAGE_ORDERS can see draft orders in where filter results+ permission_group_manage_orders.user_set.add(staff_api_client.user)+ permission_group_manage_orders.permissions.add(permission_manage_users)++ order_list[0].user = customer_user+ order_list[0].status = OrderStatus.DRAFT+ order_list[1].user = customer_user+ order_list[1].status = OrderStatus.UNFULFILLED+ Order.objects.bulk_update(order_list[:2], ["user", "status"])++ user_id = graphene.Node.to_global_id("User", customer_user.pk)+ variables = {+ "id": user_id,+ "where": {"status": {"eq": OrderStatus.DRAFT.upper()}},+ }++ # when+ response = staff_api_client.post_graphql(USER_ORDERS_WHERE_QUERY, variables)++ # then - staff can see draft orders+ content = get_graphql_content(response)+ orders_data = content["data"]["user"]["orders"]+ assert orders_data["totalCount"] == 1+ assert orders_data["edges"][0]["node"]["id"] == graphene.Node.to_global_id(+ "Order", order_list[0].pk+ )+++def test_user_orders_where_filter_no_permission(+ user_api_client,+ customer_user2,+ order_list,+):+ # given - a user trying to query another user's orders+ order_list[0].user = customer_user2+ Order.objects.bulk_update(order_list[:1], ["user"])++ user_id = graphene.Node.to_global_id("User", customer_user2.pk)+ variables = {+ "id": user_id,+ "where": {},+ }++ # when+ response = user_api_client.post_graphql(USER_ORDERS_WHERE_QUERY, variables)++ # then+ assert_no_permission(response)diff --git a/saleor/graphql/account/tests/queries/test_users.py b/saleor/graphql/account/tests/queries/test_users.pyindex 3f33053c8e..a0b19768a5 100644--- a/saleor/graphql/account/tests/queries/test_users.py+++ b/saleor/graphql/account/tests/queries/test_users.py@@ -1,5 +1,7 @@import graphene+from .....order import OrderStatus+from .....order.models import Orderfrom ....tests.utils import assert_no_permission, get_graphql_content@@ -101,3 +103,72 @@ def test_who_can_see_user(response = staff_api_client.post_graphql(query)content = get_graphql_content(response)assert content["data"]["customers"]["totalCount"] == 1+++USER_ORDERS_WHERE_QUERY = """+ query User($id: ID!, $where: CustomerOrderWhereInput) {+ user(id: $id) {+ orderswithFilter: orders(first: 10, where: $where) {+ totalCount+ edges {+ node {+ id+ number+ }+ }+ }+ orderNoFilter: orders(first: 10) {+ totalCount+ edges {+ node {+ id+ number+ }+ }+ }+ }+ }+"""+++def test_user_orders_where_filter_and_unfiltered_in_single_query(+ staff_api_client,+ customer_user,+ order_list,+ permission_group_manage_orders,+):+ # given+ permission_group_manage_orders.user_set.add(staff_api_client.user)+ order_list[0].user = customer_user+ order_list[0].status = OrderStatus.UNCONFIRMED+ order_list[1].user = customer_user+ order_list[1].status = OrderStatus.UNFULFILLED+ order_list[2].user = customer_user+ order_list[2].status = OrderStatus.UNFULFILLED+ Order.objects.bulk_update(order_list, ["user", "status"])++ user_id = graphene.Node.to_global_id("User", customer_user.pk)+ variables = {+ "id": user_id,+ "where": {"status": {"eq": OrderStatus.UNCONFIRMED.upper()}},+ }++ # when+ response = staff_api_client.post_graphql(USER_ORDERS_WHERE_QUERY, variables)++ # then+ content = get_graphql_content(response)+ user_data = content["data"]["user"]++ filtered_orders = user_data["orderswithFilter"]+ assert filtered_orders["totalCount"] == 1+ assert filtered_orders["edges"][0]["node"]["id"] == graphene.Node.to_global_id(+ "Order", order_list[0].pk+ )++ unfiltered_orders = user_data["orderNoFilter"]+ assert unfiltered_orders["totalCount"] == 3+ returned_ids = {edge["node"]["id"] for edge in unfiltered_orders["edges"]}+ assert returned_ids == {+ graphene.Node.to_global_id("Order", order.pk) for order in order_list+ }diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.pyindex 41d35fa640..591bd7e698 100644--- a/saleor/graphql/account/types.py+++ b/saleor/graphql/account/types.py@@ -33,13 +33,14 @@ from ..core.connection import (CountableConnection,create_connection_slice,create_connection_slice_for_sync_webhook_control_context,+ filter_connection_queryset,)from ..core.context import SyncWebhookControlContext, get_database_connection_name-from ..core.descriptions import ADDED_IN_319, PREVIEW_FEATURE+from ..core.descriptions import ADDED_IN_319, ADDED_IN_322, PREVIEW_FEATUREfrom ..core.doc_category import DOC_CATEGORY_USERSfrom ..core.enums import LanguageCodeEnumfrom ..core.federation import federated_entity, resolve_federation_references-from ..core.fields import ConnectionField, PermissionsField+from ..core.fields import ConnectionField, FilterConnectionField, PermissionsFieldfrom ..core.scalars import UUID, DateTimefrom ..core.tracing import traced_resolverfrom ..core.types import (@@ -57,6 +58,7 @@ from ..core.utils import from_global_id_or_error, str_to_enum, to_global_id_or_nfrom ..giftcard.dataloaders import GiftCardsByUserLoaderfrom ..meta.types import ObjectWithMetadatafrom ..order.dataloaders import OrderByIdLoader, OrderLineByIdLoader, OrdersByUserLoader+from ..order.filters import CustomerOrderWhereInputfrom ..payment.types import StoredPaymentMethodfrom ..plugins.dataloaders import get_plugin_manager_promisefrom ..utils import format_permissions_for_display, get_user_or_app_from_context@@ -407,8 +409,11 @@ class User(ModelObjectType[models.User]):description="A note about the customer.",permissions=[AccountPermissions.MANAGE_USERS, AccountPermissions.MANAGE_STAFF],)- orders = ConnectionField(+ orders = FilterConnectionField("saleor.graphql.order.types.OrderCountableConnection",+ where=CustomerOrderWhereInput(+ description="Where filtering options for orders." + ADDED_IN_322+ ),description=("List of user's orders. The query will not initiate any external requests, ""including filtering available shipping methods, or performing external "@@ -684,6 +689,42 @@ class User(ModelObjectType[models.User]):)requester = user_or_app+ where_input = kwargs.get("where")++ if where_input:+ # Queryset-based path to support `where` filtering.+ def _build_orders_qs(accessible_channels=None):+ database_connection_name = get_database_connection_name(info.context)+ qs = models.Order.objects.using(database_connection_name).filter(+ user_id=root.id+ )+ if not requester.has_perm(OrderPermissions.MANAGE_ORDERS):+ qs = qs.non_draft()+ # Return only orders from channels that the user has access to.+ # The app has access to all channels.+ if root != requester and accessible_channels is not None:+ channel_ids = [channel.id for channel in accessible_channels]+ qs = qs.filter(channel_id__in=channel_ids)+ qs = filter_connection_queryset(+ qs, kwargs, allow_replica=info.context.allow_replica+ )+ return create_connection_slice_for_sync_webhook_control_context(+ qs,+ info,+ kwargs,+ OrderCountableConnection,+ allow_sync_webhooks=False,+ )++ if isinstance(requester, models.User) and root != requester:+ return (+ AccessibleChannelsByUserIdLoader(info.context)+ .load(requester.id)+ .then(_build_orders_qs)+ )+ return _build_orders_qs()++ # Dataloader-based path for unfiltered queries.def _resolve_orders(data):orders = data[0]accessible_channels = data[1] if len(data) == 2 else None@@ -692,7 +733,6 @@ class User(ModelObjectType[models.User]):orders = [order for order in orders if order.status != OrderStatus.DRAFT]-# Return only orders from channels that the user has access to.# The app has access to all channels.if root != user_or_app and accessible_channels is not None:@@ -700,7 +740,6 @@ class User(ModelObjectType[models.User]):orders = [order for order in orders if order.channel_id in accessible_channels]-return create_connection_slice_for_sync_webhook_control_context(orders,info,@@ -714,7 +753,6 @@ class User(ModelObjectType[models.User]):to_fetch.append(AccessibleChannelsByUserIdLoader(info.context).load(requester.id))-return Promise.all(to_fetch).then(_resolve_orders)@staticmethoddiff --git a/saleor/graphql/order/filters.py b/saleor/graphql/order/filters.pyindex c5e18cdf93..c05ec1fb93 100644--- a/saleor/graphql/order/filters.py+++ b/saleor/graphql/order/filters.py@@ -273,7 +273,7 @@ def filter_by_checkout_tokens(qs, _, values):return qs.filter(checkout_token__in=values)-def filter_has_invoices(qs, value):+def filter_where_has_invoices(qs, _, value):if value is None:return qs.none()invoices = Invoice.objects.using(qs.db).filter(order_id=OuterRef("id"))@@ -282,6 +282,22 @@ def filter_has_invoices(qs, value):return qs.filter(~Exists(invoices))+def filter_where_invoices(qs, _, value):+ if not value:+ return qs.none()++ lookup = Q()+ for input_data in value:+ if filter_value := input_data.get("created_at"):+ invoices = filter_where_by_range_field(+ Invoice.objects.using(qs.db), "created_at", filter_value+ )+ lookup &= Q(Exists(invoices.filter(order_id=OuterRef("id"))))+ if lookup:+ return qs.filter(lookup)+ return qs.none()++def filter_has_fulfillments(qs, value):if value is None:return qs.none()@@ -783,6 +799,162 @@ def filter_where_shipping_address(qs, _, value):return qs.filter(Exists(address_qs.filter(id=OuterRef("shipping_address_id"))))+def filter_where_is_gift_card_used(qs, _, value):+ if value is None:+ return qs.none()+ return filter_by_gift_card(qs, value, GiftCardEvents.USED_IN_ORDER)+++def filter_where_is_gift_card_bought(qs, _, value):+ if value is None:+ return qs.none()+ return filter_by_gift_card(qs, value, GiftCardEvents.BOUGHT)+++def filter_where_status(qs, _, value):+ return filter_where_by_value_field(qs, "status", value)+++def filter_where_checkout_token(qs, _, value):+ return filter_where_by_value_field(qs, "checkout_token", value)+++def filter_where_checkout_id(qs, _, value):+ return filter_where_by_id_field(qs, "checkout_token", value, "Checkout")+++def filter_where_has_fulfillments(qs, _, value):+ return filter_has_fulfillments(qs, value)+++def filter_where_fulfillments(qs, _, value):+ return filter_fulfillments(qs, value)+++class CustomerOrderWhere(MetadataWhereBase):+ ids = GlobalIDMultipleChoiceWhereFilter(method=filter_by_ids("Order"))+ number = OperationObjectTypeWhereFilter(+ input_class=IntFilterInput,+ method=filter_where_number,+ help_text="Filter by order number.",+ )+ channel_id = OperationObjectTypeWhereFilter(+ input_class=GlobalIDFilterInput,+ method=filter_where_channel_id,+ help_text="Filter by channel.",+ )+ created_at = ObjectTypeWhereFilter(+ input_class=DateTimeRangeInput,+ method=filter_where_created_at_range,+ help_text="Filter order by created at date.",+ )+ updated_at = ObjectTypeWhereFilter(+ input_class=DateTimeRangeInput,+ method=filter_where_updated_at_range,+ help_text="Filter order by updated at date.",+ )+ user_email = OperationObjectTypeWhereFilter(+ input_class=StringFilterInput,+ method=filter_where_user_email,+ help_text="Filter by user email.",+ )+ authorize_status = OperationObjectTypeWhereFilter(+ input_class=OrderAuthorizeStatusEnumFilterInput,+ method=filter_where_authorize_status,+ help_text="Filter by authorize status.",+ )+ charge_status = OperationObjectTypeWhereFilter(+ input_class=OrderChargeStatusEnumFilterInput,+ method=filter_where_charge_status,+ help_text="Filter by charge status.",+ )+ status = OperationObjectTypeWhereFilter(+ input_class=OrderStatusEnumFilterInput,+ method=filter_where_status,+ help_text="Filter by order status.",+ )+ checkout_token = OperationObjectTypeWhereFilter(+ UUIDFilterInput,+ method=filter_where_checkout_token,+ help_text="Filter by checkout token.",+ )+ checkout_id = OperationObjectTypeWhereFilter(+ input_class=GlobalIDFilterInput,+ method=filter_where_checkout_id,+ help_text="Filter by checkout id.",+ )+ is_click_and_collect = BooleanWhereFilter(+ method=filter_where_is_click_and_collect,+ help_text="Filter by whether the order uses the click and collect delivery method.",+ )+ is_gift_card_used = BooleanWhereFilter(+ method=filter_where_is_gift_card_used,+ help_text="Filter based on whether a gift card was used in the order.",+ )+ is_gift_card_bought = BooleanWhereFilter(+ method=filter_where_is_gift_card_bought,+ help_text="Filter based on whether the order includes a gift card purchase.",+ )+ voucher_code = OperationObjectTypeWhereFilter(+ input_class=StringFilterInput,+ method=filter_where_voucher_code,+ help_text="Filter by voucher code used in the order.",+ )+ has_invoices = BooleanWhereFilter(+ method=filter_where_has_invoices,+ help_text="Filter by whether the order has any invoices.",+ )+ invoices = ListObjectTypeWhereFilter(+ input_class=InvoiceFilterInput,+ method=filter_where_invoices,+ help_text=(+ "Filter by invoice data associated with the order."+ + LIST_INPUT_OBJECT_DESCRIPTION+ ),+ )+ has_fulfillments = BooleanWhereFilter(+ method=filter_where_has_fulfillments,+ help_text="Filter by whether the order has any fulfillments.",+ )+ lines_count = OperationObjectTypeWhereFilter(+ input_class=IntFilterInput,+ method=filter_where_lines_count,+ help_text="Filter by number of lines in the order.",+ )+ total_gross = ObjectTypeWhereFilter(+ input_class=PriceFilterInput,+ method=filter_where_total_gross,+ help_text="Filter by total gross amount of the order.",+ )+ total_net = ObjectTypeWhereFilter(+ input_class=PriceFilterInput,+ method=filter_where_total_net,+ help_text="Filter by total net amount of the order.",+ )+ product_type_id = OperationObjectTypeWhereFilter(+ input_class=GlobalIDFilterInput,+ method=filter_where_product_type_id,+ help_text="Filter by the product type of related order lines.",+ )+ billing_address = ObjectTypeWhereFilter(+ input_class=AddressFilterInput,+ method=filter_where_billing_address,+ help_text="Filter by billing address of the order.",+ )+ shipping_address = ObjectTypeWhereFilter(+ input_class=AddressFilterInput,+ method=filter_where_shipping_address,+ help_text="Filter by shipping address of the order.",+ )+++class CustomerOrderWhereInput(WhereInputObjectType):+ class Meta:+ doc_category = DOC_CATEGORY_ORDERS+ filterset_class = CustomerOrderWhere+ descriptions = "Filtering options for customer orders." + ADDED_IN_322++class OrderWhere(MetadataWhereBase):ids = GlobalIDMultipleChoiceWhereFilter(method=filter_by_ids("Order"))number = OperationObjectTypeWhereFilter(@@ -827,17 +999,17 @@ class OrderWhere(MetadataWhereBase):)status = OperationObjectTypeWhereFilter(input_class=OrderStatusEnumFilterInput,- method="filter_status",+ method=filter_where_status,help_text="Filter by order status.",)checkout_token = OperationObjectTypeWhereFilter(UUIDFilterInput,- method="filter_checkout_token",+ method=filter_where_checkout_token,help_text="Filter by checkout token.",)checkout_id = OperationObjectTypeWhereFilter(input_class=GlobalIDFilterInput,- method="filter_checkout_id",+ method=filter_where_checkout_id,help_text="Filter by checkout id.",)is_click_and_collect = BooleanWhereFilter(@@ -845,11 +1017,11 @@ class OrderWhere(MetadataWhereBase):help_text="Filter by whether the order uses the click and collect delivery method.",)is_gift_card_used = BooleanWhereFilter(- method="filter_is_gift_card_used",+ method=filter_where_is_gift_card_used,help_text="Filter based on whether a gift card was used in the order.",)is_gift_card_bought = BooleanWhereFilter(- method="filter_is_gift_card_bought",+ method=filter_where_is_gift_card_bought,help_text="Filter based on whether the order includes a gift card purchase.",)voucher_code = OperationObjectTypeWhereFilter(@@ -858,24 +1030,24 @@ class OrderWhere(MetadataWhereBase):help_text="Filter by voucher code used in the order.",)has_invoices = BooleanWhereFilter(- method="filter_has_invoices",+ method=filter_where_has_invoices,help_text="Filter by whether the order has any invoices.",)invoices = ListObjectTypeWhereFilter(input_class=InvoiceFilterInput,- method="filter_invoices",+ method=filter_where_invoices,help_text=("Filter by invoice data associated with the order."+ LIST_INPUT_OBJECT_DESCRIPTION),)has_fulfillments = BooleanWhereFilter(- method="filter_has_fulfillments",+ method=filter_where_has_fulfillments,help_text="Filter by whether the order has any fulfillments.",)fulfillments = ListObjectTypeWhereFilter(input_class=FulfillmentFilterInput,- method="filter_fulfillments",+ method=filter_where_fulfillments,help_text=("Filter by fulfillment data associated with the order."+ LIST_INPUT_OBJECT_DESCRIPTION@@ -933,58 +1105,6 @@ class OrderWhere(MetadataWhereBase):help_text="Filter by shipping address of the order.",)- @staticmethod- def filter_status(qs, _, value):- return filter_where_by_value_field(qs, "status", value)-- @staticmethod- def filter_checkout_token(qs, _, value):- return filter_where_by_value_field(qs, "checkout_token", value)-- @staticmethod- def filter_checkout_id(qs, _, value):- return filter_where_by_id_field(qs, "checkout_token", value, "Checkout")-- @staticmethod- def filter_is_gift_card_used(qs, _, value):- if value is None:- return qs.none()- return filter_by_gift_card(qs, value, GiftCardEvents.USED_IN_ORDER)-- @staticmethod- def filter_is_gift_card_bought(qs, _, value):- if value is None:- return qs.none()- return filter_by_gift_card(qs, value, GiftCardEvents.BOUGHT)-- @staticmethod- def filter_has_invoices(qs, _, value):- return filter_has_invoices(qs, value)-- @staticmethod- def filter_invoices(qs, _, value):- if not value:- return qs.none()-- lookup = Q()- for input_data in value:- if filter_value := input_data.get("created_at"):- invoices = filter_where_by_range_field(- Invoice.objects.using(qs.db), "created_at", filter_value- )- lookup &= Q(Exists(invoices.filter(order_id=OuterRef("id"))))- if lookup:- return qs.filter(lookup)- return qs.none()-- @staticmethod- def filter_has_fulfillments(qs, _, value):- return filter_has_fulfillments(qs, value)-- @staticmethod- def filter_fulfillments(qs, _, value):- return filter_fulfillments(qs, value)-class OrderWhereInput(WhereInputObjectType):class Meta:diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex e6c8f8536f..015623c5c3 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3322,6 +3322,13 @@ type User implements Node & ObjectWithMetadata @doc(category: "Users") {List of user's orders. The query will not initiate any external requests, including filtering available shipping methods, or performing external tax calculations. Requires one of the following permissions: MANAGE_STAFF, OWNER."""orders(+ """+ Where filtering options for orders.++ Added in Saleor 3.22.+ """+ where: CustomerOrderWhereInput+"""Return the elements in the list that come before the specified cursor."""before: String@@ -13659,6 +13666,201 @@ type OrderCountableEdge @doc(category: "Orders") {cursor: String!}+input CustomerOrderWhereInput @doc(category: "Orders") {+ """Filter by metadata fields."""+ metadata: MetadataFilterInput+ ids: [ID!]++ """Filter by order number."""+ number: IntFilterInput++ """Filter by channel."""+ channelId: GlobalIDFilterInput++ """Filter order by created at date."""+ createdAt: DateTimeRangeInput++ """Filter order by updated at date."""+ updatedAt: DateTimeRangeInput++ """Filter by user email."""+ userEmail: StringFilterInput++ """Filter by authorize status."""+ authorizeStatus: OrderAuthorizeStatusEnumFilterInput++ """Filter by charge status."""+ chargeStatus: OrderChargeStatusEnumFilterInput++ """Filter by order status."""+ status: OrderStatusEnumFilterInput++ """Filter by checkout token."""+ checkoutToken: UUIDFilterInput++ """Filter by checkout id."""+ checkoutId: GlobalIDFilterInput++ """+ Filter by whether the order uses the click and collect delivery method.+ """+ isClickAndCollect: Boolean++ """Filter based on whether a gift card was used in the order."""+ isGiftCardUsed: Boolean++ """Filter based on whether the order includes a gift card purchase."""+ isGiftCardBought: Boolean++ """Filter by voucher code used in the order."""+ voucherCode: StringFilterInput++ """Filter by whether the order has any invoices."""+ hasInvoices: Boolean++ """+ Filter by invoice data associated with the order. Each list item represents conditions that must be satisfied by a single object. The filter matches orders that have related objects meeting all specified groups of conditions.+ """+ invoices: [InvoiceFilterInput!]++ """Filter by whether the order has any fulfillments."""+ hasFulfillments: Boolean++ """Filter by number of lines in the order."""+ linesCount: IntFilterInput++ """Filter by total gross amount of the order."""+ totalGross: PriceFilterInput++ """Filter by total net amount of the order."""+ totalNet: PriceFilterInput++ """Filter by the product type of related order lines."""+ productTypeId: GlobalIDFilterInput++ """Filter by billing address of the order."""+ billingAddress: AddressFilterInput++ """Filter by shipping address of the order."""+ shippingAddress: AddressFilterInput++ """List of conditions that must be met."""+ AND: [CustomerOrderWhereInput!]++ """A list of conditions of which at least one must be met."""+ OR: [CustomerOrderWhereInput!]+}++"""+Allows filtering based on metadata key/value pairs.++ Examples:+ - `{key: "size"}`+ Matches objects where the metadata key "size" exists, regardless of its value.+ - `{key: "color", value: {oneOf: ["blue", "green"]}}`+ Matches objects where the metadata key "color" is set to either "blue" or "green".+ - `{key: "status", value: {eq: "active"}}`+ Matches objects where the metadata key "status" is set to "active".+"""+input MetadataFilterInput {+ """+ Key to filter by. If not other fields provided - checking the existence of the key in metadata.+ """+ key: String!++ """Value to filter by."""+ value: MetadataValueFilterInput+}++"""Define the filtering options for metadata value fields."""+input MetadataValueFilterInput {+ """The value equal to."""+ eq: String++ """The value included in."""+ oneOf: [String!]+}++"""Define the filtering options for integer fields."""+input IntFilterInput {+ """The value equal to."""+ eq: Int++ """The value included in."""+ oneOf: [Int!]++ """The value in range."""+ range: IntRangeInput+}++"""Filter by authorize status."""+input OrderAuthorizeStatusEnumFilterInput @doc(category: "Orders") {+ """The value equal to."""+ eq: OrderAuthorizeStatusEnum++ """The value included in."""+ oneOf: [OrderAuthorizeStatusEnum!]+}++"""Filter by charge status."""+input OrderChargeStatusEnumFilterInput @doc(category: "Orders") {+ """The value equal to."""+ eq: OrderChargeStatusEnum++ """The value included in."""+ oneOf: [OrderChargeStatusEnum!]+}++"""Filter by order status."""+input OrderStatusEnumFilterInput @doc(category: "Orders") {+ """The value equal to."""+ eq: OrderStatus++ """The value included in."""+ oneOf: [OrderStatus!]+}++"""Define the filtering options for string fields."""+input UUIDFilterInput {+ """The value equal to."""+ eq: UUID++ """The value included in."""+ oneOf: [UUID!]+}++"""Filter input for invoices."""+input InvoiceFilterInput @doc(category: "Orders") {+ """Filter invoices by creation date."""+ createdAt: DateTimeRangeInput+}++input PriceFilterInput {+ """The currency of the price to filter by."""+ currency: String++ """The amount of the price to filter by."""+ amount: DecimalFilterInput!+}++"""Filtering options for addresses."""+input AddressFilterInput @doc(category: "Users") {+ phoneNumber: StringFilterInput+ country: CountryCodeEnumFilterInput+}++"""Filter by country code."""+input CountryCodeEnumFilterInput @doc(category: "Users") {+ """The value equal to."""+ eq: CountryCode++ """The value included in."""+ oneOf: [CountryCode!]++ """The value not included in."""+ notOneOf: [CountryCode!]+}+"""Represents user's permissions."""type UserPermission @doc(category: "Users") {"""Internal code for permission."""@@ -15437,36 +15639,6 @@ input PageWhereInput @doc(category: "Pages") {OR: [PageWhereInput!]}-"""-Allows filtering based on metadata key/value pairs.-- Examples:- - `{key: "size"}`- Matches objects where the metadata key "size" exists, regardless of its value.- - `{key: "color", value: {oneOf: ["blue", "green"]}}`- Matches objects where the metadata key "color" is set to either "blue" or "green".- - `{key: "status", value: {eq: "active"}}`- Matches objects where the metadata key "status" is set to "active".-"""-input MetadataFilterInput {- """- Key to filter by. If not other fields provided - checking the existence of the key in metadata.- """- key: String!-- """Value to filter by."""- value: MetadataValueFilterInput-}--"""Define the filtering options for metadata value fields."""-input MetadataValueFilterInput {- """The value equal to."""- eq: String-- """The value included in."""- oneOf: [String!]-}-type PageTypeCountableConnection @doc(category: "Pages") {"""Pagination data for this connection."""pageInfo: PageInfo!@@ -15704,60 +15876,6 @@ input OrderWhereInput @doc(category: "Orders") {OR: [OrderWhereInput!]}-"""Define the filtering options for integer fields."""-input IntFilterInput {- """The value equal to."""- eq: Int-- """The value included in."""- oneOf: [Int!]-- """The value in range."""- range: IntRangeInput-}--"""Filter by authorize status."""-input OrderAuthorizeStatusEnumFilterInput @doc(category: "Orders") {- """The value equal to."""- eq: OrderAuthorizeStatusEnum-- """The value included in."""- oneOf: [OrderAuthorizeStatusEnum!]-}--"""Filter by charge status."""-input OrderChargeStatusEnumFilterInput @doc(category: "Orders") {- """The value equal to."""- eq: OrderChargeStatusEnum-- """The value included in."""- oneOf: [OrderChargeStatusEnum!]-}--"""Filter by order status."""-input OrderStatusEnumFilterInput @doc(category: "Orders") {- """The value equal to."""- eq: OrderStatus-- """The value included in."""- oneOf: [OrderStatus!]-}--"""Define the filtering options for string fields."""-input UUIDFilterInput {- """The value equal to."""- eq: UUID-- """The value included in."""- oneOf: [UUID!]-}--"""Filter input for invoices."""-input InvoiceFilterInput @doc(category: "Orders") {- """Filter invoices by creation date."""- createdAt: DateTimeRangeInput-}-"""Filter input for order fulfillments data."""input FulfillmentFilterInput @doc(category: "Orders") {"""Filter by fulfillment status."""@@ -15848,14 +15966,6 @@ input PaymentMethodDetailsCardFilterInput {brand: StringFilterInput}-input PriceFilterInput {- """The currency of the price to filter by."""- currency: String-- """The amount of the price to filter by."""- amount: DecimalFilterInput!-}-"""Filter input for order events data."""input OrderEventFilterInput @doc(category: "Orders") {"""Filter order events by date."""@@ -15873,24 +15983,6 @@ input OrderEventTypeEnumFilterInput {oneOf: [OrderEventsEnum!]}-"""Filtering options for addresses."""-input AddressFilterInput @doc(category: "Users") {- phoneNumber: StringFilterInput- country: CountryCodeEnumFilterInput-}--"""Filter by country code."""-input CountryCodeEnumFilterInput @doc(category: "Users") {- """The value equal to."""- eq: CountryCode-- """The value included in."""- oneOf: [CountryCode!]-- """The value not included in."""- notOneOf: [CountryCode!]-}-input OrderDraftFilterInput @doc(category: "Orders") {customer: Stringcreated: DateRangeInput