Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Copy addresses in checkoutCreate and draftOrderCreate mutations
Paweł Zarębski765c43b6a253
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex e2b82798fb..fc0162fec5 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -168,10 +168,10 @@ class CheckoutCreate(ModelMutation, I18nMixin):billing_address = cleaned_input.get('billing_address')if shipping_address:shipping_address.save()- instance.shipping_address = shipping_address+ instance.shipping_address = shipping_address.get_copy()if billing_address:billing_address.save()- instance.billing_address = billing_address+ instance.billing_address = billing_address.get_copy()instance.save()diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex 2f01f739cd..98c8886002 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -111,11 +111,11 @@ class DraftOrderCreate(ModelMutation, I18nMixin):shipping_address = cleaned_input.get('shipping_address')if shipping_address:shipping_address.save()- instance.shipping_address = shipping_address+ instance.shipping_address = shipping_address.get_copy()billing_address = cleaned_input.get('billing_address')if billing_address:billing_address.save()- instance.billing_address = billing_address+ instance.billing_address = billing_address.get_copy()super().save(info, instance, cleaned_input)instance.save(update_fields=['billing_address', 'shipping_address'])variants = cleaned_input.get('variants')diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex d68a7dd506..d056ef31cc 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -148,8 +148,10 @@ def test_checkout_create_logged_in_customer(user_api_client, variant):cart_user = new_cart.usercustomer = user_api_client.userassert customer.id == cart_user.id- assert customer.default_shipping_address_id == new_cart.shipping_address_id- assert customer.default_billing_address_id == new_cart.billing_address_id+ assert customer.default_shipping_address_id != new_cart.shipping_address_id+ assert customer.default_shipping_address.as_data() == new_cart.shipping_address.as_data()+ assert customer.default_billing_address_id != new_cart.billing_address_id+ assert customer.default_billing_address.as_data() == new_cart.billing_address.as_data()assert customer.email == new_cart.emaildiff --git a/tests/api/test_order.py b/tests/api/test_order.pyindex b3b1cfb133..a9b8a8dc7c 100644--- a/tests/api/test_order.py+++ b/tests/api/test_order.py@@ -374,7 +374,9 @@ def test_draft_order_create(order = Order.objects.first()assert order.user == customer_user- assert order.billing_address == customer_user.default_billing_address+ # billing address should be copied+ assert order.billing_address.pk != customer_user.default_billing_address.pk+ assert order.billing_address.as_data() == customer_user.default_billing_address.as_data()assert order.shipping_method == shipping_methodassert order.shipping_address.first_name == graphql_address_data['firstName']