Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix shipping method bug on empty shipping address
Michał Ociepka3ada69f38910
diff --git a/saleor/checkout/core.py b/saleor/checkout/core.pyindex 3bc079bbfa..65aaf8f680 100644--- a/saleor/checkout/core.py+++ b/saleor/checkout/core.py@@ -86,18 +86,20 @@ class Checkout(object):@propertydef shipping_method(self):- shipping_method_country_id = self.storage.get('shipping_method_country_id')- if shipping_method_country_id is not None:- try:- shipping_method_country = ShippingMethodCountry.objects.get(- id=shipping_method_country_id)- except ShippingMethodCountry.DoesNotExist:- return None- shipping_country_code = self.shipping_address.country.code- any_country = ShippingMethodCountry.ANY_COUNTRY- if (shipping_method_country.country_code == any_country- or shipping_method_country.country_code == shipping_country_code):- return shipping_method_country+ shipping_address = self.shipping_address+ if shipping_address is not None:+ shipping_method_country_id = self.storage.get('shipping_method_country_id')+ if shipping_method_country_id is not None:+ try:+ shipping_method_country = ShippingMethodCountry.objects.get(+ id=shipping_method_country_id)+ except ShippingMethodCountry.DoesNotExist:+ return None+ shipping_country_code = shipping_address.country.code+ any_country = ShippingMethodCountry.ANY_COUNTRY+ if (shipping_method_country.country_code == any_country+ or shipping_method_country.country_code == shipping_country_code):+ return shipping_method_country@shipping_method.setterdef shipping_method(self, shipping_method_country):diff --git a/saleor/checkout/test_checkout.py b/saleor/checkout/test_checkout.pyindex 62ceae0be7..a7b3f65f95 100644--- a/saleor/checkout/test_checkout.py+++ b/saleor/checkout/test_checkout.py@@ -70,7 +70,6 @@ def test_checkout_deliveries_with_shipping_method(monkeypatch):(partition, shipping_method_mock.get_total(), total)]-@pytest.mark.parametrize('user, shipping', [(Mock(default_shipping_address='user_shipping'), 'user_shipping'),(AnonymousUser(), None),@@ -101,12 +100,12 @@ def test_checkout_shipping_address_setter():'postal_code': u'', 'street_address_1': u'','street_address_2': u''}-@pytest.mark.parametrize('shipping_address, shipping_method, value', [(Mock(country=Mock(code='PL')),Mock(country_code='PL', __eq__=lambda n, o: n.country_code == o.country_code),Mock(country_code='PL')),(Mock(country=Mock(code='DE')), Mock(country_code='PL'), None),+ (None, Mock(country_code='PL'), None),])def test_checkout_shipping_method(shipping_address, shipping_method, value, monkeypatch):queryset = Mock(get=Mock(return_value=shipping_method))