Skip to content

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

Unify code styling

Marcin Gębala2ff7d5e4b045
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 687612cf69..36957e15b3 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -42,8 +42,7 @@ class CheckoutLineInput(graphene.InputObjectType):
class CheckoutCreateInput(graphene.InputObjectType):
- lines = graphene.List(
- CheckoutLineInput, description='Checkout lines')
+ lines = graphene.List(CheckoutLineInput, description='Checkout lines')
email = graphene.String(description='Customer email')
shipping_address = AddressInput(description='Shipping address')
@@ -96,21 +95,21 @@ class CheckoutCreate(ModelMutation):
add_variant_to_cart(instance, variant, quantity)
-
class CheckoutLinesAdd(BaseMutation):
+ checkout = graphene.Field(Checkout, description='An updated checkout')
+
class Arguments:
checkout_id = graphene.ID(description='Checkout ID', required=True)
lines = graphene.List(
CheckoutLineInput, description='Checkout lines', required=True)
- checkout = graphene.Field(Checkout, description='An updated checkout')
-
class Meta:
description = 'Adds a checkout line to existing checkout'
@classmethod
def mutate(cls, root, info, checkout_id, lines, replace=False):
- checkout = graphene.Node.get_node_from_global_id(info, checkout_id, Checkout)
+ checkout = graphene.Node.get_node_from_global_id(
+ info, checkout_id, Checkout)
variants, quantities = None, None
errors = []
if lines:
@@ -126,7 +125,8 @@ class CheckoutLinesAdd(BaseMutation):
if variants and quantities:
for variant, quantity in zip(variants, quantities):
- add_variant_to_cart(checkout, variant, quantity, replace=replace)
+ add_variant_to_cart(
+ checkout, variant, quantity, replace=replace)
return CheckoutLinesAdd(checkout=checkout, errors=errors)
@@ -142,12 +142,12 @@ class CheckoutLinesUpdate(CheckoutLinesAdd):
class CheckoutLineDelete(BaseMutation):
+ checkout = graphene.Field(Checkout, description='An updated checkout')
+
class Arguments:
checkout_id = graphene.ID(description='Checkout ID', required=True)
line_id = graphene.ID(description='Checkout line ID')
- checkout = graphene.Field(Checkout, description='An updated checkout')
-
class Meta:
description = 'Deletes a checkout line'
@@ -163,14 +163,13 @@ class CheckoutLineDelete(BaseMutation):
return CheckoutLinesAdd(checkout=checkout, errors=errors)
-
class CheckoutCustomerAttach(BaseMutation):
+ checkout = graphene.Field(Checkout, description='An updated checkout')
+
class Arguments:
checkout_id = graphene.ID(description='Checkout ID', required=True)
customer_id = graphene.ID(description='Customer ID', required=True)
- checkout = graphene.Field(Checkout, description='An updated checkout')
-
@classmethod
def mutate(cls, root, info, checkout_id, customer_id):
errors = []
@@ -183,13 +182,13 @@ class CheckoutCustomerAttach(BaseMutation):
checkout.save(update_fields=['user'])
return CheckoutCustomerAttach(checkout=checkout, errors=errors)
+
class CheckoutCustomerDetach(BaseMutation):
+ checkout = graphene.Field(Checkout, description='An updated checkout')
+
class Arguments:
checkout_id = graphene.ID(description='Checkout ID', required=True)
-
- checkout = graphene.Field(Checkout, description='An updated checkout')
-
@classmethod
def mutate(cls, root, info, checkout_id):
checkout = graphene.Node.get_node_from_global_id(
@@ -199,13 +198,14 @@ class CheckoutCustomerDetach(BaseMutation):
checkout.save(update_fields=['user'])
return CheckoutCustomerDetach(checkout=checkout)
+
class CheckoutShippingAddressUpdate(BaseMutation):
+ checkout = graphene.Field(Checkout, description='An updated checkout')
+
class Arguments:
checkout_id = graphene.ID(description='Checkout ID')
shipping_address = AddressInput(description='Shipping address')
- checkout = graphene.Field(Checkout, description='An updated checkout')
-
class Meta:
description = 'Update shipping address in existing Checkout object'
@@ -221,13 +221,14 @@ class CheckoutShippingAddressUpdate(BaseMutation):
change_shipping_address_in_cart(checkout, shipping_address)
return CheckoutShippingAddressUpdate(checkout=checkout, errors=errors)
+
class CheckoutEmailUpdate(BaseMutation):
+ checkout = graphene.Field(Checkout, description='An updated checkout')
+
class Arguments:
checkout_id = graphene.ID(description='Checkout ID')
email = graphene.String(required=True, description='email')
- checkout = graphene.Field(Checkout, description='An updated checkout')
-
class Meta:
description = 'Update email address in existing Checkout object'
@@ -242,12 +243,14 @@ class CheckoutEmailUpdate(BaseMutation):
return CheckoutEmailUpdate(checkout=checkout, errors=errors)
+
class CheckoutShippingMethodUpdate(BaseMutation):
+ checkout = graphene.Field(Checkout, description='An updated checkout')
+
class Arguments:
checkout_id = graphene.ID(description='Checkout ID')
- shipping_method_id = graphene.ID(required=True, description='Shipping method')
-
- checkout = graphene.Field(Checkout, description='An updated checkout')
+ shipping_method_id = graphene.ID(
+ required=True, description='Shipping method')
@classmethod
def mutate(cls, root, info, checkout_id, shipping_method_id):
@@ -262,12 +265,13 @@ class CheckoutShippingMethodUpdate(BaseMutation):
checkout.save(update_fields=['shipping_method'])
return CheckoutShippingMethodUpdate(checkout=checkout, errors=errors)
+
class CheckoutComplete(BaseMutation):
+ order = graphene.Field(Order, description='Placed order')
+
class Arguments:
checkout_id = graphene.ID(description='Checkout ID')
- order = graphene.Field(Order, description='Placed order')
-
@classmethod
def mutate(cls, root, info, checkout_id):
errors = []
@@ -278,8 +282,7 @@ class CheckoutComplete(BaseMutation):
return CheckoutComplete(errors=errors)
ready, checkout_error = ready_to_place_order(checkout)
if not ready:
- cls.add_error(
- field=None, message=checkout_error, errors=errors)
+ cls.add_error(field=None, message=checkout_error, errors=errors)
return CheckoutComplete(errors=errors)
try:
@@ -293,6 +296,6 @@ class CheckoutComplete(BaseMutation):
except InsufficientStock:
order = None
cls.add_error(
- field=None, message='Insufficient product stock', errors=errors)
-
+ field=None, message='Insufficient product stock',
+ errors=errors)
return CheckoutComplete(order=order, errors=errors)
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.py
index 12c045ef9f..939a6a1ce0 100644
--- a/saleor/graphql/checkout/types.py
+++ b/saleor/graphql/checkout/types.py
@@ -17,7 +17,6 @@ class CheckoutLine(CountableDjangoObjectType):
model = models.CartLine
filter_fields = ['id']
-
def resolve_total_price(self, info):
taxes = get_taxes_for_address(self.cart.shipping_address)
return self.get_total(taxes=taxes)
diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.py
index 2c2073c23c..e0e44e35f2 100644
--- a/saleor/graphql/payment/mutations.py
+++ b/saleor/graphql/payment/mutations.py
@@ -29,13 +29,13 @@ class PaymentMethodInput(graphene.InputObjectType):
class CheckoutPaymentMethodCreate(BaseMutation):
+ payment_method = graphene.Field(
+ PaymentMethod, description='Updated payment method')
+
class Arguments:
input = PaymentMethodInput(
required=True, description='Payment method details')
- payment_method = graphene.Field(
- PaymentMethod, description='Updated payment method')
-
class Meta:
description = 'Creates credit card transaction.'
@@ -56,12 +56,10 @@ class CheckoutPaymentMethodCreate(BaseMutation):
# create payment method
payment_method = create_payment_method(
- variant=input['gateway'],
- billing_email=checkout.email,
- extra_data=extra_data,
- total=input['amount'],
- checkout=checkout,
+ variant=input['gateway'], billing_email=checkout.email,
+ extra_data=extra_data, total=input['amount'], checkout=checkout,
**billing_data)
+
# authorize payment
try:
gateway_authorize(payment_method, input['transaction_token'])
@@ -96,17 +94,14 @@ class CheckoutPaymentMethodCreate(BaseMutation):
'customer_user_agent': user_agent}
-
class PaymentMethodCharge(BaseMutation):
+ payment_method = graphene.Field(
+ PaymentMethod, description='Updated payment method')
class Arguments:
payment_method_id = graphene.ID(
required=True, description='Payment method ID')
- amount = graphene.Argument(
- Decimal, description='Transaction amount')
-
- payment_method = graphene.Field(
- PaymentMethod, description='Updated payment method')
+ amount = graphene.Argument(Decimal, description='Transaction amount')
@classmethod
@permission_required('order.manage_orders')
@@ -124,12 +119,11 @@ class PaymentMethodCharge(BaseMutation):
except PaymentError as exc:
msg = str(exc)
cls.add_error(field=None, message=msg, errors=errors)
-
- return PaymentMethodCharge(payment_method=payment_method, errors=errors)
+ return PaymentMethodCharge(
+ payment_method=payment_method, errors=errors)
class PaymentMethodRefund(PaymentMethodCharge):
-
@classmethod
@permission_required('order.manage_orders')
def mutate(cls, root, info, payment_method_id, amount=None):
@@ -146,18 +140,18 @@ class PaymentMethodRefund(PaymentMethodCharge):
except PaymentError as exc:
msg = str(exc)
cls.add_error(field=None, message=msg, errors=errors)
-
- return PaymentMethodRefund(payment_method=payment_method, errors=errors)
+ return PaymentMethodRefund(
+ payment_method=payment_method, errors=errors)
class PaymentMethodVoid(BaseMutation):
+ payment_method = graphene.Field(
+ PaymentMethod, description='Updated payment method')
+
class Arguments:
payment_method_id = graphene.ID(
required=True, description='Payment method ID')
- payment_method = graphene.Field(
- PaymentMethod, description='Updated payment method')
-
@classmethod
@permission_required('order.manage_orders')
def mutate(cls, root, info, payment_method_id, amount=None):
@@ -174,5 +168,4 @@ class PaymentMethodVoid(BaseMutation):
except PaymentError as exc:
msg = str(exc)
cls.add_error(field=None, message=msg, errors=errors)
-
return PaymentMethodVoid(payment_method=payment_method, errors=errors)
diff --git a/saleor/graphql/payment/resolvers.py b/saleor/graphql/payment/resolvers.py
index 6e62b600b2..3efc3ae2a8 100644
--- a/saleor/graphql/payment/resolvers.py
+++ b/saleor/graphql/payment/resolvers.py
@@ -6,11 +6,13 @@ from ..utils import filter_by_query_param
PAYMENT_SEARCH_FIELDS = ['id']
+
# @login_required
def resolve_payment_methods(info, query):
queryset = models.PaymentMethod.objects.all().distinct()
queryset = filter_by_query_param(queryset, query, PAYMENT_SEARCH_FIELDS)
return queryset
+
def resolve_payment_client_token(gateway=None):
return gateway_get_client_token(gateway)
diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.py
index c5c83ae606..a33c47b72a 100644
--- a/saleor/graphql/payment/types.py
+++ b/saleor/graphql/payment/types.py
@@ -6,6 +6,7 @@ from ..core.types.common import CountableDjangoObjectType
PaymentGatewayEnum = graphene.Enum.from_enum(PROVIDERS_ENUM)
+
class PaymentMethod(CountableDjangoObjectType):
class Meta:
description = 'Payment method'
@@ -13,6 +14,7 @@ class PaymentMethod(CountableDjangoObjectType):
model = models.PaymentMethod
filter_fields = ['id']
+
class Transaction(CountableDjangoObjectType):
class Meta:
description = 'Single payment transaction'
diff --git a/saleor/payment/forms.py b/saleor/payment/forms.py
index 5743117ac8..ad6f651529 100644
--- a/saleor/payment/forms.py
+++ b/saleor/payment/forms.py
@@ -2,6 +2,7 @@ from django import forms
from .models import PaymentMethod
from ..payment import TransactionType
+
class PaymentMethodForm(forms.ModelForm):
class Meta:
model = PaymentMethod
@@ -9,7 +10,5 @@ class PaymentMethodForm(forms.ModelForm):
def authorize_payment(self):
self.instance.transactions.create(
- amount=self.instance.total,
- transaction_type=TransactionType.AUTH,
- gateway_response={},
- is_success=True)
+ amount=self.instance.total, transaction_type=TransactionType.AUTH,
+ gateway_response={}, is_success=True)