Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extract applicable shipping methods to utils
fowczareka2b2d746fc70
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex fbfa9bd60b..9c0682d339 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -5,7 +5,7 @@ from ...checkout import modelsfrom ...core.utils.taxes import get_taxes_for_addressfrom ..core.connection import CountableDjangoObjectTypefrom ..core.types.money import TaxedMoney-from ..order.resolvers import resolve_shipping_methods+from ..order.utils import applicable_shipping_methodsfrom ..shipping.types import ShippingMethod@@ -84,7 +84,7 @@ class Checkout(CountableDjangoObjectType):taxes = get_taxes_for_address(self.shipping_address)price = self.get_subtotal(taxes=taxes, discounts=info.context.discounts)- return resolve_shipping_methods(self, info, price.gross.amount)+ return applicable_shipping_methods(self, info, price.gross.amount)def resolve_is_shipping_required(self, info):return self.is_shipping_required()diff --git a/saleor/graphql/order/resolvers.py b/saleor/graphql/order/resolvers.pyindex 151eccb8e8..b37019469b 100644--- a/saleor/graphql/order/resolvers.py+++ b/saleor/graphql/order/resolvers.py@@ -3,10 +3,10 @@ import graphene_django_optimizer as gql_optimizerfrom ...order import OrderEvents, OrderStatus, modelsfrom ...order.utils import sum_order_totals-from ...shipping import models as shipping_modelsfrom ..utils import filter_by_period, filter_by_query_paramfrom .enums import OrderStatusFilterfrom .types import Order+from .utils import applicable_shipping_methodsORDER_SEARCH_FIELDS = ('id', 'discount_name', 'token', 'user_email', 'user__email')@@ -50,15 +50,7 @@ def resolve_order(info, id):def resolve_shipping_methods(obj, info, price):- if not obj.is_shipping_required():- return None- if not obj.shipping_address:- return None-- qs = shipping_models.ShippingMethod.objects- return qs.applicable_shipping_methods(- price=price, weight=obj.get_total_weight(),- country_code=obj.shipping_address.country.code)+ return applicable_shipping_methods(obj, info, price)def resolve_homepage_events(info):diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex ab6d1bd10e..3a8b2b59dd 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -10,7 +10,7 @@ from ..core.types.money import Money, TaxedMoneyfrom ..payment.types import OrderAction, Payment, PaymentChargeStatusEnumfrom ..shipping.types import ShippingMethodfrom .enums import OrderEventsEmailsEnum, OrderEventsEnum-from .utils import can_finalize_draft_order+from .utils import applicable_shipping_methods, can_finalize_draft_orderclass OrderEvent(CountableDjangoObjectType):@@ -299,8 +299,7 @@ class Order(CountableDjangoObjectType):@staticmethoddef resolve_available_shipping_methods(self, info):- from .resolvers import resolve_shipping_methods- return resolve_shipping_methods(+ return applicable_shipping_methods(self, info, self.get_subtotal().gross.amount)def resolve_is_shipping_required(self, info):diff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.pyindex 223f786d98..1c0e27049b 100644--- a/saleor/graphql/order/utils.py+++ b/saleor/graphql/order/utils.py@@ -1,3 +1,4 @@+from ...shipping import models as shipping_modelsfrom ..core.types.common import Error@@ -25,3 +26,15 @@ def can_finalize_draft_order(order, errors):message='Shipping method is not valid for chosen shipping ''address'))return errors+++def applicable_shipping_methods(obj, info, price):+ if not obj.is_shipping_required():+ return None+ if not obj.shipping_address:+ return None++ qs = shipping_models.ShippingMethod.objects+ return qs.applicable_shipping_methods(+ price=price, weight=obj.get_total_weight(),+ country_code=obj.shipping_address.country.code)