Skip to content

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

Change Order payments to a list in API

fowczarek0085bcd1ad05
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.py
index 3faf8527f7..9d02961e5d 100644
--- a/saleor/graphql/account/types.py
+++ b/saleor/graphql/account/types.py
@@ -1,4 +1,5 @@
import graphene
+import graphene_django_optimizer as gql_optimizer
from django.contrib.auth import get_user_model
from graphene import relay
@@ -41,8 +42,10 @@ class Address(CountableDjangoObjectType):
class User(CountableDjangoObjectType):
permissions = graphene.List(
PermissionDisplay, description='List of user\'s permissions.')
- addresses = graphene.List(
- Address, description='List of all user\'s addresses.')
+ addresses = gql_optimizer.field(
+ graphene.List(
+ Address, description='List of all user\'s addresses.'),
+ model_field='addresses')
class Meta:
exclude_fields = ['password', 'is_superuser', 'OrderEvent_set']
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index e707fa6bc0..14c3356710 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -7,7 +7,7 @@ from ...product.templatetags.product_images import get_thumbnail
from ..account.types import User
from ..core.types.common import CountableDjangoObjectType
from ..core.types.money import Money, TaxedMoney
-from ..payment.types import OrderAction, PaymentChargeStatusEnum
+from ..payment.types import OrderAction, Payment, PaymentChargeStatusEnum
from ..shipping.types import ShippingMethod
OrderEventsEnum = graphene.Enum.from_enum(OrderEvents)
@@ -88,9 +88,11 @@ class FulfillmentLine(CountableDjangoObjectType):
class Fulfillment(CountableDjangoObjectType):
- lines = graphene.List(
- FulfillmentLine,
- description='List of fulfillment lines for the fulfillment')
+ lines = gql_optimizer.field(
+ graphene.List(
+ FulfillmentLine,
+ description='List of fulfillment lines for the fulfillment'),
+ model_field='lines')
status_display = graphene.String(
description='User-friendly fulfillment status.')
@@ -161,6 +163,10 @@ class Order(CountableDjangoObjectType):
description='Internal payment status.')
payment_status_display = graphene.String(
description='User-friendly payment status.')
+ payments = gql_optimizer.field(
+ graphene.List(
+ Payment, description='List of payments for the order'),
+ model_field='payments')
total = graphene.Field(
TaxedMoney, description='Total amount of the order.')
shipping_price = graphene.Field(
@@ -270,6 +276,10 @@ class Order(CountableDjangoObjectType):
def resolve_payment_status_display(self, info):
return self.get_last_payment_status_display()
+ @staticmethod
+ def resolve_payments(self, info):
+ return self.payments.all()
+
@staticmethod
def resolve_status_display(self, info):
return self.get_status_display()
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
index ac01060cd4..e8ffc899c5 100644
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -79,6 +79,9 @@ def test_order_query(
fulfillments {
fulfillmentOrder
}
+ payments{
+ id
+ }
subtotal {
net {
amount
@@ -123,6 +126,7 @@ def test_order_query(
fulfillment = order.fulfillments.first().fulfillment_order
fulfillment_order = order_data['fulfillments'][0]['fulfillmentOrder']
assert fulfillment_order == fulfillment
+ assert len(order_data['payments']) == order.payments.count()
expected_methods = ShippingMethod.objects.applicable_shipping_methods(
price=order.get_subtotal().gross.amount,