Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extract enums for orders and payments
Marcin Gębala2580dda019b6
diff --git a/saleor/graphql/order/enums.py b/saleor/graphql/order/enums.pynew file mode 100644index 0000000000..e6b252cfc8--- /dev/null+++ b/saleor/graphql/order/enums.py@@ -0,0 +1,12 @@+import graphene++from ...order import OrderEvents, OrderEventsEmails+++OrderEventsEnum = graphene.Enum.from_enum(OrderEvents)+OrderEventsEmailsEnum = graphene.Enum.from_enum(OrderEventsEmails)+++class OrderStatusFilter(graphene.Enum):+ READY_TO_FULFILL = 'READY_TO_FULFILL'+ READY_TO_CAPTURE = 'READY_TO_CAPTURE'diff --git a/saleor/graphql/order/resolvers.py b/saleor/graphql/order/resolvers.pyindex 41b03637fd..151eccb8e8 100644--- a/saleor/graphql/order/resolvers.py+++ b/saleor/graphql/order/resolvers.py@@ -5,7 +5,8 @@ from ...order import OrderEvents, OrderStatus, modelsfrom ...order.utils import sum_order_totalsfrom ...shipping import models as shipping_modelsfrom ..utils import filter_by_period, filter_by_query_param-from .types import Order, OrderStatusFilter+from .enums import OrderStatusFilter+from .types import OrderORDER_SEARCH_FIELDS = ('id', 'discount_name', 'token', 'user_email', 'user__email')diff --git a/saleor/graphql/order/schema.py b/saleor/graphql/order/schema.pyindex 060885d4d5..4fe17c8eef 100644--- a/saleor/graphql/order/schema.py+++ b/saleor/graphql/order/schema.py@@ -7,6 +7,7 @@ from ..core.fields import PrefetchingConnectionFieldfrom ..core.enums import ReportingPeriodfrom ..core.types import TaxedMoneyfrom ..descriptions import DESCRIPTIONS+from .enums import OrderStatusFilterfrom .mutations.draft_orders import (DraftOrderComplete, DraftOrderCreate, DraftOrderDelete,DraftOrderLineCreate, DraftOrderLineDelete, DraftOrderLineUpdate,@@ -19,7 +20,7 @@ from .mutations.orders import (from .resolvers import (resolve_homepage_events, resolve_order, resolve_orders,resolve_orders_total)-from .types import Order, OrderEvent, OrderStatusFilter+from .types import Order, OrderEventclass OrderQueries(graphene.ObjectType):diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex ef5e55bd00..6c5f946f23 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -2,23 +2,16 @@ import grapheneimport graphene_django_optimizer as gql_optimizerfrom graphene import relay-from ...order import OrderEvents, OrderEventsEmails, models+from ...order import modelsfrom ...product.templatetags.product_images import get_product_image_thumbnailfrom ..account.types import Userfrom ..core.connection import CountableDjangoObjectTypefrom ..core.types.money import Money, TaxedMoneyfrom ..payment.types import OrderAction, Payment, PaymentChargeStatusEnumfrom ..shipping.types import ShippingMethod+from .enums import OrderEventsEnum, OrderEventsEmailsEnumfrom .utils import can_finalize_draft_order-OrderEventsEnum = graphene.Enum.from_enum(OrderEvents)-OrderEventsEmailsEnum = graphene.Enum.from_enum(OrderEventsEmails)---class OrderStatusFilter(graphene.Enum):- READY_TO_FULFILL = 'READY_TO_FULFILL'- READY_TO_CAPTURE = 'READY_TO_CAPTURE'-class OrderEvent(CountableDjangoObjectType):date = graphene.types.datetime.DateTime(diff --git a/saleor/graphql/payment/enums.py b/saleor/graphql/payment/enums.pynew file mode 100644index 0000000000..8f9669f120--- /dev/null+++ b/saleor/graphql/payment/enums.py@@ -0,0 +1,28 @@+import graphene++from ...payment import GATEWAYS_ENUM, ChargeStatus+from ..core.utils import str_to_enum+++PaymentChargeStatusEnum = graphene.Enum(+ 'PaymentChargeStatusEnum',+ [(str_to_enum(code.upper()), code) for code, name in ChargeStatus.CHOICES])+PaymentGatewayEnum = graphene.Enum.from_enum(GATEWAYS_ENUM)+++class OrderAction(graphene.Enum):+ CAPTURE = 'CAPTURE'+ MARK_AS_PAID = 'MARK_AS_PAID'+ REFUND = 'REFUND'+ VOID = 'VOID'++ @property+ def description(self):+ if self == OrderAction.CAPTURE:+ return 'Represents the capture action.'+ if self == OrderAction.MARK_AS_PAID:+ return 'Represents a mark-as-paid action.'+ if self == OrderAction.REFUND:+ return 'Represents a refund action.'+ if self == OrderAction.VOID:+ return 'Represents a void action.'diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 8fa42f9dd1..b7ee858c8f 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -14,7 +14,8 @@ from ..account.types import AddressInputfrom ..checkout.types import Checkoutfrom ..core.mutations import BaseMutationfrom ..core.scalars import Decimal-from .types import Payment, PaymentGatewayEnum+from .enums import PaymentGatewayEnum+from .types import Paymentclass PaymentInput(graphene.InputObjectType):diff --git a/saleor/graphql/payment/schema.py b/saleor/graphql/payment/schema.pyindex a199dff92e..739eded58f 100644--- a/saleor/graphql/payment/schema.py+++ b/saleor/graphql/payment/schema.py@@ -2,11 +2,12 @@ import graphenefrom graphql_jwt.decorators import permission_requiredfrom ..core.fields import PrefetchingConnectionField+from .enums import PaymentGatewayEnumfrom .mutations import (PaymentAuthorize, PaymentCapture, PaymentCharge, PaymentRefund,PaymentVoid)from .resolvers import resolve_payment_client_token, resolve_payments-from .types import Payment, PaymentGatewayEnum+from .types import Paymentclass PaymentQueries(graphene.ObjectType):diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.pyindex 66f02b8c76..1de4e865c0 100644--- a/saleor/graphql/payment/types.py+++ b/saleor/graphql/payment/types.py@@ -3,35 +3,11 @@ import graphene_django_optimizer as gql_optimizerfrom django_countries.fields import Countryfrom graphene import relay-from ...payment import GATEWAYS_ENUM, ChargeStatus, models+from ...payment import modelsfrom ..account.types import Addressfrom ..core.connection import CountableDjangoObjectTypefrom ..core.types import Money-from ..core.utils import str_to_enum--PaymentGatewayEnum = graphene.Enum.from_enum(GATEWAYS_ENUM)-PaymentChargeStatusEnum = graphene.Enum(- 'PaymentChargeStatusEnum',- [(str_to_enum(code.upper()), code) for code, name in ChargeStatus.CHOICES])---class OrderAction(graphene.Enum):- # FIXME could use a better name- CAPTURE = 'CAPTURE'- MARK_AS_PAID = 'MARK_AS_PAID'- REFUND = 'REFUND'- VOID = 'VOID'-- @property- def description(self):- if self == OrderAction.CAPTURE:- return 'Represents the capture action.'- if self == OrderAction.MARK_AS_PAID:- return 'Represents a mark-as-paid action.'- if self == OrderAction.REFUND:- return 'Represents a refund action.'- if self == OrderAction.VOID:- return 'Represents a void action.'+from .enums import OrderAction, PaymentChargeStatusEnumclass Transaction(CountableDjangoObjectType):@@ -45,7 +21,6 @@ class Transaction(CountableDjangoObjectType):filter_fields = ['id']exclude_fields = ['currency']- @staticmethoddef resolve_amount(self, info):return self.get_amount()@@ -68,9 +43,6 @@ class CreditCard(graphene.ObjectType):class Payment(CountableDjangoObjectType):- # FIXME gateway_response field should be resolved- # if we want to use it on the frontend- # otherwise it should be removed from this typecharge_status = PaymentChargeStatusEnum(description='Internal payment status.', required=True)actions = graphene.List(diff --git a/saleor/graphql/shop/enums.py b/saleor/graphql/shop/enums.pynew file mode 100644index 0000000000..550ae4cba1--- /dev/null+++ b/saleor/graphql/shop/enums.py@@ -0,0 +1,9 @@+import graphene++from ..core.utils import str_to_enum+from ...site import AuthenticationBackends+++AuthorizationKeyType = graphene.Enum(+ 'AuthorizationKeyType', [(str_to_enum(auth_type[0]), auth_type[0])+ for auth_type in AuthenticationBackends.BACKENDS])diff --git a/saleor/graphql/shop/resolvers.py b/saleor/graphql/shop/resolvers.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.pyindex 8d1fc46cab..41d4c5a356 100644--- a/saleor/graphql/shop/types.py+++ b/saleor/graphql/shop/types.py@@ -12,14 +12,14 @@ from ...core.permissions import get_permissionsfrom ...core.utils import get_client_ip, get_country_by_ipfrom ...menu import models as menu_modelsfrom ...product import models as product_models-from ...site import AuthenticationBackends, models as site_models+from ...site import models as site_modelsfrom ..core.enums import WeightUnitsEnumfrom ..core.types.common import (CountryDisplay, LanguageDisplay, PermissionDisplay)-from ..core.utils import str_to_enumfrom ..menu.types import Menufrom ..product.types import Collectionfrom ..utils import format_permissions_for_display+from .enums import AuthorizationKeyTypeclass Navigation(graphene.ObjectType):@@ -30,11 +30,6 @@ class Navigation(graphene.ObjectType):description = 'Represents shop\'s navigation menus.'-AuthorizationKeyType = graphene.Enum(- 'AuthorizationKeyType', [(str_to_enum(auth_type[0]), auth_type[0])- for auth_type in AuthenticationBackends.BACKENDS])--class AuthorizationKey(graphene.ObjectType):name = AuthorizationKeyType(description='Name of the authorization backend.', required=True)