Skip to content

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

Fix bug with overwritting address

Marek Brzóska29f36e6f925f
diff --git a/checkout/steps.py b/checkout/steps.py
index d8cec8a227..811e8a3242 100644
--- a/checkout/steps.py
+++ b/checkout/steps.py
@@ -1,3 +1,4 @@
+from django.forms.models import model_to_dict
from .forms import ManagementForm, DigitalDeliveryForm, DeliveryForm
from checkout.forms import AnonymousEmailForm
from django.core.exceptions import ValidationError
@@ -130,8 +131,9 @@ class ShippingStep(BaseShippingStep):
if 'address' in self.group:
address = self.group['address']
else:
- address = checkout.billing_address or Address()
- address.id = None
+ address = (Address(model_to_dict(checkout.billing_address))
+ if checkout.billing_address
+ else Address())
super(ShippingStep, self).__init__(checkout, request, address)
self.forms['delivery'] = DeliveryForm(
delivery_group.get_delivery_methods(), request.POST or None)
diff --git a/checkout/tests.py b/checkout/tests.py
index 7b6a86a313..0409b3a69d 100644
--- a/checkout/tests.py
+++ b/checkout/tests.py
@@ -129,7 +129,10 @@ class TestShippingStep(TestCase):
def test_address_save_with_address_in_checkout(self, mock_save):
self.request.POST = NEW_ADDRESS_POST
self.request.POST['method'] = 0
- self.checkout.billing_address = Address()
+ original_billing_address_data = {'first_name': 'Change',
+ 'last_name': 'Me'}
+ original_billing_address = Address(original_billing_address_data)
+ self.checkout.billing_address = original_billing_address
group = MagicMock()
group.address = None
group.get_delivery_methods.return_value = [DummyShipping(group)]
@@ -137,3 +140,5 @@ class TestShippingStep(TestCase):
self.assertTrue(step.forms_are_valid(), 'Forms don\'t validate.')
step.save()
self.assertEqual(mock_save.call_count, 0)
+ self.assertEqual(self.checkout.billing_address,
+ Address(original_billing_address_data))