Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move clean to the separate method
Pacu29b7306934173
diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex 2e04f5b6f4..a8c0baf277 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -15,6 +15,31 @@ from ....shipping.models import ShippingMethod as ShippingMethodModelfrom ....core.utils.taxes import ZERO_TAXED_MONEY+def clean_order_update_shipping(order, method, errors):+ if not method:+ return errors+ if not order.shipping_address:+ errors.append(+ Error(+ field='order',+ message=(+ 'Cannot choose a shipping method for an '+ 'order without the shipping address.')))+ return errors+ valid_methods = (+ ShippingMethodModel.objects.applicable_shipping_methods(+ price=order.get_subtotal().gross.amount,+ weight=order.get_total_weight(),+ country_code=order.shipping_address.country.code))+ valid_methods = valid_methods.values_list('id', flat=True)+ if method.pk not in valid_methods:+ errors.append(+ Error(+ field='shippingMethod',+ message='Shipping method cannot be used with this order.'))+ return errors++def try_payment_action(action, money, errors):try:action(money)@@ -137,28 +162,10 @@ class OrderUpdateShipping(BaseMutation):method = cls.get_node_or_error(info, input['shipping_method'], errors,'shipping_method', ShippingMethod)+ clean_order_update_shipping(order, method, errors)if errors:return OrderUpdateShipping(errors=errors)- if not order.shipping_address:- cls.add_error(- errors, 'order',- 'Cannot choose a shipping method for an '- 'order without the shipping address.')- return OrderUpdateShipping(errors=errors)-- valid_methods = (- ShippingMethodModel.objects.applicable_shipping_methods(- price=order.get_subtotal().gross.amount,- weight=order.get_total_weight(),- country_code=order.shipping_address.country.code))- valid_methods = valid_methods.values_list('id', flat=True)- if method.pk not in valid_methods:- cls.add_error(- errors, 'shippingMethod',- 'Shipping method cannot be used with this order.')- return OrderUpdateShipping(errors=errors)-order.shipping_method = methodorder.shipping_price = method.get_total_price(info.context.taxes)order.shipping_method_name = method.name