Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
C&C address shoulnt be stored in customer address book (#10646)
Filip Owczarek5f5fa4408af7
diff --git a/saleor/checkout/complete_checkout.py b/saleor/checkout/complete_checkout.pyindex f6afcab83f..918ffb9bfa 100644--- a/saleor/checkout/complete_checkout.py+++ b/saleor/checkout/complete_checkout.py@@ -114,7 +114,11 @@ def _process_shipping_data_for_order(delivery_method_info = checkout_info.delivery_method_infoshipping_address = delivery_method_info.shipping_address- if checkout_info.user and shipping_address:+ if (+ delivery_method_info.store_as_customer_address+ and checkout_info.user+ and shipping_address+ ):store_user_address(checkout_info.user, shipping_address, AddressType.SHIPPING, manager=manager)diff --git a/saleor/checkout/fetch.py b/saleor/checkout/fetch.pyindex 1f6e1a68b9..497c87e363 100644--- a/saleor/checkout/fetch.py+++ b/saleor/checkout/fetch.py@@ -96,6 +96,7 @@ class CheckoutInfo:class DeliveryMethodBase:delivery_method: Optional[Union["ShippingMethodData", "Warehouse"]] = Noneshipping_address: Optional["Address"] = None+ store_as_customer_address: bool = False@propertydef warehouse_pk(self) -> Optional[str]:@@ -127,6 +128,7 @@ class DeliveryMethodBase:class ShippingMethodInfo(DeliveryMethodBase):delivery_method: "ShippingMethodData"shipping_address: Optional["Address"]+ store_as_customer_address: bool = True@propertydef delivery_method_name(self) -> Dict[str, Optional[str]]:diff --git a/saleor/checkout/tests/test_checkout_complete.py b/saleor/checkout/tests/test_checkout_complete.pyindex cab0858849..2794f48d8f 100644--- a/saleor/checkout/tests/test_checkout_complete.py+++ b/saleor/checkout/tests/test_checkout_complete.py@@ -21,7 +21,12 @@ from ...plugins.manager import get_plugins_managerfrom ...product.models import ProductTranslation, ProductVariantTranslationfrom ...tests.utils import flush_post_commit_hooksfrom .. import calculations-from ..complete_checkout import _create_order, _prepare_order_data, complete_checkout+from ..complete_checkout import (+ _create_order,+ _prepare_order_data,+ _process_shipping_data_for_order,+ complete_checkout,+)from ..fetch import fetch_checkout_info, fetch_checkout_linesfrom ..utils import add_variant_to_checkout@@ -1392,3 +1397,64 @@ def test_complete_checkout_order_not_created_when_the_refund_is_ongoing(# thenassert not ordermocked_create_order.assert_not_called()+++def test_process_shipping_data_for_order_store_customer_shipping_address(+ checkout_with_item, customer_user, address_usa, shipping_method+):+ # given+ checkout = checkout_with_item++ checkout.user = customer_user+ checkout.billing_address = customer_user.default_billing_address+ checkout.shipping_address = address_usa+ checkout.shipping_method = shipping_method+ checkout.save()++ user_address_count = customer_user.addresses.count()++ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ shipping_price = zero_taxed_money(checkout.currency)++ # when+ _ = _process_shipping_data_for_order(checkout_info, shipping_price, manager, lines)++ # then+ new_user_address_count = customer_user.addresses.count()+ new_address_data = address_usa.as_data()+ assert new_user_address_count == user_address_count + 1+ assert customer_user.addresses.filter(**new_address_data).exists()+++def test_process_shipping_data_for_order_dont_store_customer_click_and_collect_address(+ checkout_with_item_for_cc, customer_user, address_usa, warehouse_for_cc+):+ # given+ checkout = checkout_with_item_for_cc++ warehouse_for_cc.address = address_usa+ warehouse_for_cc.save()++ checkout.user = customer_user+ checkout.billing_address = customer_user.default_billing_address+ checkout.shipping_address = None+ checkout.collection_point = warehouse_for_cc+ checkout.save()++ user_address_count = customer_user.addresses.count()++ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ shipping_price = zero_taxed_money(checkout.currency)++ # when+ _ = _process_shipping_data_for_order(checkout_info, shipping_price, manager, lines)++ # then+ new_user_address_count = customer_user.addresses.count()+ new_address_data = warehouse_for_cc.address.as_data()+ assert new_user_address_count == user_address_count+ assert not customer_user.addresses.filter(**new_address_data).exists()