Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Configurable customer address (#17364)
Iga Karbowiak032c72d8f461
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 51e761bc98..4cf4d94ff1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,6 +5,17 @@ All notable, unreleased changes to this project will be documented in this file.# 3.21.0 [Unreleased]### Highlights+- Introduced a configurable customer address strategy, allowing control over whether shipping or billing addresses are saved in the customer’s address book - #17364 by @IKarbowiak+ - Applies when a checkout or draft order is completed for a logged-in user.+ - Default behavior remains unchanged: addresses are saved for checkouts but not for draft orders.+ - The new save address setting is available in:+ - `checkoutCreate`+ - `checkoutShippingAddressUpdate`+ - `checkoutBillingAddressUpdate`+ - `draftOrderCreate`+ - `draftOrderUpdate`+ - The flag must be provided as part of an address; otherwise, an error is raised.+ - Does not apply to Click & Collect delivery methods — shipping address is not saved in such case.### Breaking changesdiff --git a/saleor/checkout/complete_checkout.py b/saleor/checkout/complete_checkout.pyindex 81ad7a6c56..5e63c209ae 100644--- a/saleor/checkout/complete_checkout.py+++ b/saleor/checkout/complete_checkout.py@@ -15,7 +15,7 @@ from django.utils import timezonefrom prices import Money, TaxedMoneyfrom ..account.error_codes import AccountErrorCode-from ..account.models import User+from ..account.models import Address, Userfrom ..account.utils import retrieve_user_by_email, store_user_addressfrom ..channel import MarkAsPaidStrategyfrom ..checkout import CheckoutAuthorizeStatus, calculations@@ -181,15 +181,23 @@ def _process_shipping_data_for_order(delivery_method_info = checkout_info.get_delivery_method_info()shipping_address = delivery_method_info.shipping_address- if (- delivery_method_info.store_as_customer_address- and checkout_info.user- and shipping_address+ # allow saving shipping address in case the delivery method is not provided,+ # but the shipping address is set+ if not delivery_method_info.delivery_method:+ shipping_address = checkout_info.shipping_address++ if _should_store_shipping_address_in_user_addresses(+ checkout_info, shipping_address):+ user = cast(User, checkout_info.user)+ shipping_address = cast(Address, shipping_address)store_user_address(- checkout_info.user, shipping_address, AddressType.SHIPPING, manager=manager+ user,+ shipping_address,+ AddressType.SHIPPING,+ manager=manager,)- if checkout_info.user.addresses.filter(pk=shipping_address.pk).exists():+ if user.addresses.filter(pk=shipping_address.pk).exists():shipping_address = shipping_address.get_copy()if shipping_address and delivery_method_info.warehouse_pk:@@ -212,11 +220,38 @@ def _process_shipping_data_for_order(return result+def _should_store_shipping_address_in_user_addresses(+ checkout_info: "CheckoutInfo", shipping_address: Optional["Address"]+) -> bool:+ """Determine whether the shipping address should be stored in the user's addresses.++ The address should be stored if:+ - the user is authenticated+ - the shipping address is set+ - the address is marked to be saved+ - the delivery method allows storing the address as a user address+ (the delivery method is not a collection point) or the delivery method is not set+ """+ delivery_method_info = checkout_info.get_delivery_method_info()+ address_marked_to_be_saved = checkout_info.checkout.save_shipping_address+ delivery_allows_storing_as_user_address = (+ delivery_method_info.store_as_customer_address+ )+ delivery_method_not_set = not delivery_method_info.is_delivery_method_set()++ save_shipping_address = address_marked_to_be_saved and (+ delivery_allows_storing_as_user_address or delivery_method_not_set+ )++ return bool(save_shipping_address and checkout_info.user and shipping_address)++def _process_user_data_for_order(checkout_info: "CheckoutInfo", manager):"""Fetch, process and return shipping data from checkout."""billing_address = checkout_info.billing_address+ save_billing_address = checkout_info.checkout.save_billing_address- if checkout_info.user and billing_address:+ if checkout_info.user and billing_address and save_billing_address:store_user_address(checkout_info.user, billing_address, AddressType.BILLING, manager=manager)diff --git a/saleor/checkout/error_codes.py b/saleor/checkout/error_codes.pyindex 158bfc0884..dc6fa8dd16 100644--- a/saleor/checkout/error_codes.py+++ b/saleor/checkout/error_codes.py@@ -33,6 +33,7 @@ class CheckoutErrorCode(Enum):NON_EDITABLE_GIFT_LINE = "non_editable_gift_line"NON_REMOVABLE_GIFT_LINE = "non_removable_gift_line"SHIPPING_CHANGE_FORBIDDEN = "shipping_change_forbidden"+ MISSING_ADDRESS_DATA = "missing_address_data"class OrderCreateFromCheckoutErrorCode(Enum):diff --git a/saleor/checkout/fetch.py b/saleor/checkout/fetch.pyindex e5f134f036..efdbf43046 100644--- a/saleor/checkout/fetch.py+++ b/saleor/checkout/fetch.py@@ -316,6 +316,9 @@ class DeliveryMethodBase:def is_method_in_valid_methods(self, checkout_info: "CheckoutInfo") -> bool:return False+ def is_delivery_method_set(self) -> bool:+ return bool(self.delivery_method)+@dataclass(frozen=True)class ShippingMethodInfo(DeliveryMethodBase):diff --git a/saleor/checkout/migrations/0076_checkout_save_billing_address_and_more.py b/saleor/checkout/migrations/0076_checkout_save_billing_address_and_more.pynew file mode 100644index 0000000000..398ba4607b--- /dev/null+++ b/saleor/checkout/migrations/0076_checkout_save_billing_address_and_more.py@@ -0,0 +1,38 @@+# Generated by Django 4.2.15 on 2025-02-11 10:00++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("checkout", "0075_merge_20250210_1203"),+ ]++ operations = [+ migrations.AddField(+ model_name="checkout",+ name="save_billing_address",+ field=models.BooleanField(default=True),+ ),+ migrations.AddField(+ model_name="checkout",+ name="save_shipping_address",+ field=models.BooleanField(default=True),+ ),+ migrations.RunSQL(+ sql="""+ ALTER TABLE checkout_checkout+ ALTER COLUMN save_billing_address+ SET DEFAULT true;+ """,+ reverse_sql=migrations.RunSQL.noop,+ ),+ migrations.RunSQL(+ sql="""+ ALTER TABLE checkout_checkout+ ALTER COLUMN save_shipping_address+ SET DEFAULT true;+ """,+ reverse_sql=migrations.RunSQL.noop,+ ),+ ]diff --git a/saleor/checkout/models.py b/saleor/checkout/models.pyindex a4a8d2b931..06079f96aa 100644--- a/saleor/checkout/models.py+++ b/saleor/checkout/models.py@@ -58,6 +58,7 @@ class Checkout(models.Model):related_name="checkouts",on_delete=models.PROTECT,)+ save_billing_address = models.BooleanField(default=True)billing_address = models.ForeignKey("account.Address",related_name="+",@@ -65,6 +66,8 @@ class Checkout(models.Model):null=True,on_delete=models.SET_NULL,)+ # do not apply on checkouts with collection point+ save_shipping_address = models.BooleanField(default=True)shipping_address = models.ForeignKey("account.Address",related_name="+",diff --git a/saleor/checkout/tests/test_checkout.py b/saleor/checkout/tests/test_checkout.pyindex 071e0ae55f..12334f6c20 100644--- a/saleor/checkout/tests/test_checkout.py+++ b/saleor/checkout/tests/test_checkout.py@@ -1950,27 +1950,35 @@ def test_change_address_in_checkout(checkout, address):manager = get_plugins_manager(allow_replica=False)lines, _ = fetch_checkout_lines(checkout)checkout_info = fetch_checkout_info(checkout, lines, manager)+ store_shipping_address_in_user_addresses = False+ store_billing_address_in_user_addresses = Falseshipping_updated_fields = change_shipping_address_in_checkout(checkout_info,address,+ store_shipping_address_in_user_addresses,lines,- manager,checkout.channel.shipping_method_listings.all(),)- billing_updated_fields = change_billing_address_in_checkout(checkout, address)+ billing_updated_fields = change_billing_address_in_checkout(+ checkout, address, store_billing_address_in_user_addresses+ )checkout.save(update_fields=shipping_updated_fields + billing_updated_fields)checkout.refresh_from_db()assert checkout.shipping_address == addressassert checkout.billing_address == addressassert checkout_info.shipping_address == address+ assert checkout.save_shipping_address == store_shipping_address_in_user_addresses+ assert checkout.save_billing_address == store_billing_address_in_user_addressesdef test_change_address_in_checkout_to_none(checkout, address):checkout.shipping_address = addresscheckout.billing_address = address.get_copy()checkout.save()+ store_shipping_address_in_user_addresses = False+ store_billing_address_in_user_addresses = Truemanager = get_plugins_manager(allow_replica=False)lines, _ = fetch_checkout_lines(checkout)@@ -1978,17 +1986,21 @@ def test_change_address_in_checkout_to_none(checkout, address):shipping_updated_fields = change_shipping_address_in_checkout(checkout_info,None,+ store_shipping_address_in_user_addresses,lines,- manager,checkout.channel.shipping_method_listings.all(),)- billing_updated_fields = change_billing_address_in_checkout(checkout, None)+ billing_updated_fields = change_billing_address_in_checkout(+ checkout, None, store_billing_address_in_user_addresses+ )checkout.save(update_fields=shipping_updated_fields + billing_updated_fields)checkout.refresh_from_db()assert checkout.shipping_address is Noneassert checkout.billing_address is Noneassert checkout_info.shipping_address is None+ assert checkout.save_shipping_address == store_shipping_address_in_user_addresses+ assert checkout.save_billing_address == store_billing_address_in_user_addressesdef test_change_address_in_checkout_to_same(checkout, address):@@ -1997,6 +2009,8 @@ def test_change_address_in_checkout_to_same(checkout, address):checkout.save(update_fields=["shipping_address", "billing_address"])shipping_address_id = checkout.shipping_address.idbilling_address_id = checkout.billing_address.id+ store_shipping_address_in_user_addresses = True+ store_billing_address_in_user_addresses = Falsemanager = get_plugins_manager(allow_replica=False)lines, _ = fetch_checkout_lines(checkout)@@ -2004,17 +2018,21 @@ def test_change_address_in_checkout_to_same(checkout, address):shipping_updated_fields = change_shipping_address_in_checkout(checkout_info,address,+ store_shipping_address_in_user_addresses,lines,- manager,checkout.channel.shipping_method_listings.all(),)- billing_updated_fields = change_billing_address_in_checkout(checkout, address)+ billing_updated_fields = change_billing_address_in_checkout(+ checkout, address, store_billing_address_in_user_addresses+ )checkout.save(update_fields=shipping_updated_fields + billing_updated_fields)checkout.refresh_from_db()assert checkout.shipping_address.id == shipping_address_idassert checkout.billing_address.id == billing_address_idassert checkout_info.shipping_address == address+ assert checkout.save_shipping_address == store_shipping_address_in_user_addresses+ assert checkout.save_billing_address == store_billing_address_in_user_addressesdef test_change_address_in_checkout_to_other(checkout, address):@@ -2023,6 +2041,8 @@ def test_change_address_in_checkout_to_other(checkout, address):checkout.billing_address = address.get_copy()checkout.save(update_fields=["shipping_address", "billing_address"])other_address = Address.objects.create(country=Country("DE"))+ store_shipping_address_in_user_addresses = True+ store_billing_address_in_user_addresses = Truemanager = get_plugins_manager(allow_replica=False)lines, _ = fetch_checkout_lines(checkout)@@ -2030,11 +2050,13 @@ def test_change_address_in_checkout_to_other(checkout, address):shipping_updated_fields = change_shipping_address_in_checkout(checkout_info,other_address,+ store_shipping_address_in_user_addresses,lines,- manager,checkout.channel.shipping_method_listings.all(),)- billing_updated_fields = change_billing_address_in_checkout(checkout, other_address)+ billing_updated_fields = change_billing_address_in_checkout(+ checkout, other_address, store_billing_address_in_user_addresses+ )checkout.save(update_fields=shipping_updated_fields + billing_updated_fields)checkout.refresh_from_db()@@ -2042,6 +2064,8 @@ def test_change_address_in_checkout_to_other(checkout, address):assert checkout.billing_address == other_addressassert not Address.objects.filter(id=address_id).exists()assert checkout_info.shipping_address == other_address+ assert checkout.save_shipping_address == store_shipping_address_in_user_addresses+ assert checkout.save_billing_address == store_billing_address_in_user_addressesdef test_change_address_in_checkout_from_user_address_to_other(@@ -2053,6 +2077,8 @@ def test_change_address_in_checkout_from_user_address_to_other(checkout.billing_address = address.get_copy()checkout.save(update_fields=["shipping_address", "billing_address"])other_address = Address.objects.create(country=Country("DE"))+ store_shipping_address_in_user_addresses = False+ store_billing_address_in_user_addresses = Truemanager = get_plugins_manager(allow_replica=False)lines, _ = fetch_checkout_lines(checkout)@@ -2060,11 +2086,13 @@ def test_change_address_in_checkout_from_user_address_to_other(shipping_updated_fields = change_shipping_address_in_checkout(checkout_info,other_address,+ store_shipping_address_in_user_addresses,lines,- manager,checkout.channel.shipping_method_listings.all(),)- billing_updated_fields = change_billing_address_in_checkout(checkout, other_address)+ billing_updated_fields = change_billing_address_in_checkout(+ checkout, other_address, store_billing_address_in_user_addresses+ )checkout.save(update_fields=shipping_updated_fields + billing_updated_fields)checkout.refresh_from_db()@@ -2072,6 +2100,8 @@ def test_change_address_in_checkout_from_user_address_to_other(assert checkout.billing_address == other_addressassert Address.objects.filter(id=address_id).exists()assert checkout_info.shipping_address == other_address+ assert checkout.save_shipping_address == store_shipping_address_in_user_addresses+ assert checkout.save_billing_address == store_billing_address_in_user_addressesdef test_change_address_in_checkout_invalidates_shipping_methods(@@ -2079,6 +2109,7 @@ def test_change_address_in_checkout_invalidates_shipping_methods():# givencheckout = checkout_with_items+ store_address_in_user_addresses = Truemanager = get_plugins_manager(allow_replica=False)lines, _ = fetch_checkout_lines(checkout)@@ -2096,11 +2127,13 @@ def test_change_address_in_checkout_invalidates_shipping_methods(shipping_updated_fields = change_shipping_address_in_checkout(checkout_info,address,+ store_address_in_user_addresses,lines,- manager,checkout.channel.shipping_method_listings.all(),)- billing_updated_fields = change_billing_address_in_checkout(checkout, address)+ billing_updated_fields = change_billing_address_in_checkout(+ checkout, address, store_address_in_user_addresses+ )checkout.save(update_fields=shipping_updated_fields + billing_updated_fields)checkout.refresh_from_db()diff --git a/saleor/checkout/tests/test_checkout_complete.py b/saleor/checkout/tests/test_checkout_complete.pyindex f99079ea82..a38fa62892 100644--- a/saleor/checkout/tests/test_checkout_complete.py+++ b/saleor/checkout/tests/test_checkout_complete.py@@ -35,6 +35,7 @@ from ..complete_checkout import (_increase_checkout_voucher_usage,_prepare_order_data,_process_shipping_data_for_order,+ _process_user_data_for_order,_release_checkout_voucher_usage,complete_checkout,)@@ -1878,8 +1879,51 @@ def test_process_shipping_data_for_order_store_customer_shipping_address(assert customer_user.addresses.filter(**new_address_data).exists()+def test_process_shipping_data_for_order_not_store_customer_shipping_address_saving_addresses_off(+ 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_shipping_address = False+ checkout.save()++ user_address_count = customer_user.addresses.count()++ manager = get_plugins_manager(allow_replica=False)+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ shipping_price = zero_taxed_money(checkout.currency)+ base_shipping_price = zero_money(checkout.currency)++ # when+ _ = _process_shipping_data_for_order(+ checkout_info,+ base_shipping_price,+ base_shipping_price,+ 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+ assert not customer_user.addresses.filter(**new_address_data).exists()++[email protected]("save_shipping_address", [True, False])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+ save_shipping_address,+ checkout_with_item_for_cc,+ customer_user,+ address_usa,+ warehouse_for_cc,):# givencheckout = checkout_with_item_for_cc@@ -1891,6 +1935,7 @@ def test_process_shipping_data_for_order_dont_store_customer_click_and_collect_acheckout.billing_address = customer_user.default_billing_addresscheckout.shipping_address = Nonecheckout.collection_point = warehouse_for_cc+ checkout.save_shipping_address = save_shipping_addresscheckout.save()user_address_count = customer_user.addresses.count()@@ -1918,6 +1963,57 @@ def test_process_shipping_data_for_order_dont_store_customer_click_and_collect_aassert not customer_user.addresses.filter(**new_address_data).exists()+def test_process_user_data_for_order_store_customer_address(+ checkout_with_item, address_usa, customer_user+):+ # given+ checkout = checkout_with_item+ user_address_count = customer_user.addresses.count()++ checkout.user = customer_user+ checkout.billing_address = address_usa+ checkout.save(update_fields=["user", "billing_address"])++ manager = get_plugins_manager(allow_replica=False)+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, manager)++ # when+ _process_user_data_for_order(checkout_info, manager)++ # 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_user_data_for_order_do_not_store_customer_address_saving_addresses_off(+ checkout_with_item, address_usa, customer_user+):+ # given+ checkout = checkout_with_item+ user_address_count = customer_user.addresses.count()++ checkout.user = customer_user+ checkout.billing_address = address_usa+ checkout.save_billing_address = False+ checkout.save(update_fields=["user", "billing_address", "save_billing_address"])++ manager = get_plugins_manager(allow_replica=False)+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, manager)++ # when+ _process_user_data_for_order(checkout_info, manager)++ # then+ new_user_address_count = customer_user.addresses.count()+ new_address_data = address_usa.as_data()+ assert new_user_address_count == user_address_count+ assert not customer_user.addresses.filter(**new_address_data).exists()++def test_create_order_update_display_gross_prices(checkout_with_item, customer_user):# givencheckout = checkout_with_itemdiff --git a/saleor/checkout/tests/test_delivery_assignent_to_checkout.py b/saleor/checkout/tests/test_delivery_assignent_to_checkout.pyindex 3a01167b89..17cc307c8a 100644--- a/saleor/checkout/tests/test_delivery_assignent_to_checkout.py+++ b/saleor/checkout/tests/test_delivery_assignent_to_checkout.py@@ -18,7 +18,11 @@ def test_remove_delivery_method_from_checkout_with_cc(checkout_with_delivery_method_for_cc,):# given- expected_updated_fields = {"collection_point_id", "shipping_address_id"}+ expected_updated_fields = {+ "collection_point_id",+ "shipping_address_id",+ "save_shipping_address",+ }# whenupdated_fields = remove_delivery_method_from_checkout(checkout_with_delivery_method_for_cc@@ -91,6 +95,7 @@ def test_assign_external_shipping_to_checkout_with_cc("shipping_method_name","collection_point_id","shipping_address_id",+ "save_shipping_address",}# when@@ -264,6 +269,7 @@ def test_assign_built_in_shipping_to_checkout_with_cc("collection_point_id","shipping_address_id","undiscounted_base_shipping_price_amount",+ "save_shipping_address",}shipping_method_data = ShippingMethodData(id=str(shipping_method.id),@@ -371,7 +377,11 @@ def test_assign_collection_point_to_checkout_without_delivery_method():# givencollection_point = warehouses_for_cc[0]- expected_updated_fields = {"collection_point_id", "shipping_address_id"}+ expected_updated_fields = {+ "collection_point_id",+ "shipping_address_id",+ "save_shipping_address",+ }# whenfields_to_update = assign_collection_point_to_checkout(checkout, collection_point)@@ -397,6 +407,7 @@ def test_assign_collection_point_to_checkout_with_external_shipping_method("shipping_address_id","external_shipping_method_id","shipping_method_name",+ "save_shipping_address",}# when@@ -424,6 +435,7 @@ def test_assign_collection_point_to_checkout_with_shipping_method("shipping_address_id","shipping_method_id","shipping_method_name",+ "save_shipping_address",}# when@@ -453,6 +465,7 @@ def test_assign_collection_point_to_checkout_with_different_cc(expected_updated_fields = {"collection_point_id","shipping_address_id",+ "save_shipping_address",}# whendiff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex 6a3bbe5abe..7913086768 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -467,7 +467,9 @@ def _check_new_checkout_address(checkout, address, address_type):return has_address_changed, remove_old_address-def change_billing_address_in_checkout(checkout, address) -> list[str]:+def change_billing_address_in_checkout(+ checkout: "Checkout", address: "Address", store_in_user_addresses: bool+) -> list[str]:"""Save billing address in checkout if changed.Remove previously saved address if not connected to any user.@@ -480,17 +482,20 @@ def change_billing_address_in_checkout(checkout, address) -> list[str]:updated_fields = []if changed:if remove:- checkout.billing_address.delete()+ checkout.billing_address.delete() # type: ignore[union-attr]checkout.billing_address = addressupdated_fields = ["billing_address", "last_change"]+ if checkout.save_billing_address != store_in_user_addresses:+ checkout.save_billing_address = store_in_user_addresses+ updated_fields.append("save_billing_address")return updated_fieldsdef change_shipping_address_in_checkout(checkout_info: "CheckoutInfo",address: "Address",+ store_in_user_addresses: bool,lines: list["CheckoutLineInfo"],- manager: "PluginsManager",shipping_channel_listings: Iterable["ShippingMethodChannelListing"],):"""Save shipping address in checkout if changed.@@ -517,6 +522,9 @@ def change_shipping_address_in_checkout(shipping_channel_listings=shipping_channel_listings,)updated_fields = ["shipping_address", "last_change"]+ if checkout.save_shipping_address != store_in_user_addresses:+ checkout.save_shipping_address = store_in_user_addresses+ updated_fields.append("save_shipping_address")return updated_fields@@ -1155,7 +1163,9 @@ def remove_click_and_collect_from_checkout(checkout: Checkout) -> list[str]:fields_to_update.append("collection_point_id")if checkout.shipping_address_id:checkout.shipping_address = None- fields_to_update.append("shipping_address_id")+ # reset the save_shipping_address flag to the default value+ checkout.save_shipping_address = True+ fields_to_update.extend(["shipping_address_id", "save_shipping_address"])return fields_to_update@@ -1236,7 +1246,8 @@ def assign_collection_point_to_checkout(fields_to_update.append("collection_point_id")if checkout.shipping_address != collection_point.address:checkout.shipping_address = collection_point.address.get_copy()- fields_to_update.append("shipping_address_id")+ checkout.save_shipping_address = False+ fields_to_update.extend(["shipping_address_id", "save_shipping_address"])return fields_to_updatediff --git a/saleor/graphql/account/i18n.py b/saleor/graphql/account/i18n.pyindex a2128c4ebf..7f30c9ddac 100644--- a/saleor/graphql/account/i18n.py+++ b/saleor/graphql/account/i18n.py@@ -159,7 +159,7 @@ class I18nMixin:format_check=True,required_check=True,enable_normalization=True,- ):+ ) -> Address:if address_data.get("country") is None:params = {"address_type": address_type} if address_type else {}raise ValidationError(diff --git a/saleor/graphql/checkout/mutations/checkout_billing_address_update.py b/saleor/graphql/checkout/mutations/checkout_billing_address_update.pyindex ae6f6f7efb..c87153b111 100644--- a/saleor/graphql/checkout/mutations/checkout_billing_address_update.py+++ b/saleor/graphql/checkout/mutations/checkout_billing_address_update.py@@ -9,7 +9,7 @@ from ....webhook.event_types import WebhookEventAsyncTypefrom ...account.types import AddressInputfrom ...core import ResolveInfofrom ...core.context import SyncWebhookControlContext-from ...core.descriptions import DEPRECATED_IN_3X_INPUT+from ...core.descriptions import ADDED_IN_321, DEPRECATED_IN_3X_INPUTfrom ...core.doc_category import DOC_CATEGORY_CHECKOUTfrom ...core.scalars import UUIDfrom ...core.types import CheckoutError@@ -42,6 +42,16 @@ class CheckoutBillingAddressUpdate(CheckoutShippingAddressUpdate):billing_address = AddressInput(required=True, description="The billing address of the checkout.")+ save_address = graphene.Boolean(+ required=False,+ default_value=True,+ description=(+ "Indicates whether the billing address should be saved "+ "to the user’s address book upon checkout completion. "+ "If not provided, the default behavior is to save the address."+ )+ + ADDED_IN_321,+ )validation_rules = CheckoutAddressValidationRules(required=False,description=(@@ -69,6 +79,7 @@ class CheckoutBillingAddressUpdate(CheckoutShippingAddressUpdate):/,*,billing_address,+ save_address,validation_rules=None,checkout_id=None,token=None,@@ -92,7 +103,7 @@ class CheckoutBillingAddressUpdate(CheckoutShippingAddressUpdate):with traced_atomic_transaction():billing_address.save()change_address_updated_fields = change_billing_address_in_checkout(- checkout, billing_address+ checkout, billing_address, save_address)lines, _ = fetch_checkout_lines(checkout)checkout_info = fetch_checkout_info(checkout, lines, manager)diff --git a/saleor/graphql/checkout/mutations/checkout_create.py b/saleor/graphql/checkout/mutations/checkout_create.pyindex d43a9f146f..4673d77044 100644--- a/saleor/graphql/checkout/mutations/checkout_create.py+++ b/saleor/graphql/checkout/mutations/checkout_create.py@@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Optionalimport graphenefrom django.conf import settings+from django.core.exceptions import ValidationErrorfrom ....checkout import AddressType, modelsfrom ....checkout.actions import call_checkout_event@@ -18,7 +19,7 @@ from ...app.dataloaders import get_app_promisefrom ...channel.utils import clean_channelfrom ...core import ResolveInfofrom ...core.context import SyncWebhookControlContext-from ...core.descriptions import DEPRECATED_IN_3X_FIELD+from ...core.descriptions import ADDED_IN_321, DEPRECATED_IN_3X_FIELDfrom ...core.doc_category import DOC_CATEGORY_CHECKOUTfrom ...core.enums import LanguageCodeEnumfrom ...core.mutations import ModelMutation@@ -137,6 +138,15 @@ class CheckoutCreateInput(BaseInputObjectType):required=True,)email = graphene.String(description="The customer's email address.")+ save_shipping_address = graphene.Boolean(+ description=(+ "Indicates whether the shipping address should be saved "+ "to the user’s address book upon checkout completion."+ "Can only be set when a shipping address is provided. If not specified "+ "along with the address, the default behavior is to save the address."+ )+ + ADDED_IN_321+ )shipping_address = AddressInput(description=("The mailing address to where the checkout will be shipped. "@@ -145,6 +155,15 @@ class CheckoutCreateInput(BaseInputObjectType):"HANDLE_CHECKOUTS and AUTHENTICATED_APP permissions."))+ save_billing_address = graphene.Boolean(+ description=(+ "Indicates whether the billing address should be saved "+ "to the user’s address book upon checkout completion. "+ "Can only be set when a billing address is provided. If not specified "+ "along with the address, the default behavior is to save the address."+ )+ + ADDED_IN_321+ )billing_address = AddressInput(description=("Billing address of the customer. `skipValidation` requires "@@ -291,11 +310,13 @@ class CheckoutCreate(ModelMutation, I18nMixin):cleaned_input["channel"] = channelcleaned_input["currency"] = channel.currency_code+ save_shipping_address = data.get("save_shipping_address")shipping_address_metadata = (data.get("shipping_address", {}).pop("metadata", [])if data.get("shipping_address")else None)+ save_billing_address = data.get("save_billing_address")billing_address_metadata = (data.get("billing_address", {}).pop("metadata", [])if data.get("billing_address")@@ -308,6 +329,28 @@ class CheckoutCreate(ModelMutation, I18nMixin):if billing_address:cls.update_metadata(billing_address, billing_address_metadata)+ if save_shipping_address is not None and not shipping_address:+ raise ValidationError(+ {+ "save_shipping_address": ValidationError(+ "This option can only be selected if a shipping address "+ "is provided.",+ code=CheckoutErrorCode.MISSING_ADDRESS_DATA.value,+ )+ }+ )++ if save_billing_address is not None and not billing_address:+ raise ValidationError(+ {+ "save_billing_address": ValidationError(+ "This option can only be selected if a billing address "+ "is provided.",+ code=CheckoutErrorCode.MISSING_ADDRESS_DATA.value,+ )+ }+ )+country = get_active_country(channel,shipping_address,diff --git a/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py b/saleor/graphql/checkout/mutations/checkout_shipping_address_update.pyindex 4ba8130d3e..8202658809 100644--- a/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py+++ b/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py@@ -22,7 +22,7 @@ from ....webhook.event_types import WebhookEventAsyncTypefrom ...account.i18n import I18nMixinfrom ...account.types import AddressInputfrom ...core.context import SyncWebhookControlContext-from ...core.descriptions import DEPRECATED_IN_3X_INPUT+from ...core.descriptions import ADDED_IN_321, DEPRECATED_IN_3X_INPUTfrom ...core.doc_category import DOC_CATEGORY_CHECKOUTfrom ...core.mutations import BaseMutationfrom ...core.scalars import UUID@@ -65,6 +65,16 @@ class CheckoutShippingAddressUpdate(AddressMetadataMixin, BaseMutation, I18nMixirequired=True,description="The mailing address to where the checkout will be shipped.",)+ save_address = graphene.Boolean(+ required=False,+ default_value=True,+ description=(+ "Indicates whether the shipping address should be saved "+ "to the user’s address book upon checkout completion. "+ "If not provided, the default behavior is to save the address."+ )+ + ADDED_IN_321,+ )validation_rules = CheckoutAddressValidationRules(required=False,description=(@@ -120,6 +130,7 @@ class CheckoutShippingAddressUpdate(AddressMetadataMixin, BaseMutation, I18nMixiinfo,/,shipping_address,+ save_address,validation_rules=None,checkout_id=None,token=None,@@ -192,8 +203,8 @@ class CheckoutShippingAddressUpdate(AddressMetadataMixin, BaseMutation, I18nMixishipping_address_updated_fields = change_shipping_address_in_checkout(checkout_info,shipping_address_instance,+ save_address,lines,- manager,shipping_channel_listings,)invalidate_prices_updated_fields = invalidate_checkout(diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.pyindex edcd1d0097..0542efd6e1 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.py@@ -11,12 +11,14 @@ from .....product.models import ProductChannelListing, ProductVariantChannelListfrom .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncTypefrom ....core.utils import to_global_id_or_nonefrom ....tests.utils import assert_no_permission, get_graphql_content+from ..utils import assert_address_dataMUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE = """mutation checkoutBillingAddressUpdate($checkoutId: ID,$id: ID,$billingAddress: AddressInput!+ $saveAddress: Boolean$validationRules: CheckoutAddressValidationRules) {checkoutBillingAddressUpdate(@@ -24,6 +26,7 @@ MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE = """checkoutId: $checkoutId,billingAddress: $billingAddressvalidationRules: $validationRules+ saveAddress: $saveAddress){checkout {token,@@ -58,19 +61,8 @@ def test_checkout_billing_address_update_by_id(data = content["data"]["checkoutBillingAddressUpdate"]assert not data["errors"]checkout.refresh_from_db()- assert checkout.billing_address is not None- assert checkout.billing_address.first_name == billing_address["firstName"]- assert checkout.billing_address.last_name == billing_address["lastName"]- assert (- checkout.billing_address.street_address_1 == billing_address["streetAddress1"]- )- assert (- checkout.billing_address.street_address_2 == billing_address["streetAddress2"]- )- assert checkout.billing_address.postal_code == billing_address["postalCode"]- assert checkout.billing_address.country == billing_address["country"]- assert checkout.billing_address.city == billing_address["city"].upper()- assert checkout.billing_address.validation_skipped is False+ assert_address_data(checkout.billing_address, billing_address)+ assert checkout.save_billing_address is True@pytest.mark.parametrize(@@ -110,19 +102,8 @@ def test_checkout_billing_address_update_when_line_without_listing(data = content["data"]["checkoutBillingAddressUpdate"]assert not data["errors"]checkout.refresh_from_db()- assert checkout.billing_address is not None- assert checkout.billing_address.first_name == billing_address["firstName"]- assert checkout.billing_address.last_name == billing_address["lastName"]- assert (- checkout.billing_address.street_address_1 == billing_address["streetAddress1"]- )- assert (- checkout.billing_address.street_address_2 == billing_address["streetAddress2"]- )- assert checkout.billing_address.postal_code == billing_address["postalCode"]- assert checkout.billing_address.country == billing_address["country"]- assert checkout.billing_address.city == billing_address["city"].upper()- assert checkout.billing_address.validation_skipped is False+ assert_address_data(checkout.billing_address, billing_address)+ assert checkout.save_billing_address is Truedef test_checkout_billing_address_update_by_id_without_required_fields(@@ -184,20 +165,8 @@ def test_checkout_billing_address_update_by_id_without_street_address_2(data = content["data"]["checkoutBillingAddressUpdate"]assert not data["errors"]checkout.refresh_from_db()- assert checkout.billing_address is not None- assert checkout.billing_address.first_name == billing_address["firstName"]- assert checkout.billing_address.last_name == billing_address["lastName"]- assert (- checkout.billing_address.street_address_1 == billing_address["streetAddress1"]- )- assert (- checkout.billing_address.street_address_2- == billing_address["streetAddress2"]- == ""- )- assert checkout.billing_address.postal_code == billing_address["postalCode"]- assert checkout.billing_address.country == billing_address["country"]- assert checkout.billing_address.city == billing_address["city"].upper()+ assert_address_data(checkout.billing_address, billing_address)+ assert checkout.save_billing_address is True@mock.patch(@@ -242,21 +211,10 @@ def test_checkout_billing_address_update(data = content["data"]["checkoutBillingAddressUpdate"]assert not data["errors"]checkout.refresh_from_db()- assert checkout.billing_address.metadata == {"public": "public_value"}- assert checkout.billing_address is not None- assert checkout.billing_address.first_name == billing_address["firstName"]- assert checkout.billing_address.last_name == billing_address["lastName"]- assert (- checkout.billing_address.street_address_1 == billing_address["streetAddress1"]- )- assert (- checkout.billing_address.street_address_2 == billing_address["streetAddress2"]- )- assert checkout.billing_address.postal_code == billing_address["postalCode"]- assert checkout.billing_address.country == billing_address["country"]- assert checkout.billing_address.city == billing_address["city"].upper()+ assert_address_data(checkout.billing_address, billing_address)assert checkout.last_change != previous_last_changeassert mocked_invalidate_checkout.call_count == 1+ assert checkout.save_billing_address is True@pytest.mark.parametrize(@@ -791,3 +749,113 @@ def test_checkout_billing_address_triggers_webhooks(tax_delivery = tax_delivery_call.args[0]assert tax_delivery.webhook_id == tax_webhook.id+++def test_checkout_billing_address_update_reset_the_save_address_flag_to_default_value(+ checkout_with_items,+ user_api_client,+ graphql_address_data,+ address,+):+ checkout = checkout_with_items+ # given checkout billing and billing address set both save billing flags different+ # than default value - set to False+ checkout.billing_address = address+ checkout.billing_address = address+ checkout.save_billing_address = False+ checkout.save_shipping_address = False+ checkout.save(+ update_fields=[+ "billing_address",+ "billing_address",+ "save_billing_address",+ "save_shipping_address",+ ]+ )++ variables = {+ "id": to_global_id_or_none(checkout_with_items),+ "billingAddress": graphql_address_data,+ }++ # when the checkout billing address is updated without providing saveAddress flag+ response = user_api_client.post_graphql(+ MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE,+ variables,+ )+ content = get_graphql_content(response)++ # then the checkout billing address is updated, and `save_billing_address` is+ # reset to the default True value; the `save_billing_address` is not changed+ data = content["data"]["checkoutBillingAddressUpdate"]+ assert not data["errors"]++ checkout.refresh_from_db()+ assert_address_data(checkout.billing_address, graphql_address_data)+ assert checkout.save_billing_address is True+ assert checkout.save_shipping_address is False+++def test_checkout_billing_address_update_with_save_address_to_false(+ checkout_with_items,+ user_api_client,+ graphql_address_data,+):+ # given checkout with default saving address values+ checkout = checkout_with_items++ save_address = False+ variables = {+ "id": to_global_id_or_none(checkout_with_items),+ "billingAddress": graphql_address_data,+ "saveAddress": save_address,+ }++ # when update billing address with saveAddress flag set to False+ response = user_api_client.post_graphql(+ MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE,+ variables,+ )+ content = get_graphql_content(response)++ # then the address should be saved and the save_billing_address should be False+ data = content["data"]["checkoutBillingAddressUpdate"]+ assert not data["errors"]+ checkout.refresh_from_db()+ assert_address_data(checkout.billing_address, graphql_address_data)+ assert checkout.save_billing_address is save_address+ assert checkout.save_shipping_address is True+++def test_checkout_billing_address_update_change_save_address_option_to_true(+ checkout_with_items,+ user_api_client,+ graphql_address_data,+):+ # given checkout with save addresses settings to False+ checkout = checkout_with_items+ checkout.save_billing_address = False+ checkout.save_shipping_address = False+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])++ variables = {+ "id": to_global_id_or_none(checkout_with_items),+ "billingAddress": graphql_address_data,+ "saveAddress": True,+ }++ # when the billing address is updated with saveAddress flag set to True+ response = user_api_client.post_graphql(+ MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE,+ variables,+ )+ content = get_graphql_content(response)++ # then the address should be saved and the save_billing_address should be True+ # the save_billing_address should not be changed+ data = content["data"]["checkoutBillingAddressUpdate"]+ assert not data["errors"]+ checkout.refresh_from_db()+ assert_address_data(checkout.billing_address, graphql_address_data)+ assert checkout.save_billing_address is True+ assert checkout.save_shipping_address is Falsediff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_complete.py b/saleor/graphql/checkout/tests/mutations/test_checkout_complete.pyindex b3a2c6b6ca..ce22153d2c 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_complete.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_complete.py@@ -607,3 +607,56 @@ def test_checkout_complete_calls_correct_force_tax_calculation_when_tax_error_wacheckout.refresh_from_db()assert checkout.price_expiration == timezone.now() + settings.CHECKOUT_PRICES_TTLassert checkout.tax_error is None+++def test_checkout_complete_existing_user_address_save_address_options_off(+ user_api_client,+ checkout_with_item_total_0,+ customer_user,+):+ # given the checkout with the billing address that is currently in user address book+ # and the save_address option set to False+ checkout = checkout_with_item_total_0++ address = customer_user.addresses.first()+ user_address_count = customer_user.addresses.count()++ checkout.billing_address = address+ checkout.shipping_address = address+ checkout.save_shipping_address = False+ checkout.save_billing_address = False+ checkout.save(+ update_fields=[+ "billing_address",+ "shipping_address",+ "save_shipping_address",+ "save_billing_address",+ ]+ )++ orders_count = Order.objects.count()+ variables = {+ "id": to_global_id_or_none(checkout),+ "redirectUrl": "https://www.example.com",+ }++ # when checkout is completed+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)++ # then the addresses are not saved or removed from the user address book+ content = get_graphql_content(response)+ data = content["data"]["checkoutComplete"]+ assert not data["errors"]++ assert Order.objects.count() == orders_count + 1+ order = Order.objects.first()++ assert not Checkout.objects.filter(pk=checkout.pk).exists(), (+ "Checkout should have been deleted"+ )+ assert order.billing_address+ assert order.shipping_address+ assert customer_user.addresses.count() == user_address_count++ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is Nonediff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.py b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.pyindex 9fed517000..f38b7582f4 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.py@@ -170,6 +170,8 @@ def test_checkout_complete(gift_card,payment_dummy,address,+ address_usa,+ customer_user,shipping_method,caplog,):@@ -177,9 +179,10 @@ def test_checkout_complete(assert not gift_card.last_used_oncheckout = checkout_with_gift_card+ checkout.user = customer_usercheckout.shipping_address = addresscheckout.shipping_method = shipping_method- checkout.billing_address = address+ checkout.billing_address = address_usacheckout.metadata_storage.store_value_in_metadata(items={"accepted": "true"})checkout.metadata_storage.store_value_in_private_metadata(items={"accepted": "false"}@@ -188,6 +191,9 @@ def test_checkout_complete(checkout.save()checkout.metadata_storage.save()+ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()+checkout_line = checkout.lines.first()checkout_line_quantity = checkout_line.quantitycheckout_line_variant = checkout_line.variant@@ -257,6 +263,7 @@ def test_checkout_complete(assert order_line.tax_class_metadata == line_tax_class.metadataassert order_line.tax_class_private_metadata == line_tax_class.private_metadata+ assert order.billing_address.id == address_usa.idassert order.shipping_address == addressassert order.shipping_method == checkout.shipping_methodassert order.shipping_tax_rate is not None@@ -299,6 +306,14 @@ def test_checkout_complete(caplog.records[0].total_after_gift_card_compensation)+ assert customer_user.addresses.count() == user_address_count + 2+ # ensure the the customer addresses are not the same instances as the order addresses+ customer_address_ids = list(customer_user.addresses.values_list("pk", flat=True))+ assert not (+ set(customer_address_ids)+ & {order.billing_address.pk, order.shipping_address.pk}+ )+@pytest.mark.integration@patch("saleor.plugins.manager.PluginsManager.order_confirmed")@@ -3371,7 +3386,7 @@ def test_create_order_raises_insufficient_stock(def test_checkout_complete_with_digital(- api_client, checkout_with_digital_item, address, payment_dummy+ api_client, checkout_with_digital_item, address, payment_dummy, customer_user):"""Ensure it is possible to complete a digital checkout without shipping."""@@ -3383,7 +3398,8 @@ def test_checkout_complete_with_digital(# Set a billing addresscheckout.billing_address = address- checkout.save(update_fields=["billing_address"])+ checkout.user = customer_user+ checkout.save(update_fields=["billing_address", "user"])# Create a dummy payment to chargemanager = get_plugins_manager(allow_replica=False)@@ -3415,7 +3431,7 @@ def test_checkout_complete_with_digital(def test_checkout_complete_with_digital_and_shipping_address(- api_client, checkout_with_digital_item, address, payment_dummy+ api_client, checkout_with_digital_item, address, payment_dummy, customer_user):"""Ensure it is possible to complete a digital checkout without shipping."""@@ -3428,7 +3444,8 @@ def test_checkout_complete_with_digital_and_shipping_address(# Set a billing addresscheckout.billing_address = addresscheckout.shipping_address = address- checkout.save(update_fields=["billing_address", "shipping_address"])+ checkout.user = customer_user+ checkout.save(update_fields=["billing_address", "shipping_address", "user"])# Create a dummy payment to chargemanager = get_plugins_manager(allow_replica=False)@@ -3455,11 +3472,72 @@ def test_checkout_complete_with_digital_and_shipping_address(# Ensure the order was actually createdassert order, "The order should have been created"- # FIXME: fix together with ext-1684- assert not order.shipping_address+ assert order.shipping_addressassert order.billing_address+def test_checkout_complete_with_digital_saving_addresses_off(+ api_client, checkout_with_digital_item, address, payment_dummy, customer_user+):+ """Ensure it is possible to complete a digital checkout without shipping."""++ checkout = checkout_with_digital_item+ variables = {+ "id": to_global_id_or_none(checkout),+ "redirectUrl": "https://www.example.com",+ }++ # Set a billing address+ checkout.billing_address = address+ checkout.shipping_address = address+ checkout.user = customer_user+ checkout.save_shipping_address = False+ checkout.save_billing_address = False+ checkout.save(+ update_fields=[+ "billing_address",+ "shipping_address",+ "user",+ "save_shipping_address",+ "save_billing_address",+ ]+ )++ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()++ # Create a dummy payment to charge+ manager = get_plugins_manager(allow_replica=False)+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ total = calculations.checkout_total(+ manager=manager, checkout_info=checkout_info, lines=lines, address=address+ )+ payment = payment_dummy+ payment.is_active = True+ payment.order = None+ payment.total = total.gross.amount+ payment.currency = total.gross.currency+ payment.checkout = checkout+ payment.save()+ assert not payment.transactions.exists()++ # Send the creation request+ response = api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)+ content = get_graphql_content(response)["data"]["checkoutComplete"]+ assert not content["errors"]++ order = Order.objects.first()+ # Ensure the order was actually created+ assert order, "The order should have been created"++ assert order.shipping_address+ assert order.billing_address+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None+ assert customer_user.addresses.count() == user_address_count++@pytest.mark.integrationdef test_checkout_complete_0_total_value(user_api_client,@@ -4801,6 +4879,162 @@ def test_checkout_complete_reservations_drop(assert not len(Reservation.objects.all())+def test_checkout_complete_saving_addresses_off(+ user_api_client,+ checkout_with_item,+ gift_card,+ payment_dummy,+ address,+ shipping_method,+ customer_user,+):+ # given+ checkout = checkout_with_item+ checkout.shipping_address = address+ checkout.shipping_method = shipping_method+ checkout.billing_address = address+ checkout.save_shipping_address = False+ checkout.save_billing_address = False+ checkout.user = customer_user+ checkout.save()++ manager = get_plugins_manager(allow_replica=False)+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ total = calculations.calculate_checkout_total_with_gift_cards(+ manager, checkout_info, lines, address+ )+ channel = checkout.channel+ channel.automatically_confirm_all_new_orders = True+ channel.save()+ payment = payment_dummy+ payment.is_active = True+ payment.order = None+ payment.total = total.gross.amount+ payment.currency = total.gross.currency+ payment.checkout = checkout+ payment.save()+ assert not payment.transactions.exists()++ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()++ orders_count = Order.objects.count()+ redirect_url = "https://www.example.com"+ metadata_value = "metaValue"+ metadata_key = "metaKey"+ variables = {+ "id": to_global_id_or_none(checkout),+ "redirectUrl": redirect_url,+ "metadata": [{"key": metadata_key, "value": metadata_value}],+ }++ # when+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)+ content = get_graphql_content(response)+ data = content["data"]["checkoutComplete"]++ # then+ assert not data["errors"]+ assert Order.objects.count() == orders_count + 1+ order = Order.objects.first()+ assert order.status == OrderStatus.UNFULFILLED+ assert order.origin == OrderOrigin.CHECKOUT+ assert not order.original++ assert not Checkout.objects.filter(pk=checkout.pk).exists(), (+ "Checkout should have been deleted"+ )++ assert order.billing_address+ assert order.shipping_address+ assert customer_user.addresses.count() == user_address_count+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None+++def test_checkout_complete_saving_addresses_on(+ user_api_client,+ checkout_with_item,+ gift_card,+ payment_dummy,+ address,+ shipping_method,+ customer_user,+ address_usa,+):+ # given+ checkout = checkout_with_item+ checkout.shipping_address = address+ checkout.shipping_method = shipping_method+ checkout.billing_address = address_usa+ checkout.save_shipping_address = True+ checkout.save_billing_address = True+ checkout.user = customer_user+ checkout.save()++ manager = get_plugins_manager(allow_replica=False)+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ total = calculations.calculate_checkout_total_with_gift_cards(+ manager, checkout_info, lines, address+ )+ channel = checkout.channel+ channel.automatically_confirm_all_new_orders = True+ channel.save()+ payment = payment_dummy+ payment.is_active = True+ payment.order = None+ payment.total = total.gross.amount+ payment.currency = total.gross.currency+ payment.checkout = checkout+ payment.save()+ assert not payment.transactions.exists()++ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()++ orders_count = Order.objects.count()+ redirect_url = "https://www.example.com"+ metadata_value = "metaValue"+ metadata_key = "metaKey"+ variables = {+ "id": to_global_id_or_none(checkout),+ "redirectUrl": redirect_url,+ "metadata": [{"key": metadata_key, "value": metadata_value}],+ }++ # when+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)+ content = get_graphql_content(response)+ data = content["data"]["checkoutComplete"]++ # then+ assert not data["errors"]+ assert Order.objects.count() == orders_count + 1+ order = Order.objects.first()+ assert order.status == OrderStatus.UNFULFILLED+ assert order.origin == OrderOrigin.CHECKOUT+ assert not order.original++ assert not Checkout.objects.filter(pk=checkout.pk).exists(), (+ "Checkout should have been deleted"+ )++ assert order.billing_address+ assert order.shipping_address+ assert customer_user.addresses.count() == user_address_count + 2+ # ensure the the customer addresses are not the same instances as the order addresses+ customer_address_ids = list(customer_user.addresses.values_list("pk", flat=True))+ assert not (+ set(customer_address_ids)+ & {order.billing_address.pk, order.shipping_address.pk}+ )++ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None++@pytest.mark.django_db(transaction=True)def test_checkout_complete_payment_create_create_run_in_meantime(site_settings,@@ -5013,7 +5247,12 @@ def test_checkout_complete_line_deleted_in_the_meantime(def test_checkout_complete_with_invalid_address(- api_client, checkout_with_item, address, payment_dummy, shipping_method+ api_client,+ checkout_with_item,+ address,+ payment_dummy,+ shipping_method,+ customer_user,):"""Check if checkout can be completed with invalid address.@@ -5035,10 +5274,14 @@ def test_checkout_complete_with_invalid_address(checkout.billing_address = addresscheckout.shipping_address = addresscheckout.shipping_method = shipping_method+ checkout.user = customer_usercheckout.save(- update_fields=["billing_address", "shipping_address", "shipping_method"]+ update_fields=["billing_address", "shipping_address", "shipping_method", "user"])+ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()+# Create a dummy payment to chargemanager = get_plugins_manager(allow_replica=False)lines, _ = fetch_checkout_lines(checkout)@@ -5064,6 +5307,11 @@ def test_checkout_complete_with_invalid_address(order = Order.objects.get(checkout_token=checkout.token)assert order.shipping_address.postal_code == invalid_postal_codeassert order.billing_address.postal_code == invalid_postal_code+ assert customer_user.addresses.count() == user_address_count + 1+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None+ assert customer_user.addresses.first().id != order.shipping_address.id+ assert customer_user.addresses.first().id != order.billing_address.id@patch("saleor.checkout.complete_checkout._get_unit_discount_reason")diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.py b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.pyindex 375d6f0ba5..54f8443b8e 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.py@@ -108,10 +108,16 @@ def prepare_checkout_for_test(transaction_events_generator,voucher=None,user=None,+ save_shipping_address=None,+ save_billing_address=None,):checkout.shipping_address = shipping_addresscheckout.shipping_method = shipping_methodcheckout.billing_address = billing_address+ if save_shipping_address is not None:+ checkout.save_shipping_address = save_shipping_address+ if save_billing_address is not None:+ checkout.save_billing_address = save_billing_addresscheckout.user = usercheckout.save()@@ -1259,19 +1265,22 @@ def test_checkout_complete(checkout_with_gift_card,gift_card,address,+ address_usa,shipping_method,transaction_events_generator,transaction_item_generator,caplog,+ customer_user,):# givencheckout = prepare_checkout_for_test(checkout_with_gift_card,address,- address,+ address_usa,shipping_method,transaction_item_generator,transaction_events_generator,+ user=customer_user,)checkout.metadata_storage.store_value_in_metadata(items={"accepted": "true"})@@ -1282,6 +1291,9 @@ def test_checkout_complete(checkout.save()checkout.metadata_storage.save()+ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()+checkout_line = checkout.lines.first()checkout_line_quantity = checkout_line.quantitycheckout_line_variant = checkout_line.variant@@ -1340,7 +1352,10 @@ def test_checkout_complete(assert order_line.tax_class_metadata == line_tax_class.metadataassert order_line.tax_class_private_metadata == line_tax_class.private_metadata+ assert order.billing_address.id == address_usa.idassert order.shipping_address == address+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is Noneassert order.shipping_method == checkout.shipping_methodassert order.shipping_tax_rate is not Noneassert order.shipping_tax_class_name == shipping_tax_class.name@@ -1375,6 +1390,16 @@ def test_checkout_complete(caplog.records[0].total_after_gift_card_compensation)+ assert customer_user.addresses.count() == user_address_count + 2+ # ensure the the customer addresses are not the same instances as the order addresses+ customer_address_ids = list(customer_user.addresses.values_list("pk", flat=True))+ assert not (+ set(customer_address_ids)+ & {order.billing_address.pk, order.shipping_address.pk}+ )+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None+@pytest.mark.integration@patch("saleor.plugins.manager.PluginsManager.order_confirmed")@@ -3471,15 +3496,19 @@ def test_checkout_complete_with_digital(api_client,checkout_with_digital_item,address,+ address_usa,transaction_events_generator,transaction_item_generator,customer_user,):# given+ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()+checkout = prepare_checkout_for_test(checkout_with_digital_item,address,- address,+ address_usa,None,transaction_item_generator,transaction_events_generator,@@ -3502,9 +3531,12 @@ def test_checkout_complete_with_digital(# Ensure the order was actually createdassert order, "The order should have been created"- # FIXME: fix together with ext-1684- assert not order.shipping_address+ assert order.shipping_addressassert order.billing_address+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None++ assert customer_user.addresses.count() == user_address_count + 2def test_checkout_complete_with_digital_no_shipping_address_set(@@ -3545,6 +3577,55 @@ def test_checkout_complete_with_digital_no_shipping_address_set(assert order.billing_address+def test_checkout_complete_with_digital_saving_addresses_off(+ api_client,+ checkout_with_digital_item,+ address,+ address_usa,+ transaction_events_generator,+ transaction_item_generator,+ customer_user,+):+ # given+ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()++ checkout = prepare_checkout_for_test(+ checkout_with_digital_item,+ address,+ address_usa,+ None,+ transaction_item_generator,+ transaction_events_generator,+ user=customer_user,+ save_billing_address=False,+ save_shipping_address=False,+ )++ variables = {+ "id": to_global_id_or_none(checkout),+ "redirectUrl": "https://www.example.com",+ }++ # when+ response = api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)++ # then+ content = get_graphql_content(response)["data"]["checkoutComplete"]+ assert not content["errors"]++ order = Order.objects.first()+ # Ensure the order was actually created+ assert order, "The order should have been created"++ assert order.shipping_address+ assert order.billing_address+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None++ assert customer_user.addresses.count() == user_address_count++def test_complete_checkout_for_local_click_and_collect(api_client,checkout_with_item_for_cc,@@ -4542,9 +4623,9 @@ def test_checkout_complete_line_deleted_in_the_meantime(def test_checkout_complete_with_invalid_address(user_api_client,checkout_with_item,- transaction_item_generator,address,shipping_method,+ customer_user,):"""Check if checkout can be completed with invalid address.@@ -4563,8 +4644,12 @@ def test_checkout_complete_with_invalid_address(checkout.shipping_method = shipping_methodcheckout.billing_address = addresscheckout.tax_exemption = True+ checkout.user = customer_usercheckout.save()+ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()+channel = checkout.channelchannel.automatically_confirm_all_new_orders = Truechannel.allow_unpaid_orders = True@@ -4598,6 +4683,11 @@ def test_checkout_complete_with_invalid_address(assert not data["errors"]assert order.shipping_address.postal_code == invalid_postal_codeassert order.billing_address.postal_code == invalid_postal_code+ assert customer_user.addresses.count() == user_address_count + 1+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None+ assert customer_user.addresses.first().id != order.shipping_address.id+ assert customer_user.addresses.first().id != order.billing_address.id@patch("saleor.checkout.complete_checkout._get_unit_discount_reason")@@ -4862,3 +4952,101 @@ def test_checkout_complete_with_external_shipping_method(order.private_metadata[PRIVATE_META_APP_SHIPPING_ID]== graphql_externa_method_id)+++def test_checkout_complete_saving_addresses_off(+ user_api_client,+ checkout_with_item_and_voucher_specific_products,+ address,+ shipping_method,+ transaction_events_generator,+ transaction_item_generator,+ customer_user,+):+ # given+ checkout = prepare_checkout_for_test(+ checkout_with_item_and_voucher_specific_products,+ address,+ address,+ shipping_method,+ transaction_item_generator,+ transaction_events_generator,+ user=customer_user,+ save_billing_address=False,+ save_shipping_address=False,+ )++ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()++ variables = {+ "id": to_global_id_or_none(checkout),+ "redirectUrl": "https://www.example.com",+ }++ # when+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)++ # then+ content = get_graphql_content(response)+ data = content["data"]["checkoutComplete"]+ assert not data["errors"]++ order = Order.objects.first()+ assert order.billing_address+ assert order.shipping_address+ assert customer_user.addresses.count() == user_address_count+++def test_checkout_complete_saving_addresses_on(+ user_api_client,+ checkout_with_item_and_voucher_specific_products,+ address,+ address_usa,+ shipping_method,+ transaction_events_generator,+ transaction_item_generator,+ customer_user,+):+ # given+ checkout = prepare_checkout_for_test(+ checkout_with_item_and_voucher_specific_products,+ address,+ address_usa,+ shipping_method,+ transaction_item_generator,+ transaction_events_generator,+ user=customer_user,+ save_billing_address=True,+ save_shipping_address=True,+ )++ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()++ variables = {+ "id": to_global_id_or_none(checkout),+ "redirectUrl": "https://www.example.com",+ }++ # when+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)++ # then+ content = get_graphql_content(response)+ data = content["data"]["checkoutComplete"]+ assert not data["errors"]++ order = Order.objects.first()+ assert order.billing_address+ assert order.shipping_address+ assert customer_user.addresses.count() == user_address_count + 2+ # ensure the the customer addresses are not the same instances as the order addresses+ customer_address_ids = list(customer_user.addresses.values_list("pk", flat=True))+ assert not (+ set(customer_address_ids)+ & {order.billing_address.pk, order.shipping_address.pk}+ )++ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is Nonediff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_create.py b/saleor/graphql/checkout/tests/mutations/test_checkout_create.pyindex 58ca2709fc..39be197728 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_create.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_create.py@@ -592,7 +592,10 @@ def test_checkout_create(api_client, stock, graphql_address_data, channel_USD):checkout_line = new_checkout.lines.first()assert checkout_line.variant == variantassert checkout_line.quantity == 1+ assert new_checkout.billing_address is not Noneassert new_checkout.shipping_address is not None+ assert new_checkout.save_shipping_address is True+ assert new_checkout.save_billing_address is Trueassert (new_checkout.shipping_address.first_name == shipping_address_data["firstName"])@@ -2791,3 +2794,119 @@ def test_checkout_create_triggers_webhooks(assert WebhookEventSyncType.CHECKOUT_CALCULATE_TAXES in sync_deliveriestax_delivery = sync_deliveries[WebhookEventSyncType.CHECKOUT_CALCULATE_TAXES]assert tax_delivery.webhook_id == tax_webhook.id+++ ("save_shipping_address", "save_billing_address"),+ [(True, True), (True, False), (False, True), (False, False)],+)+def test_checkout_create_with_save_addresses_setting_provided(+ save_shipping_address,+ save_billing_address,+ api_client,+ stock,+ graphql_address_data,+ channel_USD,+):+ variant = stock.product_variant+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)+ # given input with provided shipping, billing addresses with save settings+ shipping_address_data = graphql_address_data.copy()+ billing_address_data = graphql_address_data.copy()++ variables = {+ "checkoutInput": {+ "channel": channel_USD.slug,+ "lines": [{"quantity": 1, "variantId": variant_id}],+ "shippingAddress": shipping_address_data,+ "billingAddress": billing_address_data,+ "saveShippingAddress": save_shipping_address,+ "saveBillingAddress": save_billing_address,+ }+ }+ assert not Checkout.objects.exists()++ # when checkout create is called with provided variables+ response = api_client.post_graphql(MUTATION_CHECKOUT_CREATE, variables)++ # then the addresses with save settings are set+ content = get_graphql_content(response)["data"]["checkoutCreate"]+ assert not content["errors"]+ new_checkout = Checkout.objects.first()+ assert new_checkout is not None+ checkout_data = content["checkout"]+ assert checkout_data["token"] == str(new_checkout.token)+ assert new_checkout.billing_address is not None+ assert new_checkout.shipping_address is not None+ assert new_checkout.save_billing_address == save_billing_address+ assert new_checkout.save_shipping_address == save_shipping_address+ assert not Reservation.objects.exists()++ assert new_checkout.billing_address.validation_skipped is False+ assert new_checkout.shipping_address.validation_skipped is False++[email protected]("save_shipping_address", [True, False])+def test_checkout_create_no_shipping_address_providing_save_address_raising_error(+ save_shipping_address, api_client, graphql_address_data, channel_USD, stock+):+ variant = stock.product_variant+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)+ # given input with save shipping address and shipping method not provided+ billing_address_data = graphql_address_data.copy()++ variables = {+ "checkoutInput": {+ "channel": channel_USD.slug,+ "lines": [{"quantity": 1, "variantId": variant_id}],+ "billingAddress": billing_address_data,+ "saveShippingAddress": save_shipping_address,+ }+ }+ assert not Checkout.objects.exists()++ # when checkout create is called with provided variables+ response = api_client.post_graphql(MUTATION_CHECKOUT_CREATE, variables)++ # then the error is raised+ data = get_graphql_content(response)["data"]["checkoutCreate"]+ assert not data["checkout"]+ errors = data["errors"]+ assert len(errors) == 1++ error = errors[0]+ assert error["field"] == "saveShippingAddress"+ assert error["code"] == CheckoutErrorCode.MISSING_ADDRESS_DATA.name++[email protected]("save_billing_address", [True, False])+def test_checkout_create_no_billing_address_providing_save_address_raising_error(+ save_billing_address, api_client, graphql_address_data, channel_USD, stock+):+ variant = stock.product_variant+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)+ # given input with save shipping address and shipping method not provided+ shipping_address_data = graphql_address_data.copy()++ variables = {+ "checkoutInput": {+ "channel": channel_USD.slug,+ "lines": [{"quantity": 1, "variantId": variant_id}],+ "shippingAddress": shipping_address_data,+ "saveBillingAddress": save_billing_address,+ }+ }+ assert not Checkout.objects.exists()++ # when checkout create is called with provided variables+ response = api_client.post_graphql(MUTATION_CHECKOUT_CREATE, variables)++ # then the error is raised+ data = get_graphql_content(response)["data"]["checkoutCreate"]+ assert not data["checkout"]+ errors = data["errors"]+ assert len(errors) == 1++ error = errors[0]+ assert error["field"] == "saveBillingAddress"+ assert error["code"] == CheckoutErrorCode.MISSING_ADDRESS_DATA.namediff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.pyindex 6e9dcc0cd6..8b49296c4d 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py@@ -1536,6 +1536,10 @@ def test_checkout_delivery_method_update_from_cc_to_external_shipping():# givencheckout = checkout_with_delivery_method_for_cc+ checkout.save_billing_address = True+ checkout.save_shipping_address = False+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])+settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]response_method_id = "abcd"response_shipping_name = "Provider - Economy"@@ -1574,6 +1578,10 @@ def test_checkout_delivery_method_update_from_cc_to_external_shipping(assert checkout.shipping_method_id is Noneassert checkout.external_shipping_method_id == method_idassert checkout.shipping_method_name == response_shipping_name+ assert checkout.save_billing_address is True+ # should be reset to the default value as the shipping address is cleared+ assert checkout.save_shipping_address is True+mocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -1594,6 +1602,9 @@ def test_checkout_delivery_method_update_from_cc_to_none():# givencheckout = checkout_with_delivery_method_for_cc+ checkout.save_billing_address = True+ checkout.save_shipping_address = False+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])# whenresponse = api_client.post_graphql(@@ -1613,6 +1624,10 @@ def test_checkout_delivery_method_update_from_cc_to_none(assert checkout.shipping_method_id is Noneassert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_name is None+ assert checkout.save_billing_address is True+ # should be reset to the default value as the shipping address is cleared+ assert checkout.save_shipping_address is True+mocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -1634,6 +1649,9 @@ def test_checkout_delivery_method_update_from_cc_to_built_in_shipping():# givencheckout = checkout_with_delivery_method_for_cc+ checkout.save_billing_address = True+ checkout.save_shipping_address = False+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])# whenresponse = api_client.post_graphql(@@ -1659,6 +1677,9 @@ def test_checkout_delivery_method_update_from_cc_to_built_in_shipping(assert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_id == shipping_method.idassert checkout.shipping_method_name == shipping_method.name+ assert checkout.save_billing_address is True+ # should be reset to the default value as the shipping address is cleared+ assert checkout.save_shipping_address is Truemocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -1681,6 +1702,9 @@ def test_checkout_delivery_method_update_from_cc_to_the_same_cc(# givencheckout = checkout_with_delivery_method_for_cccollection_point = checkout.collection_point+ checkout.save_billing_address = True+ checkout.save_shipping_address = True+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])# whenresponse = api_client.post_graphql(@@ -1708,6 +1732,9 @@ def test_checkout_delivery_method_update_from_cc_to_the_same_cc(assert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_id is Noneassert checkout.shipping_method_name is None+ assert checkout.save_billing_address is True+ # the flag remain unchanged as the address stay the same+ assert checkout.save_shipping_address is Truemocked_invalidate_checkout.assert_not_called()mocked_call_checkout_info_event.assert_not_called()@@ -1726,12 +1753,18 @@ def test_checkout_delivery_method_update_from_cc_to_different_cc(mocked_call_checkout_info_event,checkout_with_items,warehouses_for_cc,+ address_usa,api_client,):# given+ warehouses_for_cc[0].address = address_usa+ warehouses_for_cc[0].save(update_fields=["address"])+checkout = checkout_with_itemscheckout.collection_point = warehouses_for_cc[0]- checkout.shipping_address = warehouses_for_cc[0].address.get_copy()+ checkout.shipping_address = address_usa.get_copy()+ checkout.save_billing_address = True+ checkout.save_shipping_address = Truecheckout.save()collection_point = warehouses_for_cc[1]@@ -1762,6 +1795,9 @@ def test_checkout_delivery_method_update_from_cc_to_different_cc(assert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_id is Noneassert checkout.shipping_method_name is None+ assert checkout.save_billing_address is True+ # set the save_shipping_address setting to False for CC+ assert checkout.save_shipping_address is Falsemocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -1780,10 +1816,21 @@ def test_checkout_delivery_method_update_from_external_shipping_to_cc(mocked_call_checkout_info_event,checkout_with_delivery_method_for_external_shipping,warehouses_for_cc,+ address_usa,api_client,):# givencheckout = checkout_with_delivery_method_for_external_shipping+ checkout.save_billing_address = True+ checkout.save_shipping_address = True+ checkout.shipping_address = address_usa+ checkout.save(+ update_fields=[+ "save_billing_address",+ "save_shipping_address",+ "shipping_address",+ ]+ )collection_point = warehouses_for_cc[1]@@ -1813,6 +1860,9 @@ def test_checkout_delivery_method_update_from_external_shipping_to_cc(assert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_id is Noneassert checkout.shipping_method_name is None+ assert checkout.save_billing_address is True+ # set the save_shipping_address setting to False for CC+ assert checkout.save_shipping_address is Falsemocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -1835,6 +1885,9 @@ def test_checkout_delivery_method_update_from_external_shipping_to_built_in_ship):# givencheckout = checkout_with_delivery_method_for_external_shipping+ checkout.save_billing_address = True+ checkout.save_shipping_address = True+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])# whenresponse = api_client.post_graphql(@@ -1860,6 +1913,8 @@ def test_checkout_delivery_method_update_from_external_shipping_to_built_in_shipassert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_id == shipping_method.idassert checkout.shipping_method_name == shipping_method.name+ assert checkout.save_billing_address is True+ assert checkout.save_shipping_address is Truemocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -1885,6 +1940,9 @@ def test_checkout_delivery_method_update_from_external_shipping_to_different_ext):# givencheckout = checkout_with_delivery_method_for_external_shipping+ checkout.save_billing_address = True+ checkout.save_shipping_address = True+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]response_method_id = "new-abcd"@@ -1924,6 +1982,8 @@ def test_checkout_delivery_method_update_from_external_shipping_to_different_extassert checkout.shipping_method_id is Noneassert checkout.external_shipping_method_id == method_idassert checkout.shipping_method_name == response_shipping_name+ assert checkout.save_billing_address is True+ assert checkout.save_shipping_address is Truemocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -1945,6 +2005,9 @@ def test_checkout_delivery_method_update_from_external_shipping_to_none():# givencheckout = checkout_with_delivery_method_for_external_shipping+ checkout.save_billing_address = True+ checkout.save_shipping_address = False+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])# whenresponse = api_client.post_graphql(@@ -1964,6 +2027,9 @@ def test_checkout_delivery_method_update_from_external_shipping_to_none(assert checkout.shipping_method_id is Noneassert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_name is None+ # the flags should not be changed as shipping address is not reset+ assert checkout.save_billing_address is True+ assert checkout.save_shipping_address is Falsemocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -2014,6 +2080,8 @@ def test_checkout_delivery_method_update_from_external_shipping_to_the_same_extecheckout.external_shipping_method_id = method_idcheckout.shipping_method_name = response_shipping_namecheckout.undiscounted_base_shipping_price_amount = Decimal(response_shipping_price)+ checkout.save_billing_address = True+ checkout.save_shipping_address = Truecheckout.save()# when@@ -2035,6 +2103,8 @@ def test_checkout_delivery_method_update_from_external_shipping_to_the_same_exteassert checkout.shipping_method_id is Noneassert checkout.external_shipping_method_id == method_idassert checkout.shipping_method_name == response_shipping_name+ assert checkout.save_billing_address is True+ assert checkout.save_shipping_address is Truemocked_invalidate_checkout.assert_not_called()mocked_call_checkout_info_event.assert_not_called()@@ -2053,10 +2123,21 @@ def test_checkout_delivery_method_update_from_built_in_shipping_to_cc(mocked_call_checkout_info_event,checkout_with_shipping_method,warehouses_for_cc,+ address_usa,api_client,):# givencheckout = checkout_with_shipping_method+ checkout.save_billing_address = True+ checkout.save_shipping_address = True+ checkout.shipping_address = address_usa+ checkout.save(+ update_fields=[+ "save_billing_address",+ "save_shipping_address",+ "shipping_address",+ ]+ )collection_point = warehouses_for_cc[1]@@ -2085,6 +2166,9 @@ def test_checkout_delivery_method_update_from_built_in_shipping_to_cc(assert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_id is Noneassert checkout.shipping_method_name is None+ assert checkout.save_billing_address is True+ # set the save_shipping_address setting to False for CC+ assert checkout.save_shipping_address is Falsemocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -2130,6 +2214,9 @@ def test_checkout_delivery_method_update_from_built_in_shipping_to_external_ship)checkout = checkout_with_shipping_method+ checkout.save_billing_address = True+ checkout.save_shipping_address = True+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])# whenresponse = api_client.post_graphql(@@ -2149,6 +2236,8 @@ def test_checkout_delivery_method_update_from_built_in_shipping_to_external_shipassert checkout.shipping_method_id is Noneassert checkout.external_shipping_method_id == method_idassert checkout.shipping_method_name == response_shipping_name+ assert checkout.save_billing_address is True+ assert checkout.save_shipping_address is Truemocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -2171,6 +2260,9 @@ def test_checkout_delivery_method_update_from_built_in_shipping_to_differnt_buil):# givencheckout = checkout_with_shipping_method+ checkout.save_billing_address = True+ checkout.save_shipping_address = True+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])# whenresponse = api_client.post_graphql(@@ -2195,6 +2287,8 @@ def test_checkout_delivery_method_update_from_built_in_shipping_to_differnt_builassert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_id == other_shipping_method.idassert checkout.shipping_method_name == other_shipping_method.name+ assert checkout.save_billing_address is True+ assert checkout.save_shipping_address is Truemocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()@@ -2216,6 +2310,8 @@ def test_checkout_delivery_method_update_from_built_in_shipping_to_the_same_ship):# givencheckout = checkout_with_shipping_method+ checkout.save_billing_address = True+ checkout.save_shipping_address = Trueshipping_method = checkout.shipping_methodprice = shipping_method.channel_listings.get().pricecheckout.undiscounted_base_shipping_price_amount = price.amount@@ -2244,6 +2340,8 @@ def test_checkout_delivery_method_update_from_built_in_shipping_to_the_same_shipassert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_id == shipping_method.idassert checkout.shipping_method_name == shipping_method.name+ assert checkout.save_billing_address is True+ assert checkout.save_shipping_address is Truemocked_invalidate_checkout.assert_not_called()mocked_call_checkout_info_event.assert_not_called()@@ -2265,6 +2363,9 @@ def test_checkout_delivery_method_update_from_built_in_shipping_to_none():# givencheckout = checkout_with_shipping_method+ checkout.save_billing_address = True+ checkout.save_shipping_address = False+ checkout.save(update_fields=["save_billing_address", "save_shipping_address"])# whenresponse = api_client.post_graphql(@@ -2283,6 +2384,9 @@ def test_checkout_delivery_method_update_from_built_in_shipping_to_none(assert checkout.external_shipping_method_id is Noneassert checkout.shipping_method_id is Noneassert checkout.shipping_method_name is None+ # the flags should not be changed as shipping address is not reset+ assert checkout.save_billing_address is True+ assert checkout.save_shipping_address is Falsemocked_invalidate_checkout.assert_called_once()mocked_call_checkout_info_event.assert_called_once()diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.pyindex a4f69e57f6..3305842c9a 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py@@ -24,17 +24,20 @@ from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncTypefrom ....core.utils import to_global_id_or_nonefrom ....tests.utils import assert_no_permission, get_graphql_contentfrom ...mutations.utils import update_checkout_shipping_method_if_invalid+from ..utils import assert_address_dataMUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE = """mutation checkoutShippingAddressUpdate($id: ID,$shippingAddress: AddressInput!,$validationRules: CheckoutAddressValidationRules+ $saveAddress: Boolean) {checkoutShippingAddressUpdate(id: $id,shippingAddress: $shippingAddress,validationRules: $validationRules+ saveAddress: $saveAddress) {checkout {token@@ -126,27 +129,14 @@ def test_checkout_shipping_address_with_metadata_update(data = content["data"]["checkoutShippingAddressUpdate"]assert not data["errors"]checkout.refresh_from_db()- assert checkout.shipping_address.metadata == {"public": "public_value"}-- assert checkout.shipping_address is not None- assert checkout.shipping_address.first_name == shipping_address["firstName"]- assert checkout.shipping_address.last_name == shipping_address["lastName"]- assert (- checkout.shipping_address.street_address_1 == shipping_address["streetAddress1"]- )- assert (- checkout.shipping_address.street_address_2 == shipping_address["streetAddress2"]- )- assert checkout.shipping_address.postal_code == shipping_address["postalCode"]- assert checkout.shipping_address.country == shipping_address["country"]- assert checkout.shipping_address.city == shipping_address["city"].upper()- assert checkout.shipping_address.validation_skipped is False+ assert_address_data(checkout.shipping_address, shipping_address)manager = get_plugins_manager(allow_replica=False)lines, _ = fetch_checkout_lines(checkout)checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_changeassert mocked_invalidate_checkout.call_count == 1+ assert checkout.save_shipping_address is True@pytest.mark.parametrize(@@ -202,27 +192,14 @@ def test_checkout_shipping_address_when_variant_without_listing(data = content["data"]["checkoutShippingAddressUpdate"]assert not data["errors"]checkout.refresh_from_db()- assert checkout.shipping_address.metadata == {"public": "public_value"}-- assert checkout.shipping_address is not None- assert checkout.shipping_address.first_name == shipping_address["firstName"]- assert checkout.shipping_address.last_name == shipping_address["lastName"]- assert (- checkout.shipping_address.street_address_1 == shipping_address["streetAddress1"]- )- assert (- checkout.shipping_address.street_address_2 == shipping_address["streetAddress2"]- )- assert checkout.shipping_address.postal_code == shipping_address["postalCode"]- assert checkout.shipping_address.country == shipping_address["country"]- assert checkout.shipping_address.city == shipping_address["city"].upper()- assert checkout.shipping_address.validation_skipped is False+ assert_address_data(checkout.shipping_address, shipping_address)manager = get_plugins_manager(allow_replica=False)lines, _ = fetch_checkout_lines(checkout)checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_changeassert mocked_invalidate_checkout.call_count == 1+ assert checkout.save_shipping_address is True@mock.patch(@@ -264,24 +241,14 @@ def test_checkout_shipping_address_update_changes_checkout_country(data = content["data"]["checkoutShippingAddressUpdate"]assert not data["errors"]checkout.refresh_from_db()- assert checkout.shipping_address is not None- assert checkout.shipping_address.first_name == shipping_address["firstName"]- assert checkout.shipping_address.last_name == shipping_address["lastName"]- assert (- checkout.shipping_address.street_address_1 == shipping_address["streetAddress1"]- )- assert (- checkout.shipping_address.street_address_2 == shipping_address["streetAddress2"]- )- assert checkout.shipping_address.postal_code == shipping_address["postalCode"]- assert checkout.shipping_address.country == shipping_address["country"]- assert checkout.shipping_address.city == shipping_address["city"].upper()+ assert_address_data(checkout.shipping_address, shipping_address)manager = get_plugins_manager(allow_replica=False)lines, _ = fetch_checkout_lines(checkout)checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.country == shipping_address["country"]assert checkout.last_change != previous_last_change+ assert checkout.save_shipping_address is True@mock.patch(@@ -1004,6 +971,7 @@ def test_checkout_update_shipping_address_with_digital(# Ensure the address was setcheckout.refresh_from_db(fields=["shipping_address"])assert checkout.shipping_address+ assert_address_data(checkout.shipping_address, graphql_address_data)def test_checkout_shipping_address_update_with_not_applicable_voucher(@@ -1091,6 +1059,7 @@ def test_checkout_shipping_address_update_with_collection_point_already_set(variables = {"id": to_global_id_or_none(checkout),"shippingAddress": shipping_address,+ "saveAddress": False,}response = user_api_client.post_graphql(@@ -1244,3 +1213,113 @@ def test_checkout_shipping_address_update_triggers_webhooks(tax_delivery = tax_delivery_call.args[0]assert tax_delivery.webhook_id == tax_webhook.id+++def test_checkout_shipping_address_update_reset_the_save_address_flag_to_default_value(+ checkout_with_items,+ user_api_client,+ graphql_address_data,+ address,+):+ checkout = checkout_with_items+ # given checkout shipping and billing address set both save shipping flags different+ # than default value - set to False+ checkout.shipping_address = address+ checkout.billing_address = address+ checkout.save_shipping_address = False+ checkout.save_billing_address = False+ checkout.save(+ update_fields=[+ "shipping_address",+ "billing_address",+ "save_shipping_address",+ "save_billing_address",+ ]+ )++ variables = {+ "id": to_global_id_or_none(checkout_with_items),+ "shippingAddress": graphql_address_data,+ }++ # when the checkout shipping address is updated without providing saveAddress flag+ response = user_api_client.post_graphql(+ MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE,+ variables,+ )+ content = get_graphql_content(response)++ # then the checkout shipping address is updated, and `save_shipping_address` is+ # reset to the default True value; the `save_billing_address` is not changed+ data = content["data"]["checkoutShippingAddressUpdate"]+ assert not data["errors"]++ checkout.refresh_from_db()+ assert_address_data(checkout.shipping_address, graphql_address_data)+ assert checkout.save_shipping_address is True+ assert checkout.save_billing_address is False+++def test_checkout_shipping_address_update_with_save_address_to_false(+ checkout_with_items,+ user_api_client,+ graphql_address_data,+):+ # given checkout with default saving address values+ checkout = checkout_with_items++ save_address = False+ variables = {+ "id": to_global_id_or_none(checkout_with_items),+ "shippingAddress": graphql_address_data,+ "saveAddress": save_address,+ }++ # when update shipping address with saveAddress flag set to False+ response = user_api_client.post_graphql(+ MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE,+ variables,+ )+ content = get_graphql_content(response)++ # then the address should be saved and the save_shipping_address should be False+ data = content["data"]["checkoutShippingAddressUpdate"]+ assert not data["errors"]+ checkout.refresh_from_db()+ assert_address_data(checkout.shipping_address, graphql_address_data)+ assert checkout.save_shipping_address is save_address+ assert checkout.save_billing_address is True+++def test_checkout_shipping_address_update_change_save_address_option_to_true(+ checkout_with_items,+ user_api_client,+ graphql_address_data,+):+ # given checkout with save addresses settings to False+ checkout = checkout_with_items+ checkout.save_shipping_address = False+ checkout.save_billing_address = False+ checkout.save(update_fields=["save_shipping_address", "save_billing_address"])++ variables = {+ "id": to_global_id_or_none(checkout_with_items),+ "shippingAddress": graphql_address_data,+ "saveAddress": True,+ }++ # when the shipping address is updated with saveAddress flag set to True+ response = user_api_client.post_graphql(+ MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE,+ variables,+ )+ content = get_graphql_content(response)++ # then the address should be saved and the save_shipping_address should be True+ # the save_billing_address should not be changed+ data = content["data"]["checkoutShippingAddressUpdate"]+ assert not data["errors"]+ checkout.refresh_from_db()+ assert_address_data(checkout.shipping_address, graphql_address_data)+ assert checkout.save_shipping_address is True+ assert checkout.save_billing_address is Falsediff --git a/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py b/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.pyindex 22cbe1aade..d767f426c0 100644--- a/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py+++ b/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py@@ -121,21 +121,27 @@ def test_order_from_checkout(checkout_with_gift_card,gift_card,address,+ address_usa,shipping_method,+ customer_user,):assert not gift_card.last_used_oncheckout = checkout_with_gift_cardcheckout.shipping_address = addresscheckout.shipping_method = shipping_method- checkout.billing_address = address+ checkout.billing_address = address_usacheckout.metadata_storage.store_value_in_metadata(items={"accepted": "true"})checkout.metadata_storage.store_value_in_private_metadata(items={"accepted": "false"})+ checkout.user = customer_usercheckout.save()checkout.metadata_storage.save()+ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()+checkout_line = checkout.lines.first()metadata_key = "md key"@@ -214,6 +220,8 @@ def test_order_from_checkout(gift_card=gift_card, type=GiftCardEvents.USED_IN_ORDER)+ assert customer_user.addresses.count() == user_address_count + 2+order_confirmed_mock.assert_called_once_with(order, webhooks=set())recalculate_with_plugins_mock.assert_not_called()@@ -261,6 +269,60 @@ def test_order_from_checkout_with_transaction(assert not order.original+def test_order_from_checkout_saving_addresses_off(+ app_api_client,+ site_settings,+ checkout_with_item_and_transaction_item,+ permission_handle_checkouts,+ permission_manage_checkouts,+ address,+ shipping_method,+ customer_user,+):+ # given+ checkout = checkout_with_item_and_transaction_item+ checkout.shipping_address = address+ checkout.shipping_method = shipping_method+ checkout.billing_address = address+ checkout.save_shipping_address = False+ checkout.save_billing_address = False+ checkout.user = customer_user+ checkout.save()++ channel = checkout.channel+ channel.automatically_confirm_all_new_orders = True+ channel.save()++ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()++ variables = {+ "id": graphene.Node.to_global_id("Checkout", checkout.pk),+ }++ # when+ response = app_api_client.post_graphql(+ MUTATION_ORDER_CREATE_FROM_CHECKOUT,+ variables,+ permissions=[permission_handle_checkouts, permission_manage_checkouts],+ )++ # then+ content = get_graphql_content(response)+ data = content["data"]["orderCreateFromCheckout"]+ assert not data["errors"]++ order = Order.objects.first()++ assert order.status == OrderStatus.UNFULFILLED+ assert order.origin == OrderOrigin.CHECKOUT+ assert not order.original++ assert order.billing_address+ assert order.shipping_address+ assert customer_user.addresses.count() == user_address_count++@pytest.mark.parametrize(("auto_confirm", "order_status"),[(True, OrderStatus.UNFULFILLED), (False, OrderStatus.UNCONFIRMED)],@@ -1727,6 +1789,7 @@ def test_order_from_checkout_with_digital(permission_handle_checkouts,checkout_with_digital_item,address,+ customer_user,):"""Ensure it is possible to complete a digital checkout without shipping."""@@ -1735,7 +1798,8 @@ def test_order_from_checkout_with_digital(# Set a billing addresscheckout.billing_address = address- checkout.save(update_fields=["billing_address"])+ checkout.user = customer_user+ checkout.save(update_fields=["billing_address", "user"])# Send the creation requestresponse = app_api_client.post_graphql(@@ -1759,16 +1823,17 @@ def test_order_from_checkout_with_digital_and_shipping_address(permission_handle_checkouts,checkout_with_digital_item,address,+ customer_user,):"""Ensure it is possible to complete a digital checkout without shipping."""-checkout = checkout_with_digital_itemvariables = {"id": graphene.Node.to_global_id("Checkout", checkout.pk)}# Set a billing addresscheckout.billing_address = addresscheckout.shipping_address = address- checkout.save(update_fields=["billing_address", "shipping_address"])+ checkout.user = customer_user+ checkout.save(update_fields=["billing_address", "shipping_address", "user"])# Send the creation requestresponse = app_api_client.post_graphql(@@ -1783,9 +1848,62 @@ def test_order_from_checkout_with_digital_and_shipping_address(# Ensure the order was actually createdassert order, "The order should have been created"- # FIXME: fix together with ext-1684- assert not order.shipping_address+ assert order.shipping_address+ assert order.billing_address+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None+++def test_order_from_checkout_with_digital_saving_addresses_off(+ app_api_client,+ permission_handle_checkouts,+ checkout_with_digital_item,+ address,+ customer_user,+):+ # given+ checkout = checkout_with_digital_item+ variables = {"id": graphene.Node.to_global_id("Checkout", checkout.pk)}++ # Set a billing address+ checkout.billing_address = address+ checkout.shipping_address = address+ checkout.user = customer_user+ checkout.save_shipping_address = False+ checkout.save_billing_address = False+ checkout.save(+ update_fields=[+ "billing_address",+ "shipping_address",+ "user",+ "save_shipping_address",+ "save_billing_address",+ ]+ )++ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()++ # when+ response = app_api_client.post_graphql(+ MUTATION_ORDER_CREATE_FROM_CHECKOUT,+ variables,+ permissions=[permission_handle_checkouts],+ )++ # then+ content = get_graphql_content(response)["data"]["orderCreateFromCheckout"]+ assert not content["errors"]++ order = Order.objects.first()+ # Ensure the order was actually created+ assert order, "The order should have been created"++ assert order.shipping_addressassert order.billing_address+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None+ assert customer_user.addresses.count() == user_address_count@pytest.mark.integrationdiff --git a/saleor/graphql/checkout/tests/utils.py b/saleor/graphql/checkout/tests/utils.pynew file mode 100644index 0000000000..e92b15f74c--- /dev/null+++ b/saleor/graphql/checkout/tests/utils.py@@ -0,0 +1,13 @@+def assert_address_data(address, address_data, validation_skipped=False):+ if metadata := address_data.get("metadata"):+ assert address.metadata == {data["key"]: data["value"] for data in metadata}++ assert address is not None+ assert address.first_name == address_data["firstName"]+ assert address.last_name == address_data["lastName"]+ assert address.street_address_1 == address_data["streetAddress1"]+ assert address.street_address_2 == address_data["streetAddress2"]+ assert address.postal_code == address_data["postalCode"]+ assert address.country == address_data["country"]+ assert address.city == address_data["city"].upper()+ assert address.validation_skipped == validation_skippeddiff --git a/saleor/graphql/order/mutations/draft_order_complete.py b/saleor/graphql/order/mutations/draft_order_complete.pyindex 180a553f15..231985678c 100644--- a/saleor/graphql/order/mutations/draft_order_complete.py+++ b/saleor/graphql/order/mutations/draft_order_complete.py@@ -17,7 +17,11 @@ from ....order.calculations import fetch_order_prices_if_expiredfrom ....order.error_codes import OrderErrorCodefrom ....order.fetch import OrderInfo, OrderLineInfofrom ....order.search import prepare_order_search_vector_value-from ....order.utils import get_order_country, update_order_display_gross_prices+from ....order.utils import (+ get_order_country,+ store_user_addresses_from_draft_order,+ update_order_display_gross_prices,+)from ....permission.enums import OrderPermissionsfrom ....warehouse.management import allocate_preorders, allocate_stocksfrom ....warehouse.reservations import is_reservation_enabled@@ -177,6 +181,12 @@ class DraftOrderComplete(BaseMutation):lines_data=order_lines_info,)app = get_app_promise(info.context).get()+ transaction.on_commit(+ lambda: store_user_addresses_from_draft_order(+ order=order,+ manager=manager,+ )+ )transaction.on_commit(lambda: order_created(order_info=order_info,diff --git a/saleor/graphql/order/mutations/draft_order_create.py b/saleor/graphql/order/mutations/draft_order_create.pyindex 6768865255..b092094b68 100644--- a/saleor/graphql/order/mutations/draft_order_create.py+++ b/saleor/graphql/order/mutations/draft_order_create.py@@ -99,6 +99,15 @@ class OrderLineCreateInput(OrderLineInput):class DraftOrderInput(BaseInputObjectType):billing_address = AddressInput(description="Billing address of the customer.")+ save_billing_address = graphene.Boolean(+ description=(+ "Indicates whether the billing address should be saved "+ "to the user’s address book upon draft order completion. "+ "Can only be set when a billing address is provided. If not specified "+ "along with the address, the default behavior is to not save the address."+ )+ + ADDED_IN_321+ )user = graphene.ID(description="Customer associated with the draft order.", name="user")@@ -111,6 +120,15 @@ class DraftOrderInput(BaseInputObjectType):))shipping_address = AddressInput(description="Shipping address of the customer.")+ save_shipping_address = graphene.Boolean(+ description=(+ "Indicates whether the shipping address should be saved "+ "to the user’s address book upon draft order completion."+ "Can only be set when a shipping address is provided. If not specified "+ "along with the address, the default behavior is to not save the address."+ )+ + ADDED_IN_321+ )shipping_method = graphene.ID(description="ID of a selected shipping method.", name="shippingMethod")@@ -439,6 +457,8 @@ class DraftOrderCreate(billing_address,manager,):+ save_shipping_address = cleaned_input.get("save_shipping_address")+ save_billing_address = cleaned_input.get("save_billing_address")if shipping_address:shipping_address = cls.validate_address(shipping_address,@@ -450,6 +470,19 @@ class DraftOrderCreate(shipping_address, "shipping", user=instance)cleaned_input["shipping_address"] = shipping_address+ cleaned_input["draft_save_shipping_address"] = (+ save_shipping_address or False+ )+ elif save_shipping_address is not None:+ raise ValidationError(+ {+ "save_shipping_address": ValidationError(+ "This option can only be selected if a shipping address "+ "is provided.",+ code=OrderErrorCode.MISSING_ADDRESS_DATA.value,+ )+ }+ )if billing_address:billing_address = cls.validate_address(billing_address,@@ -461,6 +494,17 @@ class DraftOrderCreate(billing_address, "billing", user=instance)cleaned_input["billing_address"] = billing_address+ cleaned_input["draft_save_billing_address"] = save_billing_address or False+ elif save_billing_address is not None:+ raise ValidationError(+ {+ "save_billing_address": ValidationError(+ "This option can only be selected if a billing address "+ "is provided.",+ code=OrderErrorCode.MISSING_ADDRESS_DATA.value,+ )+ }+ )@classmethoddef clean_redirect_url(cls, redirect_url):diff --git a/saleor/graphql/order/tests/mutations/test_draft_order_complete.py b/saleor/graphql/order/tests/mutations/test_draft_order_complete.pyindex 4f771bcc37..ea53c95973 100644--- a/saleor/graphql/order/tests/mutations/test_draft_order_complete.py+++ b/saleor/graphql/order/tests/mutations/test_draft_order_complete.py@@ -74,6 +74,9 @@ DRAFT_ORDER_COMPLETE_MUTATION = """"""+@patch(+ "saleor.graphql.order.mutations.draft_order_complete.store_user_addresses_from_draft_order",+)@patch("saleor.graphql.order.mutations.draft_order_complete.order_created",wraps=order_created,@@ -82,6 +85,7 @@ DRAFT_ORDER_COMPLETE_MUTATION = """def test_draft_order_complete(product_variant_out_of_stock_webhook_mock,order_created_mock,+ store_user_addresses_from_draft_order_mock,staff_api_client,permission_group_manage_orders,staff_user,@@ -133,6 +137,7 @@ def test_draft_order_complete(Stock.objects.last())assert order_created_mock.called+ store_user_addresses_from_draft_order_mock.assert_called_once()def test_draft_order_complete_no_automatically_confirm_all_new_orders(@@ -1474,7 +1479,7 @@ def test_draft_order_complete_with_catalogue_and_gift_discount(def test_draft_order_complete_with_invalid_address(staff_api_client,permission_group_manage_orders,- staff_user,+ customer_user,draft_order,address,):@@ -1491,7 +1496,11 @@ def test_draft_order_complete_with_invalid_address(order.shipping_address = address.get_copy()order.billing_address = address.get_copy()- order.save(update_fields=["shipping_address", "billing_address"])+ order.user = customer_user+ order.save(update_fields=["shipping_address", "billing_address", "user"])++ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()order_id = graphene.Node.to_global_id("Order", order.id)variables = {"id": order_id}@@ -1508,6 +1517,65 @@ def test_draft_order_complete_with_invalid_address(assert data["origin"] == OrderOrigin.DRAFT.upper()assert order.shipping_address.postal_code == wrong_postal_codeassert order.billing_address.postal_code == wrong_postal_code+ assert customer_user.addresses.count() == user_address_count+++def test_draft_order_complete_with_invalid_address_save_addresses_on(+ staff_api_client,+ permission_group_manage_orders,+ draft_order,+ address,+ customer_user,+):+ """Check if draft order can be completed with invalid address.++ After introducing `AddressInput.skip_validation`, Saleor may have invalid address+ stored in database.+ """+ # given+ permission_group_manage_orders.user_set.add(staff_api_client.user)+ order = draft_order+ wrong_postal_code = "wrong postal code"+ address.postal_code = wrong_postal_code++ order.shipping_address = address.get_copy()+ order.billing_address = address.get_copy()+ order.draft_save_shipping_address = True+ order.draft_save_billing_address = True+ order.user = customer_user+ order.save(+ update_fields=[+ "shipping_address",+ "billing_address",+ "draft_save_shipping_address",+ "draft_save_billing_address",+ "user",+ ]+ )++ customer_user.addresses.clear()+ user_address_count = customer_user.addresses.count()++ order_id = graphene.Node.to_global_id("Order", order.id)+ variables = {"id": order_id}++ # when+ response = staff_api_client.post_graphql(DRAFT_ORDER_COMPLETE_MUTATION, variables)+ content = get_graphql_content(response)++ # then+ data = content["data"]["draftOrderComplete"]["order"]+ order.refresh_from_db()++ assert data["status"] == order.status.upper()+ assert data["origin"] == OrderOrigin.DRAFT.upper()+ assert order.shipping_address.postal_code == wrong_postal_code+ assert order.billing_address.postal_code == wrong_postal_code+ assert customer_user.addresses.count() == user_address_count + 1+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is None+ assert customer_user.addresses.first().id != order.shipping_address.id+ assert customer_user.addresses.first().id != order.billing_address.id@patch(@@ -1610,3 +1678,119 @@ def test_draft_order_complete_triggers_webhooks()assert wrapped_call_order_event.called+++@patch(+ "saleor.graphql.order.mutations.draft_order_complete.order_created",+)+def test_draft_order_complete_save_user_addresses_in_customer_book(+ order_created_mock,+ staff_api_client,+ permission_group_manage_orders,+ draft_order,+ customer_user,+ address_usa,+):+ # given the order with user set+ # and draft_save_shipping_address and draft_save_billing_address set to True+ order = draft_order+ order.user = customer_user+ order.shipping_address = address_usa+ order.draft_save_shipping_address = True+ order.draft_save_billing_address = True+ order.save(+ update_fields=[+ "user",+ "draft_save_shipping_address",+ "draft_save_billing_address",+ "shipping_address",+ ]+ )++ customer_user.addresses.clear()++ permission_group_manage_orders.user_set.add(staff_api_client.user)++ order_id = graphene.Node.to_global_id("Order", order.id)+ variables = {"id": order_id}++ # when the draft order is completed+ response = staff_api_client.post_graphql(DRAFT_ORDER_COMPLETE_MUTATION, variables)++ # then the addresses are saved in the customer book+ # the flags are cleared+ content = get_graphql_content(response)+ data = content["data"]["draftOrderComplete"]["order"]+ order.refresh_from_db()+ assert data["status"] == order.status.upper()+ assert data["origin"] == OrderOrigin.DRAFT.upper()++ order_created_mock.assert_called_once()++ customer_user.refresh_from_db()+ assert customer_user.addresses.count() == 2+ # ensure that the addresses are not the same instances are addresses assigned to order+ customer_address_ids = set(customer_user.addresses.values_list("id", flat=True))+ order_address_ids = {order.billing_address_id, order.shipping_address_id}+ assert not (customer_address_ids & order_address_ids)++ assert order.draft_save_shipping_address is None+ assert order.draft_save_billing_address is None+++@patch(+ "saleor.graphql.order.mutations.draft_order_complete.order_created",+)+def test_draft_order_complete_do_not_save_user_addresses_in_customer_book(+ order_created_mock,+ staff_api_client,+ permission_group_manage_orders,+ draft_order,+ customer_user,+ address_usa,+):+ # given the order with user set+ # and draft_save_shipping_address and draft_save_billing_address set to False+ order = draft_order+ order.user = customer_user+ order.shipping_address = address_usa+ order.draft_save_shipping_address = False+ order.draft_save_billing_address = False+ order.save(+ update_fields=[+ "user",+ "draft_save_shipping_address",+ "draft_save_billing_address",+ "shipping_address",+ ]+ )++ customer_user.addresses.clear()++ permission_group_manage_orders.user_set.add(staff_api_client.user)++ order_id = graphene.Node.to_global_id("Order", order.id)+ variables = {"id": order_id}++ # when the draft order is completed+ response = staff_api_client.post_graphql(DRAFT_ORDER_COMPLETE_MUTATION, variables)++ # then the addresses are not saved in the customer book+ # the flags are cleared+ content = get_graphql_content(response)+ data = content["data"]["draftOrderComplete"]["order"]+ order.refresh_from_db()+ assert data["status"] == order.status.upper()+ assert data["origin"] == OrderOrigin.DRAFT.upper()++ order_created_mock.assert_called_once()++ customer_user.refresh_from_db()+ assert customer_user.addresses.count() == 0+ # ensure that the addresses are not the same instances are addresses assigned to order+ customer_address_ids = set(customer_user.addresses.values_list("id", flat=True))+ order_address_ids = {order.billing_address_id, order.shipping_address_id}+ assert not (customer_address_ids & order_address_ids)++ assert order.draft_save_shipping_address is None+ assert order.draft_save_billing_address is Nonediff --git a/saleor/graphql/order/tests/mutations/test_draft_order_create.py b/saleor/graphql/order/tests/mutations/test_draft_order_create.pyindex 254acc3433..03e2a38c69 100644--- a/saleor/graphql/order/tests/mutations/test_draft_order_create.py+++ b/saleor/graphql/order/tests/mutations/test_draft_order_create.py@@ -1696,6 +1696,8 @@ def test_draft_order_create_without_sku(assert order.shipping_method == shipping_methodassert order.billing_addressassert order.shipping_address+ assert order.draft_save_billing_address is False+ assert order.draft_save_shipping_address is Falseshipping_total = shipping_method.channel_listings.get(channel_id=order.channel_id).get_total()@@ -3752,3 +3754,168 @@ def test_draft_order_create_with_metadata(assert private_metadata_result_list[0]["key"] == private_metadata_keyassert private_metadata_result_list[0]["value"] == private_metadata_value+++ ("save_shipping_address", "save_billing_address"),+ [(True, True), (True, False), (False, True), (False, False)],+)+def test_draft_order_create_with_save_address_option_provided(+ save_shipping_address,+ save_billing_address,+ staff_api_client,+ permission_group_manage_orders,+ customer_user,+ shipping_method,+ variant,+ channel_USD,+ graphql_address_data,+):+ # given input with provided shipping, billing addresses with save settings+ query = DRAFT_ORDER_CREATE_MUTATION+ permission_group_manage_orders.user_set.add(staff_api_client.user)++ user_id = graphene.Node.to_global_id("User", customer_user.id)+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)+ variant_list = [+ {"variantId": variant_id, "quantity": 2},+ ]+ shipping_address = graphql_address_data+ shipping_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)+ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)++ variables = {+ "input": {+ "user": user_id,+ "lines": variant_list,+ "billingAddress": shipping_address,+ "shippingAddress": shipping_address,+ "saveShippingAddress": save_shipping_address,+ "saveBillingAddress": save_billing_address,+ "shippingMethod": shipping_id,+ "channelId": channel_id,+ }+ }++ # when draft order is created+ response = staff_api_client.post_graphql(query, variables)++ # then the addresses with save settings are set+ content = get_graphql_content(response)+ assert not content["data"]["draftOrderCreate"]["errors"]+ data = content["data"]["draftOrderCreate"]["order"]+ assert data["status"] == OrderStatus.DRAFT.upper()+ assert (+ data["billingAddress"]["streetAddress1"]+ == graphql_address_data["streetAddress1"]+ )+ assert (+ data["shippingAddress"]["streetAddress1"]+ == graphql_address_data["streetAddress1"]+ )++ order = Order.objects.first()+ assert order.user == customer_user+ assert order.shipping_method == shipping_method+ assert order.billing_address+ assert order.shipping_address+ assert order.draft_save_billing_address == save_billing_address+ assert order.draft_save_shipping_address == save_shipping_address++[email protected]("save_shipping_address", [True, False])+def test_draft_order_create_no_shipping_address_provided_save_address_raising_error(+ save_shipping_address,+ staff_api_client,+ permission_group_manage_orders,+ customer_user,+ shipping_method,+ variant,+ channel_USD,+ graphql_address_data,+):+ # given input with save shipping address and shipping method not provided+ query = DRAFT_ORDER_CREATE_MUTATION+ permission_group_manage_orders.user_set.add(staff_api_client.user)++ user_id = graphene.Node.to_global_id("User", customer_user.id)+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)+ variant_list = [+ {"variantId": variant_id, "quantity": 2},+ ]+ billing_address = graphql_address_data+ shipping_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)+ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)++ variables = {+ "input": {+ "user": user_id,+ "lines": variant_list,+ "billingAddress": billing_address,+ "saveShippingAddress": save_shipping_address,+ "shippingMethod": shipping_id,+ "channelId": channel_id,+ }+ }++ # when+ response = staff_api_client.post_graphql(query, variables)++ # then+ content = get_graphql_content(response)+ data = content["data"]["draftOrderCreate"]+ assert not data["order"]+ assert len(data["errors"]) == 1++ error = data["errors"][0]+ assert error["field"] == "saveShippingAddress"+ assert error["code"] == OrderErrorCode.MISSING_ADDRESS_DATA.name++[email protected]("save_billing_address", [True, False])+def test_draft_order_create_no_billing_address_provided_save_address_raising_error(+ save_billing_address,+ staff_api_client,+ permission_group_manage_orders,+ customer_user,+ shipping_method,+ variant,+ channel_USD,+ graphql_address_data,+):+ # given input with save shipping address and shipping method not provided+ query = DRAFT_ORDER_CREATE_MUTATION+ permission_group_manage_orders.user_set.add(staff_api_client.user)++ user_id = graphene.Node.to_global_id("User", customer_user.id)+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)+ variant_list = [+ {"variantId": variant_id, "quantity": 2},+ ]+ shipping_address = graphql_address_data+ shipping_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)+ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)++ variables = {+ "input": {+ "user": user_id,+ "lines": variant_list,+ "shippingAddress": shipping_address,+ "saveBillingAddress": save_billing_address,+ "shippingMethod": shipping_id,+ "channelId": channel_id,+ }+ }++ # when+ response = staff_api_client.post_graphql(query, variables)++ # then+ content = get_graphql_content(response)+ data = content["data"]["draftOrderCreate"]+ assert not data["order"]+ assert len(data["errors"]) == 1++ error = data["errors"][0]+ assert error["field"] == "saveBillingAddress"+ assert error["code"] == OrderErrorCode.MISSING_ADDRESS_DATA.namediff --git a/saleor/graphql/order/tests/mutations/test_draft_order_update.py b/saleor/graphql/order/tests/mutations/test_draft_order_update.pyindex 4108bb40f2..5e930b0fb3 100644--- a/saleor/graphql/order/tests/mutations/test_draft_order_update.py+++ b/saleor/graphql/order/tests/mutations/test_draft_order_update.py@@ -2449,6 +2449,156 @@ def test_draft_order_update_triggers_webhooks_when_tax_webhook_not_needed(assert wrapped_call_order_event.called+def test_draft_order_update_address_reset_save_address_flag_to_default_value(+ staff_api_client,+ permission_group_manage_orders,+ draft_order,+ graphql_address_data,+):+ order = draft_order+ permission_group_manage_orders.user_set.add(staff_api_client.user)++ # given draft order billing and billing address set both save billing flags+ # different than default value - set to True+ order.draft_save_billing_address = True+ order.draft_save_shipping_address = True+ order.save(+ update_fields=["draft_save_billing_address", "draft_save_shipping_address"]+ )++ # when addresses are updated without providing save address flags+ variables = {+ "id": graphene.Node.to_global_id("Order", order.id),+ "input": {+ "shippingAddress": graphql_address_data,+ "billingAddress": graphql_address_data,+ },+ }++ response = staff_api_client.post_graphql(DRAFT_ORDER_UPDATE_MUTATION, variables)++ # then the addresses are set and save address flags are set to default value+ content = get_graphql_content(response)+ data = content["data"]["draftOrderUpdate"]+ assert data["order"]++ order.refresh_from_db()+ assert order.shipping_address+ assert order.billing_address+ assert order.draft_save_billing_address is False+ assert order.draft_save_shipping_address is False+++ ("save_shipping_address", "save_billing_address"),+ [(True, True), (True, False), (False, True), (False, False)],+)+def test_draft_order_update_address_save_addresses_setting_provided(+ save_shipping_address,+ save_billing_address,+ staff_api_client,+ permission_group_manage_orders,+ draft_order,+ graphql_address_data,+):+ # given+ order = draft_order+ permission_group_manage_orders.user_set.add(staff_api_client.user)++ # when addresses are updated with providing save address flags+ variables = {+ "id": graphene.Node.to_global_id("Order", order.id),+ "input": {+ "shippingAddress": graphql_address_data,+ "billingAddress": graphql_address_data,+ "saveShippingAddress": save_shipping_address,+ "saveBillingAddress": save_billing_address,+ },+ }+ response = staff_api_client.post_graphql(DRAFT_ORDER_UPDATE_MUTATION, variables)++ # then the addresses with save settings are set+ content = get_graphql_content(response)+ data = content["data"]["draftOrderUpdate"]+ assert data["order"]++ order.refresh_from_db()+ assert order.shipping_address+ assert order.billing_address+ assert order.draft_save_billing_address == save_billing_address+ assert order.draft_save_shipping_address == save_shipping_address+++ "save_shipping_address",+ [True, False],+)+def test_draft_order_update_no_shipping_address_save_addresses_raising_error(+ save_shipping_address,+ staff_api_client,+ permission_group_manage_orders,+ draft_order,+):+ # given+ order = draft_order+ permission_group_manage_orders.user_set.add(staff_api_client.user)++ # when only save address flag is provided+ variables = {+ "id": graphene.Node.to_global_id("Order", order.id),+ "input": {+ "saveShippingAddress": save_shipping_address,+ },+ }+ response = staff_api_client.post_graphql(DRAFT_ORDER_UPDATE_MUTATION, variables)++ # then the error is raised+ content = get_graphql_content(response)+ data = content["data"]["draftOrderUpdate"]+ assert not data["order"]+ errors = data["errors"]+ assert len(errors) == 1++ error = errors[0]+ assert error["field"] == "saveShippingAddress"+ assert error["code"] == OrderErrorCode.MISSING_ADDRESS_DATA.name+++ "save_billing_address",+ [True, False],+)+def test_draft_order_update_no_billing_address_save_addresses_raising_error(+ save_billing_address,+ staff_api_client,+ permission_group_manage_orders,+ draft_order,+):+ # given+ order = draft_order+ permission_group_manage_orders.user_set.add(staff_api_client.user)++ # when only save address flag is provided+ variables = {+ "id": graphene.Node.to_global_id("Order", order.id),+ "input": {+ "saveBillingAddress": save_billing_address,+ },+ }+ response = staff_api_client.post_graphql(DRAFT_ORDER_UPDATE_MUTATION, variables)++ # then the error is raised+ content = get_graphql_content(response)+ data = content["data"]["draftOrderUpdate"]+ assert not data["order"]+ errors = data["errors"]+ assert len(errors) == 1++ error = errors[0]+ assert error["field"] == "saveBillingAddress"+ assert error["code"] == OrderErrorCode.MISSING_ADDRESS_DATA.name++def test_draft_order_update_with_metadata(app_api_client, permission_manage_orders, draft_order, channel_PLN):diff --git a/saleor/graphql/order/tests/mutations/test_order_update.py b/saleor/graphql/order/tests/mutations/test_order_update.pyindex 76c2aa9a75..cd4110eac0 100644--- a/saleor/graphql/order/tests/mutations/test_order_update.py+++ b/saleor/graphql/order/tests/mutations/test_order_update.py@@ -81,6 +81,8 @@ def test_order_update(assert order.billing_address.last_name == graphql_address_data["lastName"]assert order.shipping_address.validation_skipped is Falseassert order.billing_address.validation_skipped is False+ assert order.draft_save_billing_address is None+ assert order.draft_save_shipping_address is Noneassert order.user_email == emailassert order.user is Noneassert order.status == OrderStatus.UNFULFILLEDdiff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 55d500179f..b7cd08c2de 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -11868,6 +11868,7 @@ enum OrderErrorCode @doc(category: "Orders") {INVALID_VOUCHER_CODENON_EDITABLE_GIFT_LINENON_REMOVABLE_GIFT_LINE+ MISSING_ADDRESS_DATA}enum AddressTypeEnum {@@ -17236,6 +17237,13 @@ type Mutation {"""The checkout's ID."""id: ID+ """+ Indicates whether the billing address should be saved to the user’s address book upon checkout completion. If not provided, the default behavior is to save the address.++ Added in Saleor 3.21.+ """+ saveAddress: Boolean = true+"""Checkout token.@@ -17601,6 +17609,13 @@ type Mutation {"""The checkout's ID."""id: ID+ """+ Indicates whether the shipping address should be saved to the user’s address book upon checkout completion. If not provided, the default behavior is to save the address.++ Added in Saleor 3.21.+ """+ saveAddress: Boolean = true+"""The mailing address to where the checkout will be shipped."""shippingAddress: AddressInput!@@ -23365,6 +23380,13 @@ input DraftOrderCreateInput @doc(category: "Orders") {"""Billing address of the customer."""billingAddress: AddressInput+ """+ Indicates whether the billing address should be saved to the user’s address book upon draft order completion. Can only be set when a billing address is provided. If not specified along with the address, the default behavior is to not save the address.++ Added in Saleor 3.21.+ """+ saveBillingAddress: Boolean+"""Customer associated with the draft order."""user: ID@@ -23381,6 +23403,13 @@ input DraftOrderCreateInput @doc(category: "Orders") {"""Shipping address of the customer."""shippingAddress: AddressInput+ """+ Indicates whether the shipping address should be saved to the user’s address book upon draft order completion.Can only be set when a shipping address is provided. If not specified along with the address, the default behavior is to not save the address.++ Added in Saleor 3.21.+ """+ saveShippingAddress: Boolean+"""ID of a selected shipping method."""shippingMethod: ID@@ -23494,6 +23523,13 @@ input DraftOrderInput @doc(category: "Orders") {"""Billing address of the customer."""billingAddress: AddressInput+ """+ Indicates whether the billing address should be saved to the user’s address book upon draft order completion. Can only be set when a billing address is provided. If not specified along with the address, the default behavior is to not save the address.++ Added in Saleor 3.21.+ """+ saveBillingAddress: Boolean+"""Customer associated with the draft order."""user: ID@@ -23510,6 +23546,13 @@ input DraftOrderInput @doc(category: "Orders") {"""Shipping address of the customer."""shippingAddress: AddressInput+ """+ Indicates whether the shipping address should be saved to the user’s address book upon draft order completion.Can only be set when a shipping address is provided. If not specified along with the address, the default behavior is to not save the address.++ Added in Saleor 3.21.+ """+ saveShippingAddress: Boolean+"""ID of a selected shipping method."""shippingMethod: ID@@ -26840,6 +26883,7 @@ enum CheckoutErrorCode @doc(category: "Checkout") {NON_EDITABLE_GIFT_LINENON_REMOVABLE_GIFT_LINESHIPPING_CHANGE_FORBIDDEN+ MISSING_ADDRESS_DATA}"""@@ -26932,11 +26976,25 @@ input CheckoutCreateInput @doc(category: "Checkout") {"""The customer's email address."""email: String+ """+ Indicates whether the shipping address should be saved to the user’s address book upon checkout completion.Can only be set when a shipping address is provided. If not specified along with the address, the default behavior is to save the address.++ Added in Saleor 3.21.+ """+ saveShippingAddress: Boolean+"""The mailing address to where the checkout will be shipped. Note: the address will be ignored if the checkout doesn't contain shippable items. `skipValidation` requires HANDLE_CHECKOUTS and AUTHENTICATED_APP permissions."""shippingAddress: AddressInput+ """+ Indicates whether the billing address should be saved to the user’s address book upon checkout completion. Can only be set when a billing address is provided. If not specified along with the address, the default behavior is to save the address.++ Added in Saleor 3.21.+ """+ saveBillingAddress: Boolean+"""Billing address of the customer. `skipValidation` requires HANDLE_CHECKOUTS and AUTHENTICATED_APP permissions."""diff --git a/saleor/order/error_codes.py b/saleor/order/error_codes.pyindex f5bb4a73b5..5ec02d5b1d 100644--- a/saleor/order/error_codes.py+++ b/saleor/order/error_codes.py@@ -38,6 +38,7 @@ class OrderErrorCode(Enum):INVALID_VOUCHER_CODE = "invalid_voucher_code"NON_EDITABLE_GIFT_LINE = "non_editable_gift_line"NON_REMOVABLE_GIFT_LINE = "non_removable_gift_line"+ MISSING_ADDRESS_DATA = "missing_address_data"class OrderGrantRefundCreateErrorCode(Enum):diff --git a/saleor/order/migrations/0197_order_draft_save_billing_address_and_more.py b/saleor/order/migrations/0197_order_draft_save_billing_address_and_more.pynew file mode 100644index 0000000000..cf8014ed08--- /dev/null+++ b/saleor/order/migrations/0197_order_draft_save_billing_address_and_more.py@@ -0,0 +1,22 @@+# Generated by Django 4.2.15 on 2025-02-11 10:07++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("order", "0196_merge_20241014_0631"),+ ]++ operations = [+ migrations.AddField(+ model_name="order",+ name="draft_save_billing_address",+ field=models.BooleanField(blank=True, null=True),+ ),+ migrations.AddField(+ model_name="order",+ name="draft_save_shipping_address",+ field=models.BooleanField(blank=True, null=True),+ ),+ ]diff --git a/saleor/order/models.py b/saleor/order/models.pyindex c79c613998..3aad6cc4cc 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -153,6 +153,10 @@ class Order(ModelWithMetadata, ModelWithExternalReference):null=True,on_delete=models.SET_NULL,)+ # The flag is only applicable to draft orders and should be null for orders+ # with a status other than `DRAFT`.+ draft_save_billing_address = models.BooleanField(null=True, blank=True)+ draft_save_shipping_address = models.BooleanField(null=True, blank=True)user_email = models.EmailField(blank=True, default="")original = models.ForeignKey("self", null=True, blank=True, on_delete=models.SET_NULLdiff --git a/saleor/order/tests/test_order_utils.py b/saleor/order/tests/test_order_utils.pyindex 2953f5f740..ddb5225030 100644--- a/saleor/order/tests/test_order_utils.py+++ b/saleor/order/tests/test_order_utils.py@@ -28,6 +28,7 @@ from ..utils import (get_valid_shipping_methods_for_order,match_orders_with_new_user,order_info_for_logs,+ store_user_addresses_from_draft_order,update_order_display_gross_prices,)@@ -744,3 +745,198 @@ def test_order_info_for_logs(order_with_lines, voucher, order_promotion_with_rulassert extra["order_id"] == graphene.Node.to_global_id("Order", order.pk)assert extra["discounts"]assert extra["lines"][0]["discounts"]+++def test_store_user_addresses_from_draft_order(order, customer_user, address_usa):+ # given+ order.status = OrderStatus.DRAFT+ order.user = customer_user+ order.billing_address = address_usa+ order.draft_save_shipping_address = True+ order.draft_save_billing_address = True+ order.save(+ update_fields=[+ "user",+ "draft_save_shipping_address",+ "draft_save_billing_address",+ "billing_address",+ ]+ )++ customer_user.addresses.clear()+ manager = get_plugins_manager(allow_replica=False)++ # when+ store_user_addresses_from_draft_order(order, manager)++ # then+ customer_user.refresh_from_db()+ assert customer_user.addresses.count() == 2+ # ensure that the addresses are not the same instances are addresses assigned to order+ customer_address_ids = set(customer_user.addresses.values_list("id", flat=True))+ order_address_ids = {order.billing_address_id, order.shipping_address_id}+ assert not (customer_address_ids & order_address_ids)++ order.refresh_from_db()+ assert order.draft_save_shipping_address is None+ assert order.draft_save_billing_address is None+++def test_store_user_addresses_from_draft_order_no_user(order):+ # given draft order without user set+ order.user = None+ order.draft_save_shipping_address = True+ order.draft_save_billing_address = True+ order.save(+ update_fields=[+ "user",+ "draft_save_shipping_address",+ "draft_save_billing_address",+ ]+ )++ manager = get_plugins_manager(allow_replica=False)++ # when+ store_user_addresses_from_draft_order(order, manager)++ # then+ order.refresh_from_db()+ assert order.draft_save_shipping_address is None+ assert order.draft_save_billing_address is None+++def test_store_user_addresses_from_draft_order_save_address_options_set_to_false(+ order, customer_user, address_usa+):+ # given+ order.status = OrderStatus.DRAFT+ order.user = customer_user+ order.billing_address = address_usa+ order.draft_save_shipping_address = False+ order.draft_save_billing_address = False+ order.save(+ update_fields=[+ "user",+ "draft_save_shipping_address",+ "draft_save_billing_address",+ "billing_address",+ ]+ )++ customer_user.addresses.clear()+ manager = get_plugins_manager(allow_replica=False)++ # when+ store_user_addresses_from_draft_order(order, manager)++ # then+ customer_user.refresh_from_db()+ assert customer_user.addresses.count() == 0++ order.refresh_from_db()+ assert order.draft_save_shipping_address is None+ assert order.draft_save_billing_address is None+++def test_store_user_addresses_from_draft_order_save_address_options_empty(+ order, customer_user, address_usa+):+ # given+ order.status = OrderStatus.DRAFT+ order.user = customer_user+ order.billing_address = address_usa+ order.draft_save_shipping_address = None+ order.draft_save_billing_address = None+ order.save(+ update_fields=[+ "user",+ "draft_save_shipping_address",+ "draft_save_billing_address",+ "billing_address",+ ]+ )++ customer_user.addresses.clear()+ manager = get_plugins_manager(allow_replica=False)++ # when+ store_user_addresses_from_draft_order(order, manager)++ # then+ customer_user.refresh_from_db()+ assert customer_user.addresses.count() == 0++ order.refresh_from_db()+ assert order.draft_save_shipping_address is None+ assert order.draft_save_billing_address is None+++def test_store_user_addresses_from_draft_order_only_draft_save_shipping_address_true(+ order, customer_user, address_usa+):+ # given+ order.status = OrderStatus.DRAFT+ order.user = customer_user+ order.billing_address = address_usa+ order.draft_save_shipping_address = True+ order.draft_save_billing_address = None+ order.save(+ update_fields=[+ "user",+ "draft_save_shipping_address",+ "draft_save_billing_address",+ "billing_address",+ ]+ )++ customer_user.addresses.clear()+ manager = get_plugins_manager(allow_replica=False)++ # when+ store_user_addresses_from_draft_order(order, manager)++ # then+ customer_user.refresh_from_db()+ assert customer_user.addresses.count() == 1+ # ensure that the addresses are not the same instances are addresses assigned to order+ assert customer_user.addresses.first().id != order.shipping_address_id++ order.refresh_from_db()+ assert order.draft_save_shipping_address is None+ assert order.draft_save_billing_address is None+++def test_store_user_addresses_from_draft_order_only_draft_save_billing_address_true(+ order, customer_user, address_usa+):+ # given+ order.status = OrderStatus.DRAFT+ order.user = customer_user+ order.billing_address = address_usa+ order.draft_save_shipping_address = None+ order.draft_save_billing_address = True+ order.save(+ update_fields=[+ "user",+ "draft_save_shipping_address",+ "draft_save_billing_address",+ "billing_address",+ ]+ )++ customer_user.addresses.clear()+ manager = get_plugins_manager(allow_replica=False)++ # when+ store_user_addresses_from_draft_order(order, manager)++ # then+ customer_user.refresh_from_db()+ assert customer_user.addresses.count() == 1+ # ensure that the addresses are not the same instances are addresses assigned to order+ assert customer_user.addresses.first().id != order.billing_address_id++ order.refresh_from_db()+ assert order.draft_save_shipping_address is None+ assert order.draft_save_billing_address is Nonediff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 6069bce61c..499b1dacf8 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -13,6 +13,8 @@ from django.utils import timezonefrom prices import Money, TaxedMoneyfrom ..account.models import User+from ..account.utils import store_user_address+from ..checkout import AddressTypefrom ..core.prices import quantize_pricefrom ..core.taxes import zero_moneyfrom ..core.tracing import traced_atomic_transaction@@ -1347,3 +1349,31 @@ def clean_order_line_quantities(order_lines, quantities_for_lines):)})+++def store_user_addresses_from_draft_order(order, manager):+ """Save the user's billing and shipping addresses after draft order completion.++ This function stores the billing and shipping addresses in the customer's+ address book if the order has an assigned user and the respective flags+ (`draft_save_billing_address` or `draft_save_shipping_address`) are set to `True`.++ Once the addresses are stored, the flags are reset to `None`, as they are only+ applicable during the draft order stage.+ """+ if order.user:+ if order.draft_save_billing_address is True and order.billing_address:+ store_user_address(+ order.user, order.billing_address, AddressType.BILLING, manager+ )++ if order.draft_save_shipping_address is True and order.shipping_address:+ store_user_address(+ order.user, order.shipping_address, AddressType.SHIPPING, manager+ )++ order.draft_save_billing_address = None+ order.draft_save_shipping_address = None+ order.save(+ update_fields=["draft_save_billing_address", "draft_save_shipping_address"]+ )diff --git a/saleor/tests/e2e/__init__.py b/saleor/tests/e2e/__init__.pyindex 7f4ef2dabe..4d0ee9d4e1 100644--- a/saleor/tests/e2e/__init__.py+++ b/saleor/tests/e2e/__init__.py@@ -10,3 +10,29 @@ DEFAULT_ADDRESS = {"countryArea": "CA","phone": "+12025550163",}++DEFAULT_WAREHOUSE_ADDRESS = {+ "firstName": "Saleor",+ "lastName": "Mirumee",+ "companyName": "Mirumee Software",+ "streetAddress1": "Tęczowa 7",+ "streetAddress2": "",+ "postalCode": "53-601",+ "country": "PL",+ "city": "Wrocław",+ "countryArea": "",+ "phone": "+48321321888",+}++ADDRESS_DE = {+ "firstName": "John",+ "lastName": "Muller",+ "companyName": "Saleor Commerce DE",+ "streetAddress1": "Potsdamer Platz 47",+ "streetAddress2": "",+ "postalCode": "85131",+ "country": "DE",+ "city": "Pollenfeld",+ "phone": "+498421499469",+ "countryArea": "",+}diff --git a/saleor/tests/e2e/account/utils/__init__.py b/saleor/tests/e2e/account/utils/__init__.pyindex 08651738ea..fa5db6ee77 100644--- a/saleor/tests/e2e/account/utils/__init__.py+++ b/saleor/tests/e2e/account/utils/__init__.py@@ -1,3 +1,4 @@+from .account_address_delete import account_address_deletefrom .account_register import account_register, raw_account_registerfrom .create_customer import create_customerfrom .customer_bulk_update import customer_bulk_update@@ -14,6 +15,7 @@ __all__ = ["token_create","raw_token_create","get_own_data",+ "account_address_delete","create_customer","customer_bulk_update","customer_update",diff --git a/saleor/tests/e2e/account/utils/account_address_delete.py b/saleor/tests/e2e/account/utils/account_address_delete.pynew file mode 100644index 0000000000..7693c2f345--- /dev/null+++ b/saleor/tests/e2e/account/utils/account_address_delete.py@@ -0,0 +1,39 @@+from ...utils import get_graphql_content++ACCOUNT_ADDRESS_DELETE_MUTATION = """+ mutation deleteUserAddress($id: ID!) {+ accountAddressDelete(id: $id) {+ address {+ city+ }+ user {+ id+ }+ errors {+ field+ message+ code+ }+ }+ }+"""+++def account_address_delete(api_client, id):+ variables = {"id": id}++ response = api_client.post_graphql(+ ACCOUNT_ADDRESS_DELETE_MUTATION,+ variables=variables,+ )+ content = get_graphql_content(response)++ data = content["data"]["accountAddressDelete"]++ user_id = data["user"]["id"]+ errors = data["errors"]++ assert errors == []+ assert user_id is not None++ return datadiff --git a/saleor/tests/e2e/account/utils/fragments.py b/saleor/tests/e2e/account/utils/fragments.pynew file mode 100644index 0000000000..c97c2ca9e8--- /dev/null+++ b/saleor/tests/e2e/account/utils/fragments.py@@ -0,0 +1,18 @@+ADDRESS_FRAGMENT = """+ fragment Address on Address {+ id+ firstName+ lastName+ companyName+ streetAddress1+ streetAddress2+ city+ cityArea+ postalCode+ countryArea+ phone+ country {+ code+ }+ }+"""diff --git a/saleor/tests/e2e/account/utils/me.py b/saleor/tests/e2e/account/utils/me.pyindex 5e8e4769c3..687561263a 100644--- a/saleor/tests/e2e/account/utils/me.py+++ b/saleor/tests/e2e/account/utils/me.py@@ -1,6 +1,8 @@from ...utils import get_graphql_content+from .fragments import ADDRESS_FRAGMENT-ME_QUERY = """+ME_QUERY = (+ """query Me{me{id@@ -12,9 +14,14 @@ query Me{}}}+ addresses {+ ...Address+ }}}"""+ + ADDRESS_FRAGMENT+)def get_own_data(api_client):diff --git a/saleor/tests/e2e/account/utils/user.py b/saleor/tests/e2e/account/utils/user.pyindex 4f4b8a5662..2219a1f134 100644--- a/saleor/tests/e2e/account/utils/user.py+++ b/saleor/tests/e2e/account/utils/user.py@@ -1,39 +1,52 @@from ...utils import get_graphql_content+from .fragments import ADDRESS_FRAGMENT-USER_QUERY = """-query CustomerDetails($id:ID!){- user(id: $id) {- id- isConfirmed- isActive- orders(first: 10){- edges {- node {- id- number- paymentStatus- created+USER_QUERY = (+ """+ query User($id: ID!) {+ user(id: $id) {+ id+ firstName+ lastName+ isStaff+ isActive+ isConfirmed+ addresses {+ ...Address+ }+ checkoutIds+ orders(first: 10) {+ totalCount+ edges {+ node {+ id+ number+ }+ }+ }+ defaultShippingAddress {+ ...Address+ }+ defaultBillingAddress {+ ...Address+ }}- }}- }-}"""+ + ADDRESS_FRAGMENT+)-def get_user(- staff_api_client,- user_id,-):+def get_user(api_client, user_id):variables = {"id": user_id}- response = staff_api_client.post_graphql(+ response = api_client.post_graphql(USER_QUERY,variables,)content = get_graphql_content(response)-data = content["data"]["user"]+ assert data is not Nonereturn datadiff --git a/saleor/tests/e2e/channel/utils/channel_create.py b/saleor/tests/e2e/channel/utils/channel_create.pyindex 64c19348b4..322a343412 100644--- a/saleor/tests/e2e/channel/utils/channel_create.py+++ b/saleor/tests/e2e/channel/utils/channel_create.py@@ -66,11 +66,19 @@ def create_channel(warehouse_ids = []if slug is None:slug = f"channel_slug_{uuid.uuid4()}"- if order_settings is None:- order_settings = {}if checkout_settings is None:checkout_settings = {}+ order_settings = {+ "markAsPaidStrategy": "PAYMENT_FLOW",+ "automaticallyFulfillNonShippableGiftCard": False,+ "allowUnpaidOrders": False,+ "automaticallyConfirmAllNewOrders": True,+ "expireOrdersAfter": 60,+ "deleteExpiredOrdersAfter": 1,+ **(order_settings or {}),+ }+variables = {"input": {"name": channel_name,@@ -81,12 +89,6 @@ def create_channel("addWarehouses": warehouse_ids,"addShippingZones": shipping_zones,"orderSettings": {- "markAsPaidStrategy": "PAYMENT_FLOW",- "automaticallyFulfillNonShippableGiftCard": False,- "allowUnpaidOrders": False,- "automaticallyConfirmAllNewOrders": True,- "expireOrdersAfter": 60,- "deleteExpiredOrdersAfter": 1,**order_settings,},"checkoutSettings": {@@ -106,7 +108,10 @@ def create_channel(assert data["slug"] == slugassert data["currencyCode"] == currencyassert data["defaultCountry"]["code"] == country- assert data["orderSettings"]["automaticallyConfirmAllNewOrders"] is True+ assert (+ data["orderSettings"]["automaticallyConfirmAllNewOrders"]+ == order_settings["automaticallyConfirmAllNewOrders"]+ )assert data["isActive"] is is_activereturn datadiff --git a/saleor/tests/e2e/checkout/taxes/test_checkout_calculate_simple_taxes_based_on_shipping_country.py b/saleor/tests/e2e/checkout/taxes/test_checkout_calculate_simple_taxes_based_on_shipping_country.pyindex 3ea0654d15..a920a69285 100644--- a/saleor/tests/e2e/checkout/taxes/test_checkout_calculate_simple_taxes_based_on_shipping_country.py+++ b/saleor/tests/e2e/checkout/taxes/test_checkout_calculate_simple_taxes_based_on_shipping_country.py@@ -1,5 +1,6 @@import pytest+from ... import ADDRESS_DEfrom ...product.utils.preparing_product import prepare_productfrom ...shop.utils import prepare_shopfrom ...taxes.utils import update_country_tax_rates@@ -152,18 +153,7 @@ def test_checkout_calculate_simple_tax_based_on_shipping_country_CORE_2001(assert len(checkout_data["shippingMethods"]) == 1# Step 3 - Set billing address for checkout- billing_address = {- "firstName": "John",- "lastName": "Muller",- "companyName": "Saleor Commerce DE",- "streetAddress1": "Potsdamer Platz 47",- "streetAddress2": "",- "postalCode": "85131",- "country": "DE",- "city": "Pollenfeld",- "phone": "+498421499469",- "countryArea": "",- }+ billing_address = ADDRESS_DEcheckout_billing_address_update(e2e_staff_api_client, checkout_id, billing_address)# Step 4 - Get checkout and verify taxesdiff --git a/saleor/tests/e2e/checkout/taxes/test_checkout_with_click_and_collect_calculate_simple_taxes_based_on_shipping_address.py b/saleor/tests/e2e/checkout/taxes/test_checkout_with_click_and_collect_calculate_simple_taxes_based_on_shipping_address.pyindex e64c5f271c..63348a0d88 100644--- a/saleor/tests/e2e/checkout/taxes/test_checkout_with_click_and_collect_calculate_simple_taxes_based_on_shipping_address.py+++ b/saleor/tests/e2e/checkout/taxes/test_checkout_with_click_and_collect_calculate_simple_taxes_based_on_shipping_address.py@@ -1,5 +1,6 @@import pytest+from ... import ADDRESS_DEfrom ...product.utils.preparing_product import prepare_productfrom ...shop.utils import prepare_shopfrom ...taxes.utils import update_country_tax_rates@@ -122,18 +123,7 @@ def test_calculate_simple_taxes_order_with_click_and_collect_with_prices_enteredassert len(checkout_data["shippingMethods"]) == 1# Step 2 - Set billing address for checkout- billing_address = {- "firstName": "John",- "lastName": "Muller",- "companyName": "Saleor Commerce DE",- "streetAddress1": "Potsdamer Platz 47",- "streetAddress2": "",- "postalCode": "85131",- "country": "DE",- "city": "Pollenfeld",- "phone": "+498421499469",- "countryArea": "",- }+ billing_address = ADDRESS_DEcheckout_billing_address_update(e2e_staff_api_client, checkout_id, billing_address)# Step 3 - Get checkout and verify taxes@@ -292,18 +282,7 @@ def test_calculate_simple_taxes_order_with_click_and_collect_with_prices_enteredassert len(checkout_data["shippingMethods"]) == 1# Step 2 - Set billing address for checkout- billing_address = {- "firstName": "John",- "lastName": "Muller",- "companyName": "Saleor Commerce DE",- "streetAddress1": "Potsdamer Platz 47",- "streetAddress2": "",- "postalCode": "85131",- "country": "DE",- "city": "Pollenfeld",- "phone": "+498421499469",- "countryArea": "",- }+ billing_address = ADDRESS_DEcheckout_billing_address_update(e2e_staff_api_client, checkout_id, billing_address)# Step 3 - Get checkout and verify taxesdiff --git a/saleor/tests/e2e/checkout/test_checkout_complete_not_save_cc_address_in_customer_address_book.py b/saleor/tests/e2e/checkout/test_checkout_complete_not_save_cc_address_in_customer_address_book.pynew file mode 100644index 0000000000..d0a680ae19--- /dev/null+++ b/saleor/tests/e2e/checkout/test_checkout_complete_not_save_cc_address_in_customer_address_book.py@@ -0,0 +1,145 @@+import pytest++from .. import ADDRESS_DE+from ..account.utils import get_own_data+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_default_shop+from ..utils import assert_address_data, assign_permissions+from ..warehouse.utils import update_warehouse+from .utils import (+ checkout_complete,+ checkout_create,+ checkout_delivery_method_update,+ checkout_dummy_payment_create,+ raw_checkout_shipping_address_update,+)+++def test_checkout_complete_not_save_cc_address_in_customer_address_book_CORE_0130(+ e2e_staff_api_client,+ e2e_logged_api_client,+ permission_manage_product_types_and_attributes,+ shop_permissions,+):+ # Before+ permissions = [+ permission_manage_product_types_and_attributes,+ *shop_permissions,+ ]++ assign_permissions(e2e_staff_api_client, permissions)++ shop_data = prepare_default_shop(e2e_staff_api_client)+ channel_id = shop_data["channel"]["id"]+ channel_slug = shop_data["channel"]["slug"]+ warehouse_id = shop_data["warehouse"]["id"]+ update_warehouse(+ e2e_staff_api_client,+ warehouse_id,+ is_private=False,+ click_and_collect_option="LOCAL",+ )+ variant_price = 10++ (+ _product_id,+ product_variant_id,+ _product_variant_price,+ ) = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ variant_price,+ )++ # Step 1 - Create checkout.+ lines = [+ {"variantId": product_variant_id, "quantity": 1},+ ]+ billing_address = ADDRESS_DE+ shipping_address = {+ "firstName": "John",+ "lastName": "Muller",+ "companyName": "Saleor Commerce CZ",+ "streetAddress1": "Sluneční 1396",+ "streetAddress2": "",+ "postalCode": "74784",+ "country": "CZ",+ "city": "Melc",+ "phone": "+420722274643",+ "countryArea": "",+ }+ checkout_data = checkout_create(+ e2e_logged_api_client,+ lines,+ channel_slug,+ email=None,+ billing_address=billing_address,+ shipping_address=shipping_address,+ save_billing_address=True,+ save_shipping_address=True,+ )+ checkout_id = checkout_data["id"]++ expected_email = e2e_logged_api_client.user.email+ assert checkout_data["email"] == expected_email+ assert checkout_data["user"]["email"] == expected_email+ assert checkout_data["isShippingRequired"] is True+ checkout_shipping_address = checkout_data["shippingAddress"]++ collection_point = checkout_data["availableCollectionPoints"][0]+ assert collection_point["id"] == warehouse_id+ assert collection_point["isPrivate"] is False+ assert collection_point["clickAndCollectOption"] == "LOCAL"++ # Step 2 - Assign delivery method+ checkout_data = checkout_delivery_method_update(+ e2e_logged_api_client,+ checkout_id,+ collection_point["id"],+ )+ assert checkout_data["deliveryMethod"]["id"] == warehouse_id+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]+ # Ensure the address has been changed+ assert (+ checkout_data["shippingAddress"]["streetAddress1"]+ != checkout_shipping_address["streetAddress1"]+ )++ # Step 3 - Try to change the shipping address and set the save_shipping_address value+ checkout_data = raw_checkout_shipping_address_update(+ e2e_logged_api_client, checkout_id, save_address=True+ )++ assert len(checkout_data["errors"]) == 1+ assert checkout_data["errors"][0]["field"] == "shippingAddress"+ assert checkout_data["errors"][0]["code"] == "SHIPPING_CHANGE_FORBIDDEN"++ # Step 3 - Create dummy payment+ checkout_dummy_payment_create(+ e2e_logged_api_client,+ checkout_id,+ total_gross_amount,+ )++ # Step 4 - Complete the checkout+ order_data = checkout_complete(+ e2e_logged_api_client,+ checkout_id,+ )+ assert order_data["status"] == "UNFULFILLED"+ assert order_data["total"]["gross"]["amount"] == total_gross_amount+ assert order_data["deliveryMethod"]["id"] == warehouse_id+ assert order_data["shippingAddress"]+ assert order_data["billingAddress"]+ assert_address_data(order_data["billingAddress"], billing_address)++ # Step 5 - Verify the user address book+ me = get_own_data(e2e_logged_api_client)++ assert len(me["addresses"]) == 1+ address = me["addresses"][0]+ assert_address_data(address, billing_address)+ assert address["id"] != order_data["billingAddress"]["id"]+ assert address["id"] != order_data["shippingAddress"]["id"]diff --git a/saleor/tests/e2e/checkout/test_checkout_complete_respect_saving_address_settings.py b/saleor/tests/e2e/checkout/test_checkout_complete_respect_saving_address_settings.pynew file mode 100644index 0000000000..9aa570a291--- /dev/null+++ b/saleor/tests/e2e/checkout/test_checkout_complete_respect_saving_address_settings.py@@ -0,0 +1,132 @@+import pytest++from .. import ADDRESS_DE+from ..account.utils import get_own_data+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_default_shop+from ..utils import assert_address_data, assign_permissions+from .utils import (+ checkout_complete,+ checkout_create,+ checkout_delivery_method_update,+ checkout_dummy_payment_create,+)+++def test_respect_saving_address_setting_in_checkout_process_CORE_0132(+ e2e_staff_api_client,+ e2e_logged_api_client,+ shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+):+ # Before+ permissions = [+ *shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ shop_data = prepare_default_shop(e2e_staff_api_client)+ channel_id = shop_data["channel"]["id"]+ channel_slug = shop_data["channel"]["slug"]+ warehouse_id = shop_data["warehouse"]["id"]+ shipping_method_id = shop_data["shipping_method"]["id"]++ product_price = 10+ _product_id, product_variant_id, _product_variant_price = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ product_price,+ )++ # Step 1 - Create checkout.+ # use different address for shipping and billing+ billing_address = ADDRESS_DE+ shipping_address = {+ "firstName": "John",+ "lastName": "Muller",+ "companyName": "Saleor Commerce USA",+ "streetAddress1": "2595 Shinn Street",+ "streetAddress2": "",+ "postalCode": "10281",+ "country": "US",+ "city": "New York",+ "phone": "+19175563216",+ "countryArea": "NY",+ }+ lines = [+ {"variantId": product_variant_id, "quantity": 1},+ ]+ user = e2e_logged_api_client.user+ checkout_data = checkout_create(+ e2e_logged_api_client,+ lines,+ channel_slug,+ billing_address=billing_address,+ shipping_address=shipping_address,+ save_billing_address=False,+ save_shipping_address=True,+ )+ checkout_id = checkout_data["id"]++ assert checkout_data["isShippingRequired"] is True+ assert checkout_data["deliveryMethod"] is None+ assert checkout_data["shippingMethod"] is None+ assert checkout_data["shippingAddress"]+ assert checkout_data["billingAddress"]+ assert (+ checkout_data["shippingAddress"]["streetAddress1"]+ == shipping_address["streetAddress1"]+ )+ assert (+ checkout_data["billingAddress"]["streetAddress1"]+ == billing_address["streetAddress1"]+ )++ # Step 2 - Set shipping address and DeliveryMethod for checkout+ checkout_data = checkout_delivery_method_update(+ e2e_logged_api_client,+ checkout_id,+ shipping_method_id,+ )+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]++ # Step 3 - Create dummy payment+ checkout_dummy_payment_create(+ e2e_logged_api_client,+ checkout_id,+ total_gross_amount,+ )++ # Step 4 - Checkout complete results in the order creation+ order_data = checkout_complete(+ e2e_logged_api_client,+ checkout_id,+ )+ assert order_data["isShippingRequired"] is True+ assert order_data["paymentStatus"] == "FULLY_CHARGED"+ assert order_data["status"] == "UNFULFILLED"+ assert order_data["isPaid"] is True+ order_billing_address = order_data["billingAddress"]+ assert order_billing_address+ order_shipping_address = order_data["shippingAddress"]+ assert order_shipping_address+ assert_address_data(order_shipping_address, shipping_address)+ assert_address_data(order_billing_address, billing_address)+ assert order_data["userEmail"] == user.email++ # Step 5 - Verify the user address book+ user = get_own_data(e2e_logged_api_client)++ assert len(user["addresses"]) == 1+ address = user["addresses"][0]+ assert_address_data(address, shipping_address)+ assert address["id"] != order_billing_address["id"]+ assert address["id"] != order_shipping_address["id"]diff --git a/saleor/tests/e2e/checkout/test_checkout_complete_store_address_in_customer_addresses_after_updating_the_address.py b/saleor/tests/e2e/checkout/test_checkout_complete_store_address_in_customer_addresses_after_updating_the_address.pynew file mode 100644index 0000000000..ccd58f0841--- /dev/null+++ b/saleor/tests/e2e/checkout/test_checkout_complete_store_address_in_customer_addresses_after_updating_the_address.py@@ -0,0 +1,140 @@+import pytest++from .. import ADDRESS_DE, DEFAULT_ADDRESS+from ..account.utils import get_own_data+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_default_shop+from ..utils import assert_address_data, assign_permissions+from .utils import (+ checkout_complete,+ checkout_create,+ checkout_delivery_method_update,+ checkout_dummy_payment_create,+ checkout_shipping_address_update,+)+++def test_updating_the_address_without_the_save_flag_esnures_that_the_address_is_stored_in_customer_addresses_CORE_0131(+ e2e_staff_api_client,+ e2e_logged_api_client,+ shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+):+ # Before+ permissions = [+ *shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ shop_data = prepare_default_shop(e2e_staff_api_client)+ channel_id = shop_data["channel"]["id"]+ channel_slug = shop_data["channel"]["slug"]+ warehouse_id = shop_data["warehouse"]["id"]+ shipping_method_id = shop_data["shipping_method"]["id"]++ product_price = 10+ _product_id, product_variant_id, _product_variant_price = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ product_price,+ )++ # Step 1 - Create checkout.+ # use different address for shipping and billing+ billing_address = ADDRESS_DE+ lines = [+ {"variantId": product_variant_id, "quantity": 1},+ ]+ user = e2e_logged_api_client.user+ checkout_data = checkout_create(+ e2e_logged_api_client,+ lines,+ channel_slug,+ billing_address=billing_address,+ save_billing_address=False,+ save_shipping_address=False,+ )+ checkout_id = checkout_data["id"]++ assert checkout_data["isShippingRequired"] is True+ assert checkout_data["deliveryMethod"] is None+ assert checkout_data["shippingMethod"] is None+ assert checkout_data["shippingAddress"]+ assert checkout_data["billingAddress"]+ assert (+ checkout_data["shippingAddress"]["streetAddress1"]+ == DEFAULT_ADDRESS["streetAddress1"]+ )+ assert (+ checkout_data["billingAddress"]["streetAddress1"]+ == billing_address["streetAddress1"]+ )++ # Step 2 - Update the shipping address, do not provide the save_address flag+ new_shipping_address = {+ "firstName": "John",+ "lastName": "Muller",+ "companyName": "Saleor Commerce USA",+ "streetAddress1": "2595 Shinn Street",+ "streetAddress2": "",+ "postalCode": "10281",+ "country": "US",+ "city": "New York",+ "phone": "+19175563216",+ "countryArea": "NY",+ }++ checkout_data = checkout_shipping_address_update(+ e2e_logged_api_client,+ checkout_id,+ new_shipping_address,+ )++ # Step 3 - Set shipping address and DeliveryMethod for checkout+ checkout_data = checkout_delivery_method_update(+ e2e_logged_api_client,+ checkout_id,+ shipping_method_id,+ )+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]++ # Step 4 - Create dummy payment+ checkout_dummy_payment_create(+ e2e_logged_api_client,+ checkout_id,+ total_gross_amount,+ )++ # Step 5 - Checkout complete results in the order creation+ order_data = checkout_complete(+ e2e_logged_api_client,+ checkout_id,+ )+ assert order_data["isShippingRequired"] is True+ assert order_data["paymentStatus"] == "FULLY_CHARGED"+ assert order_data["status"] == "UNFULFILLED"+ assert order_data["isPaid"] is True+ order_billing_address = order_data["billingAddress"]+ assert order_billing_address+ order_shipping_address = order_data["shippingAddress"]+ assert order_shipping_address+ assert_address_data(order_shipping_address, new_shipping_address)+ assert_address_data(order_billing_address, billing_address)+ assert order_data["userEmail"] == user.email++ # Step 6 - Verify the user address book+ user = get_own_data(e2e_logged_api_client)++ assert len(user["addresses"]) == 1+ address = user["addresses"][0]+ assert_address_data(address, new_shipping_address)+ assert address["id"] != order_billing_address["id"]+ assert address["id"] != order_shipping_address["id"]diff --git a/saleor/tests/e2e/checkout/test_guest_user_can_complete_checkout_without_saving_addresses.py b/saleor/tests/e2e/checkout/test_guest_user_can_complete_checkout_without_saving_addresses.pynew file mode 100644index 0000000000..541927b591--- /dev/null+++ b/saleor/tests/e2e/checkout/test_guest_user_can_complete_checkout_without_saving_addresses.py@@ -0,0 +1,108 @@+import pytest++from .. import ADDRESS_DE+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_default_shop+from ..utils import assert_address_data, assign_permissions+from .utils import (+ checkout_complete,+ checkout_create,+ checkout_delivery_method_update,+ checkout_dummy_payment_create,+)+++def test_guest_user_can_complete_checkout_without_saving_addresses_CORE_0129(+ e2e_staff_api_client,+ e2e_not_logged_api_client,+ permission_manage_product_types_and_attributes,+ shop_permissions,+ permission_manage_orders,+ permission_manage_checkouts,+ permission_manage_users,+):+ # Before+ permissions = [+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_checkouts,+ permission_manage_users,+ *shop_permissions,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ shop_data = prepare_default_shop(e2e_staff_api_client)+ channel_id = shop_data["channel"]["id"]+ channel_slug = shop_data["channel"]["slug"]+ warehouse_id = shop_data["warehouse"]["id"]+ shipping_method_id = shop_data["shipping_method"]["id"]++ variant_price = 10++ (+ _product_id,+ product_variant_id,+ _product_variant_price,+ ) = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ variant_price,+ )++ # Step 1 - Create checkout+ lines = [+ {"variantId": product_variant_id, "quantity": 1},+ ]+ # use different address for shipping and billing+ billing_address = ADDRESS_DE+ email = "[email protected]"+ checkout_data = checkout_create(+ e2e_not_logged_api_client,+ lines,+ channel_slug,+ email=email,+ billing_address=billing_address,+ save_billing_address=True,+ save_shipping_address=True,+ )+ checkout_id = checkout_data["id"]++ assert checkout_data["email"] == email+ assert checkout_data["user"] is None+ assert checkout_data["isShippingRequired"] is True+ checkout_billing_address = checkout_data["billingAddress"]+ checkout_shipping_address = checkout_data["shippingAddress"]++ # Step 2 - Set DeliveryMethod for checkout+ checkout_data = checkout_delivery_method_update(+ e2e_not_logged_api_client,+ checkout_id,+ shipping_method_id,+ )+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]++ # Step 3 - Create payment for checkout+ checkout_dummy_payment_create(+ e2e_not_logged_api_client,+ checkout_id,+ total_gross_amount,+ )++ # Step 4 - Complete checkout.+ order_data = checkout_complete(+ e2e_not_logged_api_client,+ checkout_id,+ )+ assert order_data["isShippingRequired"] is True+ assert order_data["status"] == "UNFULFILLED"+ assert order_data["total"]["gross"]["amount"] == total_gross_amount+ assert order_data["deliveryMethod"]["id"] == shipping_method_id+ assert order_data["shippingAddress"]+ assert order_data["billingAddress"]+ checkout_billing_address["country"] = checkout_billing_address["country"]["code"]+ checkout_shipping_address["country"] = checkout_shipping_address["country"]["code"]+ assert_address_data(order_data["shippingAddress"], checkout_shipping_address)+ assert_address_data(order_data["billingAddress"], checkout_billing_address)diff --git a/saleor/tests/e2e/checkout/utils/__init__.py b/saleor/tests/e2e/checkout/utils/__init__.pyindex ae52b2a190..2ecf2e42bf 100644--- a/saleor/tests/e2e/checkout/utils/__init__.py+++ b/saleor/tests/e2e/checkout/utils/__init__.py@@ -19,7 +19,10 @@ from .checkout_payment_create import (raw_checkout_dummy_payment_create,)from .checkout_remove_promo_code import checkout_remove_promo_code-from .checkout_shipping_address_update import checkout_shipping_address_update+from .checkout_shipping_address_update import (+ checkout_shipping_address_update,+ raw_checkout_shipping_address_update,+)from .query_checkout import get_checkout__all__ = [@@ -32,6 +35,7 @@ __all__ = ["checkout_delivery_method_update","checkout_dummy_payment_create","checkout_shipping_address_update",+ "raw_checkout_shipping_address_update","raw_checkout_dummy_payment_create","checkout_lines_update","draft_order_create",diff --git a/saleor/tests/e2e/checkout/utils/checkout_billing_address_update.py b/saleor/tests/e2e/checkout/utils/checkout_billing_address_update.pyindex b7201dc544..08a607009d 100644--- a/saleor/tests/e2e/checkout/utils/checkout_billing_address_update.py+++ b/saleor/tests/e2e/checkout/utils/checkout_billing_address_update.py@@ -1,5 +1,5 @@from ... import DEFAULT_ADDRESS-from ...utils import get_graphql_content+from ...utils import assert_address_data, get_graphql_contentCHECKOUT_BILLING_ADDRESS_UPDATE_MUTATION = """mutation CheckoutBillingAddressUpdate(@@ -45,14 +45,6 @@ def checkout_billing_address_update(api_client, checkout_id, address=DEFAULT_ADDassert content["data"]["checkoutBillingAddressUpdate"]["errors"] == []data = content["data"]["checkoutBillingAddressUpdate"]["checkout"]- assert data["billingAddress"]["firstName"] == address["firstName"]- assert data["billingAddress"]["lastName"] == address["lastName"]- assert data["billingAddress"]["companyName"] == address["companyName"]- assert data["billingAddress"]["streetAddress1"] == address["streetAddress1"]- assert data["billingAddress"]["postalCode"] == address["postalCode"]- assert data["billingAddress"]["country"]["code"] == address["country"]- assert data["billingAddress"]["city"] == address["city"].upper()- assert data["billingAddress"]["countryArea"] == address["countryArea"]- assert data["billingAddress"]["phone"] == address["phone"]+ assert_address_data(data["billingAddress"], address)return datadiff --git a/saleor/tests/e2e/checkout/utils/checkout_complete.py b/saleor/tests/e2e/checkout/utils/checkout_complete.pyindex cbfceb036d..09b62e12c5 100644--- a/saleor/tests/e2e/checkout/utils/checkout_complete.py+++ b/saleor/tests/e2e/checkout/utils/checkout_complete.py@@ -1,6 +1,8 @@+from ...account.utils.fragments import ADDRESS_FRAGMENTfrom ...utils import get_graphql_content-CHECKOUT_COMPLETE_MUTATION = """+CHECKOUT_COMPLETE_MUTATION = (+ """mutation CheckoutComplete($checkoutId: ID!) {checkoutComplete(id: $checkoutId) {errors {@@ -10,6 +12,7 @@ mutation CheckoutComplete($checkoutId: ID!) {}order {id+ userEmailstatuspaymentStatusisPaid@@ -104,10 +107,18 @@ mutation CheckoutComplete($checkoutId: ID!) {idlast4CodeChars}+ billingAddress {+ ...Address+ }+ shippingAddress {+ ...Address+ }}}}"""+ + ADDRESS_FRAGMENT+)def raw_checkout_complete(api_client, checkout_id):diff --git a/saleor/tests/e2e/checkout/utils/checkout_create.py b/saleor/tests/e2e/checkout/utils/checkout_create.pyindex e5fdeae05f..a9141db7c5 100644--- a/saleor/tests/e2e/checkout/utils/checkout_create.py+++ b/saleor/tests/e2e/checkout/utils/checkout_create.py@@ -1,7 +1,9 @@from ... import DEFAULT_ADDRESS+from ...account.utils.fragments import ADDRESS_FRAGMENTfrom ...utils import get_graphql_content-CHECKOUT_CREATE_MUTATION = """+CHECKOUT_CREATE_MUTATION = (+ """mutation CreateCheckout($input: CheckoutCreateInput!) {checkoutCreate(input: $input) {errors {@@ -47,14 +49,10 @@ mutation CreateCheckout($input: CheckoutCreateInput!) {createdisShippingRequiredbillingAddress {- country {- code- }+ ...Address}shippingAddress {- country {- code- }+ ...Address}shippingMethods {id@@ -117,6 +115,8 @@ mutation CreateCheckout($input: CheckoutCreateInput!) {}}"""+ + ADDRESS_FRAGMENT+)def raw_checkout_create(@@ -126,6 +126,8 @@ def raw_checkout_create(email=None,billing_address=DEFAULT_ADDRESS,shipping_address=DEFAULT_ADDRESS,+ save_billing_address=None,+ save_shipping_address=None,):variables = {"input": {@@ -141,6 +143,12 @@ def raw_checkout_create(if shipping_address:variables["input"]["shippingAddress"] = shipping_address+ if save_billing_address is not None:+ variables["input"]["saveBillingAddress"] = save_billing_address++ if save_shipping_address is not None:+ variables["input"]["saveShippingAddress"] = save_shipping_address+response = api_client.post_graphql(CHECKOUT_CREATE_MUTATION,variables=variables,@@ -159,6 +167,8 @@ def checkout_create(email=None,billing_address=DEFAULT_ADDRESS,shipping_address=DEFAULT_ADDRESS,+ save_billing_address=None,+ save_shipping_address=None,):checkout_response = raw_checkout_create(api_client,@@ -167,6 +177,8 @@ def checkout_create(email,billing_address,shipping_address,+ save_billing_address,+ save_shipping_address,)assert checkout_response["errors"] == []diff --git a/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.py b/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.pyindex 5b7bc0f3b0..9564bbaa7e 100644--- a/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.py+++ b/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.py@@ -1,6 +1,8 @@+from ...account.utils.fragments import ADDRESS_FRAGMENTfrom ...utils import get_graphql_content-CHECKOUT_DELIVERY_METHOD_UPDATE_MUTATION = """+CHECKOUT_DELIVERY_METHOD_UPDATE_MUTATION = (+ """mutation checkoutDeliveryMethodUpdate($checkoutId: ID!, $deliveryMethodId: ID) {checkoutDeliveryMethodUpdate(id: $checkoutId@@ -59,10 +61,15 @@ mutation checkoutDeliveryMethodUpdate($checkoutId: ID!, $deliveryMethodId: ID) {id}}+ shippingAddress {+ ...Address+ }}}}"""+ + ADDRESS_FRAGMENT+)def checkout_delivery_method_update(diff --git a/saleor/tests/e2e/checkout/utils/checkout_shipping_address_update.py b/saleor/tests/e2e/checkout/utils/checkout_shipping_address_update.pyindex c21da7d080..f4bb9a291e 100644--- a/saleor/tests/e2e/checkout/utils/checkout_shipping_address_update.py+++ b/saleor/tests/e2e/checkout/utils/checkout_shipping_address_update.py@@ -1,5 +1,5 @@from ... import DEFAULT_ADDRESS-from ...utils import get_graphql_content+from ...utils import assert_address_data, get_graphql_contentCHECKOUT_SHIPPING_ADDRESS_UPDATE_MUTATION = """mutation CheckoutShippingAddressUpdate(@@ -38,28 +38,34 @@ mutation CheckoutShippingAddressUpdate("""-def checkout_shipping_address_update(api_client, checkout_id, address=DEFAULT_ADDRESS):+def raw_checkout_shipping_address_update(+ api_client, checkout_id, address=DEFAULT_ADDRESS, save_address=None+):variables = {"checkoutId": checkout_id,"shippingAddress": address,}+ if save_address is not None:+ variables["saveAddress"] = save_address+response = api_client.post_graphql(CHECKOUT_SHIPPING_ADDRESS_UPDATE_MUTATION,variables=variables,)content = get_graphql_content(response)+ return content["data"]["checkoutShippingAddressUpdate"]+++def checkout_shipping_address_update(+ api_client, checkout_id, address=DEFAULT_ADDRESS, save_address=None+):+ response = raw_checkout_shipping_address_update(+ api_client, checkout_id, address=address, save_address=None+ )- assert content["data"]["checkoutShippingAddressUpdate"]["errors"] == []+ assert response["errors"] == []- data = content["data"]["checkoutShippingAddressUpdate"]["checkout"]- assert data["shippingAddress"]["firstName"] == address["firstName"]- assert data["shippingAddress"]["lastName"] == address["lastName"]- assert data["shippingAddress"]["companyName"] == address["companyName"]- assert data["shippingAddress"]["streetAddress1"] == address["streetAddress1"]- assert data["shippingAddress"]["postalCode"] == address["postalCode"]- assert data["shippingAddress"]["country"]["code"] == address["country"]- assert data["shippingAddress"]["city"] == address["city"].upper()- assert data["shippingAddress"]["countryArea"] == address["countryArea"]- assert data["shippingAddress"]["phone"] == address["phone"]+ data = response["checkout"]+ assert_address_data(data["shippingAddress"], address)return datadiff --git a/saleor/tests/e2e/orders/taxes/test_order_calculate_simple_taxes_based_on_shipping_address.py b/saleor/tests/e2e/orders/taxes/test_order_calculate_simple_taxes_based_on_shipping_address.pyindex 83079986b2..61843ab1e1 100644--- a/saleor/tests/e2e/orders/taxes/test_order_calculate_simple_taxes_based_on_shipping_address.py+++ b/saleor/tests/e2e/orders/taxes/test_order_calculate_simple_taxes_based_on_shipping_address.py@@ -1,5 +1,6 @@import pytest+from ... import ADDRESS_DEfrom ...product.utils.preparing_product import prepare_productfrom ...shop.utils.preparing_shop import prepare_shopfrom ...taxes.utils import update_country_tax_rates@@ -119,18 +120,7 @@ def test_order_calculate_simple_tax_based_on_shipping_address_CORE_2002(assert order_data["total"]["gross"]["amount"] == product_variant_price# Step 3 - Add shipping and billing addresses- shipping_address = {- "firstName": "John",- "lastName": "Muller",- "companyName": "Saleor Commerce DE",- "streetAddress1": "Potsdamer Platz 47",- "streetAddress2": "",- "postalCode": "85131",- "country": "DE",- "city": "Pollenfeld",- "phone": "+498421499469",- "countryArea": "",- }+ shipping_address = ADDRESS_DEbilling_address = {"firstName": "John","lastName": "Muller",diff --git a/saleor/tests/e2e/orders/taxes/test_order_calculate_simple_taxes_for_digital_product.py b/saleor/tests/e2e/orders/taxes/test_order_calculate_simple_taxes_for_digital_product.pyindex c503538e2a..2390c9d4c6 100644--- a/saleor/tests/e2e/orders/taxes/test_order_calculate_simple_taxes_for_digital_product.py+++ b/saleor/tests/e2e/orders/taxes/test_order_calculate_simple_taxes_for_digital_product.py@@ -1,5 +1,6 @@import pytest+from ... import ADDRESS_DEfrom ...product.utils.preparing_product import prepare_digital_productfrom ...shop.utils.preparing_shop import prepare_shopfrom ...taxes.utils import update_country_tax_rates@@ -77,18 +78,7 @@ def test_digital_order_calculate_simple_tax_based_on_billing_country_CORE_2008()# Step 1 - Create a draft order- billing_address = {- "firstName": "John",- "lastName": "Muller",- "companyName": "Saleor Commerce DE",- "streetAddress1": "Potsdamer Platz 47",- "streetAddress2": "",- "postalCode": "85131",- "country": "DE",- "city": "Pollenfeld",- "phone": "+498421499469",- "countryArea": "",- }+ billing_address = ADDRESS_DEinput = {"channelId": channel_id,"billingAddress": billing_address,diff --git a/saleor/tests/e2e/orders/test_able_to_decide_if_address_is_saved_in_user_address_book.py b/saleor/tests/e2e/orders/test_able_to_decide_if_address_is_saved_in_user_address_book.pynew file mode 100644index 0000000000..82bc5a3d1a--- /dev/null+++ b/saleor/tests/e2e/orders/test_able_to_decide_if_address_is_saved_in_user_address_book.py@@ -0,0 +1,235 @@+import pytest++from .. import ADDRESS_DE, DEFAULT_ADDRESS+from ..account.utils import create_customer, get_user+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_default_shop+from ..utils import assert_address_data, assign_permissions+from .utils import (+ draft_order_complete,+ draft_order_create,+ draft_order_update,+ order_lines_create,+)+++def test_allow_save_shipping_and_not_save_billing_in_user_address_book_CORE_0253(+ e2e_staff_api_client,+ shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+):+ # Before+ permissions = [+ *shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ price = 10++ shop_data = prepare_default_shop(e2e_staff_api_client)+ channel_id = shop_data["channel"]["id"]+ warehouse_id = shop_data["warehouse"]["id"]+ shipping_method_id = shop_data["shipping_method"]["id"]++ (+ _product_id,+ product_variant_id,+ _product_variant_price,+ ) = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ price,+ )++ customer_input = {+ "email": "[email protected]",+ }++ user_data = create_customer(+ e2e_staff_api_client,+ customer_input,+ )+ user_id = user_data["id"]+ user_email = user_data["email"]++ # Step 1 - Create draft order+ # use different address for shipping and billing+ billing_address = ADDRESS_DE++ draft_order_input = {+ "channelId": channel_id,+ "user": user_id,+ "shippingAddress": DEFAULT_ADDRESS,+ "billingAddress": billing_address,+ "saveShippingAddress": True,+ "saveBillingAddress": False,+ }+ data = draft_order_create(+ e2e_staff_api_client,+ draft_order_input,+ )+ order_id = data["order"]["id"]+ assert order_id is not None++ # Step 2 - Add lines to the order+ lines = [{"variantId": product_variant_id, "quantity": 1}]+ order_lines = order_lines_create(+ e2e_staff_api_client,+ order_id,+ lines,+ )+ order_product_variant_id = order_lines["order"]["lines"][0]["variant"]["id"]+ assert order_product_variant_id == product_variant_id++ # Step 3 - Update order's shipping method+ input = {"shippingMethod": shipping_method_id}+ draft_order = draft_order_update(+ e2e_staff_api_client,+ order_id,+ input,+ )+ order_shipping_id = draft_order["order"]["deliveryMethod"]["id"]+ assert order_shipping_id is not None++ # Step 4 - Complete the order+ order = draft_order_complete(e2e_staff_api_client, order_id)+ order_complete_id = order["order"]["id"]+ assert order_complete_id == order_id+ order_line = order["order"]["lines"][0]+ assert order_line["productVariantId"] == product_variant_id+ assert order["order"]["status"] == "UNFULFILLED"+ order_billing_address = order["order"]["billingAddress"]+ order_shipping_address = order["order"]["shippingAddress"]+ assert_address_data(order_billing_address, billing_address)+ assert_address_data(order_shipping_address, DEFAULT_ADDRESS)+ assert order["order"]["user"]["id"] == user_id+ assert order["order"]["userEmail"] == user_email++ # Step 5 - Verify the user address book+ user = get_user(e2e_staff_api_client, user_id)++ assert len(user["addresses"]) == 1+ address = user["addresses"][0]+ order_shipping_address["country"] = order_shipping_address["country"]["code"]+ assert_address_data(address, order_shipping_address)+ assert address["id"] != order_billing_address["id"]+ assert address["id"] != order_shipping_address["id"]+++def test_allow_not_save_shipping_and_save_billing_in_user_address_book_CORE_0254(+ e2e_staff_api_client,+ shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+):+ # Before+ permissions = [+ *shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ price = 10++ shop_data = prepare_default_shop(e2e_staff_api_client)+ channel_id = shop_data["channel"]["id"]+ warehouse_id = shop_data["warehouse"]["id"]+ shipping_method_id = shop_data["shipping_method"]["id"]++ (+ _product_id,+ product_variant_id,+ _product_variant_price,+ ) = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ price,+ )++ customer_input = {+ "email": "[email protected]",+ }++ user_data = create_customer(+ e2e_staff_api_client,+ customer_input,+ )+ user_id = user_data["id"]+ user_email = user_data["email"]++ # Step 1 - Create draft order+ # use different address for shipping and billing+ billing_address = ADDRESS_DE++ draft_order_input = {+ "channelId": channel_id,+ "user": user_id,+ }+ data = draft_order_create(+ e2e_staff_api_client,+ draft_order_input,+ )+ order_id = data["order"]["id"]+ assert order_id is not None++ # Step 2 - Add lines to the order+ lines = [{"variantId": product_variant_id, "quantity": 1}]+ order_lines = order_lines_create(+ e2e_staff_api_client,+ order_id,+ lines,+ )+ order_product_variant_id = order_lines["order"]["lines"][0]["variant"]["id"]+ assert order_product_variant_id == product_variant_id++ # Step 3 - Update order's shipping method and save address settings+ input = {+ "shippingMethod": shipping_method_id,+ "saveShippingAddress": False,+ "saveBillingAddress": True,+ "shippingAddress": DEFAULT_ADDRESS,+ "billingAddress": billing_address,+ }+ draft_order = draft_order_update(+ e2e_staff_api_client,+ order_id,+ input,+ )+ order_shipping_id = draft_order["order"]["deliveryMethod"]["id"]+ assert order_shipping_id is not None++ # Step 4 - Complete the order+ order = draft_order_complete(e2e_staff_api_client, order_id)+ order_complete_id = order["order"]["id"]+ assert order_complete_id == order_id+ order_line = order["order"]["lines"][0]+ assert order_line["productVariantId"] == product_variant_id+ assert order["order"]["status"] == "UNFULFILLED"+ order_billing_address = order["order"]["billingAddress"]+ order_shipping_address = order["order"]["shippingAddress"]+ assert_address_data(order_billing_address, billing_address)+ assert_address_data(order_shipping_address, DEFAULT_ADDRESS)+ assert order["order"]["user"]["id"] == user_id+ assert order["order"]["userEmail"] == user_email++ # Step 5 - Verify the user address book+ user = get_user(e2e_staff_api_client, user_id)++ assert len(user["addresses"]) == 1+ address = user["addresses"][0]+ order_billing_address["country"] = order_billing_address["country"]["code"]+ assert_address_data(address, order_billing_address)+ assert address["id"] != order_billing_address["id"]+ assert address["id"] != order_shipping_address["id"]diff --git a/saleor/tests/e2e/orders/test_changing_order_address_not_update_the_customer_one.py b/saleor/tests/e2e/orders/test_changing_order_address_not_update_the_customer_one.pynew file mode 100644index 0000000000..53cc9f6f0a--- /dev/null+++ b/saleor/tests/e2e/orders/test_changing_order_address_not_update_the_customer_one.py@@ -0,0 +1,161 @@+import pytest++from .. import ADDRESS_DE, DEFAULT_ADDRESS+from ..account.utils import get_own_data, get_user+from ..checkout.utils import (+ checkout_create,+ checkout_delivery_method_update,+ raw_checkout_complete,+)+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_shop+from ..utils import assert_address_data, assign_permissions+from .utils import (+ order_update,+)+++def test_changing_order_address_do_not_influence_customer_address_CORE_0257(+ e2e_staff_api_client,+ e2e_logged_api_client,+ shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+):+ # Before+ permissions = [+ *shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ product_price = 10+ shipping_price = 10+ tax_settings = {+ "charge_taxes": True,+ "tax_calculation_strategy": "FLAT_RATES",+ "display_gross_prices": False,+ "prices_entered_with_tax": True,+ }++ shop_data, _tax_config = prepare_shop(+ e2e_staff_api_client,+ channels=[+ {+ "shipping_zones": [+ {+ "countries": ["US"],+ "shipping_methods": [+ {+ "name": "us shipping zone",+ "add_channels": {+ "price": shipping_price,+ },+ }+ ],+ }+ ],+ "order_settings": {+ "automaticallyConfirmAllNewOrders": False,+ "allowUnpaidOrders": True,+ },+ }+ ],+ tax_settings=tax_settings,+ )+ channel_id = shop_data[0]["id"]+ channel_slug = shop_data[0]["slug"]+ warehouse_id = shop_data[0]["warehouse_id"]+ shipping_method_id = shop_data[0]["shipping_zones"][0]["shipping_methods"][0]["id"]++ _product_id, product_variant_id, _product_variant_price = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ product_price,+ )++ # Step 1 - Create checkout.+ # use different address for shipping and billing+ billing_address = ADDRESS_DE+ lines = [+ {"variantId": product_variant_id, "quantity": 1},+ ]+ user = e2e_logged_api_client.user+ checkout_data = checkout_create(+ e2e_logged_api_client,+ lines,+ channel_slug,+ billing_address=billing_address,+ save_billing_address=True,+ save_shipping_address=False,+ )+ checkout_id = checkout_data["id"]++ assert checkout_data["isShippingRequired"] is True+ assert checkout_data["deliveryMethod"] is None+ assert checkout_data["shippingMethod"] is None+ assert checkout_data["shippingAddress"]+ assert checkout_data["billingAddress"]+ assert_address_data(checkout_data["shippingAddress"], DEFAULT_ADDRESS)+ assert_address_data(checkout_data["billingAddress"], billing_address)++ # Step 2 - Set shipping address and DeliveryMethod for checkout+ checkout_data = checkout_delivery_method_update(+ e2e_logged_api_client,+ checkout_id,+ shipping_method_id,+ )+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id++ # Step 3 - Checkout complete results in the order creation+ data = raw_checkout_complete(+ e2e_logged_api_client,+ checkout_id,+ )+ order_data = data["order"]+ order_id = order_data["id"]+ assert order_data is not None+ assert order_data["id"] is not None+ assert order_data["isShippingRequired"] is True+ assert order_data["paymentStatus"] == "NOT_CHARGED"+ assert order_data["status"] == "UNCONFIRMED"+ assert order_data["isPaid"] is False+ order_billing_address = order_data["billingAddress"]+ assert order_billing_address+ order_shipping_address = order_data["shippingAddress"]+ assert order_shipping_address+ assert order_data["userEmail"] == user.email++ # Step 5 - Verify the user address book+ user = get_own_data(e2e_logged_api_client)++ assert len(user["addresses"]) == 1+ address = user["addresses"][0]+ order_billing_address["country"] = order_billing_address["country"]["code"]+ assert_address_data(address, order_billing_address)+ assert address["id"] != order_billing_address["id"]+ user_id = user["id"]++ # Step 6 - Update order's shipping address+ billing_address["streetAddress1"] = "New street 12"+ updated_order_data = order_update(+ e2e_staff_api_client,+ order_id,+ {"billingAddress": billing_address},+ )++ assert (+ updated_order_data["order"]["billingAddress"]["streetAddress1"]+ == billing_address["streetAddress1"]+ )++ # Step 7 - Verify if the user address stay unchanged+ user = get_user(e2e_staff_api_client, user_id)+ assert len(user["addresses"]) == 1+ address = user["addresses"][0]+ assert_address_data(address, order_billing_address)diff --git a/saleor/tests/e2e/orders/test_order_keep_address_information.py b/saleor/tests/e2e/orders/test_order_keep_address_information.pynew file mode 100644index 0000000000..581fbfeded--- /dev/null+++ b/saleor/tests/e2e/orders/test_order_keep_address_information.py@@ -0,0 +1,131 @@+import pytest++from .. import ADDRESS_DE, DEFAULT_ADDRESS+from ..account.utils import account_address_delete, create_customer, get_user+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_default_shop+from ..utils import assert_address_data, assign_permissions+from .utils import (+ draft_order_complete,+ draft_order_create,+ draft_order_update,+ order_lines_create,+ order_query,+)+++def test_order_keep_address_information_CORE_0256(+ e2e_staff_api_client,+ shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+):+ # Before+ permissions = [+ *shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ price = 10++ shop_data = prepare_default_shop(e2e_staff_api_client)+ channel_id = shop_data["channel"]["id"]+ warehouse_id = shop_data["warehouse"]["id"]+ shipping_method_id = shop_data["shipping_method"]["id"]++ (+ _product_id,+ product_variant_id,+ _product_variant_price,+ ) = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ price,+ )++ customer_input = {+ "email": "[email protected]",+ }++ user_data = create_customer(+ e2e_staff_api_client,+ customer_input,+ )+ user_id = user_data["id"]+ user_email = user_data["email"]++ # Step 1 - Create draft order+ # use different address for shipping and billing+ billing_address = ADDRESS_DE++ draft_order_input = {+ "channelId": channel_id,+ "user": user_id,+ "shippingAddress": DEFAULT_ADDRESS,+ "billingAddress": billing_address,+ "saveShippingAddress": True,+ "saveBillingAddress": True,+ }+ data = draft_order_create(+ e2e_staff_api_client,+ draft_order_input,+ )+ order_id = data["order"]["id"]+ assert order_id is not None++ # Step 2 - Add lines to the order+ lines = [{"variantId": product_variant_id, "quantity": 1}]+ order_lines = order_lines_create(+ e2e_staff_api_client,+ order_id,+ lines,+ )+ order_product_variant_id = order_lines["order"]["lines"][0]["variant"]["id"]+ assert order_product_variant_id == product_variant_id++ # Step 3 - Update order's shipping method+ input = {"shippingMethod": shipping_method_id}+ draft_order = draft_order_update(+ e2e_staff_api_client,+ order_id,+ input,+ )+ order_shipping_id = draft_order["order"]["deliveryMethod"]["id"]+ assert order_shipping_id is not None++ # Step 4 - Complete the order+ order = draft_order_complete(e2e_staff_api_client, order_id)+ order_complete_id = order["order"]["id"]+ assert order_complete_id == order_id+ order_line = order["order"]["lines"][0]+ assert order_line["productVariantId"] == product_variant_id+ assert order["order"]["status"] == "UNFULFILLED"+ order_billing_address = order["order"]["billingAddress"]+ order_shipping_address = order["order"]["shippingAddress"]+ assert_address_data(order_billing_address, billing_address)+ assert_address_data(order_shipping_address, DEFAULT_ADDRESS)+ assert order["order"]["user"]["id"] == user_id+ assert order["order"]["userEmail"] == user_email++ # Step 5 - Verify the user address book+ user = get_user(e2e_staff_api_client, user_id)++ assert len(user["addresses"]) == 2+ address = user["addresses"][0]+ address_id = address["id"]++ # Step 6 - Remove user address+ account_address_delete(e2e_staff_api_client, address_id)++ # Step 7 - Ensure the order still has the address information+ order_data = order_query(e2e_staff_api_client, order_id)+ assert order_data["shippingAddress"]+ assert order_data["billingAddress"]+ assert_address_data(order_data["shippingAddress"], DEFAULT_ADDRESS)+ assert_address_data(order_data["billingAddress"], billing_address)diff --git a/saleor/tests/e2e/orders/test_unable_to_update_save_settings_after_order_completion.py b/saleor/tests/e2e/orders/test_unable_to_update_save_settings_after_order_completion.pynew file mode 100644index 0000000000..e5fd897531--- /dev/null+++ b/saleor/tests/e2e/orders/test_unable_to_update_save_settings_after_order_completion.py@@ -0,0 +1,128 @@+import pytest++from .. import ADDRESS_DE, DEFAULT_ADDRESS+from ..account.utils import create_customer+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_default_shop+from ..utils import assert_address_data, assign_permissions+from .utils import (+ draft_order_complete,+ draft_order_create,+ draft_order_update,+ order_lines_create,+ raw_draft_order_update,+)+++def test_unable_to_update_save_settings_after_order_complete_CORE_0255(+ e2e_staff_api_client,+ shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+):+ # Before+ permissions = [+ *shop_permissions,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ permission_manage_users,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ price = 10++ shop_data = prepare_default_shop(e2e_staff_api_client)+ channel_id = shop_data["channel"]["id"]+ warehouse_id = shop_data["warehouse"]["id"]+ shipping_method_id = shop_data["shipping_method"]["id"]++ (+ _product_id,+ product_variant_id,+ _product_variant_price,+ ) = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ price,+ )++ customer_input = {+ "email": "[email protected]",+ }++ user_data = create_customer(+ e2e_staff_api_client,+ customer_input,+ )+ user_id = user_data["id"]+ user_email = user_data["email"]++ # Step 1 - Create draft order+ # use different address for shipping and billing+ billing_address = ADDRESS_DE++ draft_order_input = {+ "channelId": channel_id,+ "user": user_id,+ "shippingAddress": DEFAULT_ADDRESS,+ "billingAddress": billing_address,+ "saveShippingAddress": True,+ "saveBillingAddress": False,+ }+ data = draft_order_create(+ e2e_staff_api_client,+ draft_order_input,+ )+ order_id = data["order"]["id"]+ assert order_id is not None++ # Step 2 - Add lines to the order+ lines = [{"variantId": product_variant_id, "quantity": 1}]+ order_lines = order_lines_create(+ e2e_staff_api_client,+ order_id,+ lines,+ )+ order_product_variant_id = order_lines["order"]["lines"][0]["variant"]["id"]+ assert order_product_variant_id == product_variant_id++ # Step 3 - Update order's shipping method+ input = {"shippingMethod": shipping_method_id}+ draft_order = draft_order_update(+ e2e_staff_api_client,+ order_id,+ input,+ )+ order_shipping_id = draft_order["order"]["deliveryMethod"]["id"]+ assert order_shipping_id is not None++ # Step 4 - Complete the order+ order = draft_order_complete(e2e_staff_api_client, order_id)+ order_complete_id = order["order"]["id"]+ assert order_complete_id == order_id+ order_line = order["order"]["lines"][0]+ assert order_line["productVariantId"] == product_variant_id+ assert order["order"]["status"] == "UNFULFILLED"+ order_billing_address = order["order"]["billingAddress"]+ order_shipping_address = order["order"]["shippingAddress"]+ assert_address_data(order_billing_address, billing_address)+ assert_address_data(order_shipping_address, DEFAULT_ADDRESS)+ assert order["order"]["user"]["id"] == user_id+ assert order["order"]["userEmail"] == user_email++ # Step 5 - Try to update order's save settings+ input = {+ "billingAddress": billing_address,+ "shippingAddress": DEFAULT_ADDRESS,+ "saveShippingAddress": True,+ "saveBillingAddress": True,+ }+ response = raw_draft_order_update(e2e_staff_api_client, order_id, input)+ errors = response["errors"]+ assert len(errors) == 1+ error = errors[0]+ assert error["field"] == "id"+ assert error["code"] == "INVALID"diff --git a/saleor/tests/e2e/orders/utils/__init__.py b/saleor/tests/e2e/orders/utils/__init__.pyindex 73e8832a77..c637dc63de 100644--- a/saleor/tests/e2e/orders/utils/__init__.py+++ b/saleor/tests/e2e/orders/utils/__init__.py@@ -2,7 +2,7 @@ from .draft_order_bulk_delete import draft_order_bulk_deletefrom .draft_order_complete import draft_order_complete, raw_draft_order_completefrom .draft_order_create import draft_order_createfrom .draft_order_delete import draft_order_delete-from .draft_order_update import draft_order_update+from .draft_order_update import draft_order_update, raw_draft_order_updatefrom .order_by_checkout_id_query import order_by_checkout_id_queryfrom .order_cancel import order_cancelfrom .order_create_from_checkout import (@@ -20,6 +20,7 @@ from .order_line_update import order_line_updatefrom .order_lines_create import order_lines_createfrom .order_mark_as_paid import mark_order_paidfrom .order_query import order_query+from .order_update import order_updatefrom .order_update_shipping import order_update_shippingfrom .order_void import order_void, raw_order_void@@ -48,4 +49,6 @@ __all__ = ["order_line_delete","order_line_discount_update","raw_order_create_from_checkout",+ "raw_draft_order_update",+ "order_update",]diff --git a/saleor/tests/e2e/orders/utils/draft_order_complete.py b/saleor/tests/e2e/orders/utils/draft_order_complete.pyindex 62969df46d..8217b751b5 100644--- a/saleor/tests/e2e/orders/utils/draft_order_complete.py+++ b/saleor/tests/e2e/orders/utils/draft_order_complete.py@@ -1,6 +1,8 @@-from saleor.graphql.tests.utils import get_graphql_content+from ...account.utils.fragments import ADDRESS_FRAGMENT+from ...utils import get_graphql_content-DRAFT_ORDER_COMPLETE_MUTATION = """+DRAFT_ORDER_COMPLETE_MUTATION = (+ """mutation DraftOrderComplete($id: ID!) {draftOrderComplete(id: $id) {errors {@@ -14,6 +16,13 @@ mutation DraftOrderComplete($id: ID!) {id}+ userEmail+ billingAddress {+ ...Address+ }+ shippingAddress {+ ...Address+ }undiscountedTotal {...BaseTaxedMoney}@@ -96,6 +105,8 @@ fragment BaseTaxedMoney on TaxedMoney {currency}"""+ + ADDRESS_FRAGMENT+)def raw_draft_order_complete(api_client, id):diff --git a/saleor/tests/e2e/orders/utils/draft_order_update.py b/saleor/tests/e2e/orders/utils/draft_order_update.pyindex 3143426b8e..b719cde4dd 100644--- a/saleor/tests/e2e/orders/utils/draft_order_update.py+++ b/saleor/tests/e2e/orders/utils/draft_order_update.py@@ -129,6 +129,20 @@ fragment BaseTaxedMoney on TaxedMoney {"""+def raw_draft_order_update(api_client, id, input):+ variables = {"id": id, "input": input}++ response = api_client.post_graphql(+ DRAFT_ORDER_UPDATE_MUTATION,+ variables=variables,+ )+ content = get_graphql_content(response)++ data = content["data"]["draftOrderUpdate"]++ return data++def draft_order_update(api_client,id,diff --git a/saleor/tests/e2e/orders/utils/order_query.py b/saleor/tests/e2e/orders/utils/order_query.pyindex 437967ac48..95c9226258 100644--- a/saleor/tests/e2e/orders/utils/order_query.py+++ b/saleor/tests/e2e/orders/utils/order_query.py@@ -1,6 +1,8 @@-from saleor.graphql.tests.utils import get_graphql_content+from ...account.utils.fragments import ADDRESS_FRAGMENT+from ...utils import get_graphql_content-ORDER_QUERY = """+ORDER_QUERY = (+ """query OrderDetails($id: ID!) {order(id: $id) {availableShippingMethods {@@ -39,17 +41,10 @@ query OrderDetails($id: ID!) {id}shippingAddress {- country {- code- }- countryArea- firstName- cityArea- city- phone- postalCode- streetAddress1- streetAddress2+ ...Address+ }+ billingAddress {+ ...Address}statusDisplaystatus@@ -67,6 +62,8 @@ query OrderDetails($id: ID!) {}}"""+ + ADDRESS_FRAGMENT+)def order_query(diff --git a/saleor/tests/e2e/orders/utils/order_update.py b/saleor/tests/e2e/orders/utils/order_update.pynew file mode 100644index 0000000000..8a3b62c737--- /dev/null+++ b/saleor/tests/e2e/orders/utils/order_update.py@@ -0,0 +1,61 @@+from ...account.utils.fragments import ADDRESS_FRAGMENT+from ...utils import get_graphql_content++ORDER_UPDATE_MUTATION = (+ """+ mutation orderUpdate(+ $id: ID+ $externalReference: String+ $input: OrderUpdateInput!+ ) {+ orderUpdate(+ id: $id+ externalReference: $externalReference+ input: $input+ ) {+ errors {+ field+ message+ code+ }+ order {+ id+ externalReference+ shippingAddress {+ ...Address+ }+ billingAddress {+ ...Address+ }+ }+ }+ }+"""+ + ADDRESS_FRAGMENT+)+++def raw_order_update(api_client, id, input):+ variables = {"id": id, "input": input}++ response = api_client.post_graphql(+ ORDER_UPDATE_MUTATION,+ variables=variables,+ )+ content = get_graphql_content(response)++ data = content["data"]["orderUpdate"]++ return data+++def order_update(api_client, id, input):+ response = raw_order_update(api_client, id, input)++ assert response["order"] is not None++ errors = response["errors"]++ assert errors == []++ return responsediff --git a/saleor/tests/e2e/utils.py b/saleor/tests/e2e/utils.pyindex e877359aaa..384efa93ba 100644--- a/saleor/tests/e2e/utils.py+++ b/saleor/tests/e2e/utils.py@@ -40,3 +40,15 @@ def request_matcher(r1, r2):return Falsereturn True+++def assert_address_data(address_data, address):+ assert address_data["firstName"] == address["firstName"]+ assert address_data["lastName"] == address["lastName"]+ assert address_data["companyName"] == address["companyName"]+ assert address_data["streetAddress1"] == address["streetAddress1"]+ assert address_data["postalCode"] == address["postalCode"]+ assert address_data["country"]["code"] == address["country"]+ assert address_data["city"] == address["city"].upper()+ assert address_data["countryArea"] == address["countryArea"]+ assert address_data["phone"] == address["phone"]