Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change Order payments to a list in API
fowczarek0085bcd1ad05
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.pyindex 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_optimizerfrom django.contrib.auth import get_user_modelfrom 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.pyindex 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_thumbnailfrom ..account.types import Userfrom ..core.types.common import CountableDjangoObjectTypefrom ..core.types.money import Money, TaxedMoney-from ..payment.types import OrderAction, PaymentChargeStatusEnum+from ..payment.types import OrderAction, Payment, PaymentChargeStatusEnumfrom ..shipping.types import ShippingMethodOrderEventsEnum = 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()+@staticmethoddef resolve_status_display(self, info):return self.get_status_display()diff --git a/tests/api/test_order.py b/tests/api/test_order.pyindex 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_orderfulfillment_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,