Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move saving address to a helper
Artur Smętf8cb4d7d499a
diff --git a/saleor/checkout/core.py b/saleor/checkout/core.pyindex 51b4a0fe66..191225f0fd 100644--- a/saleor/checkout/core.py+++ b/saleor/checkout/core.py@@ -12,7 +12,8 @@ from ..core import analyticsfrom ..discount.models import Voucher, NotApplicablefrom ..order.models import Orderfrom ..shipping.models import ShippingMethodCountry, ANY_COUNTRY-from ..userprofile.models import Address, User+from ..userprofile.models import Address+from ..userprofile.utils import store_user_addressSTORAGE_SESSION_KEY = 'checkout_storage'@@ -195,9 +196,8 @@ class Checkout(object):def _add_to_user_address_book(self, address, is_billing=False,is_shipping=False):if self.user.is_authenticated():- User.objects.store_address(- self.user, address, shipping=is_shipping,- billing=is_billing)+ store_user_address(self.user, address, shipping=is_shipping,+ billing=is_billing)def _get_address_copy(self, address):address.user = Nonediff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.pyindex e9acbcd6c7..0adef2b9cc 100644--- a/saleor/userprofile/models.py+++ b/saleor/userprofile/models.py@@ -103,19 +103,6 @@ class UserManager(BaseUserManager):return self.create_user(email, password, is_staff=True,is_superuser=True, **extra_fields)- def store_address(self, user, address, billing=False, shipping=False):- entry = Address.objects.store_address(user, address)- changed = False- if billing and not user.default_billing_address_id:- user.default_billing_address = entry- changed = True- if shipping and not user.default_shipping_address_id:- user.default_shipping_address = entry- changed = True- if changed:- user.save()- return entry-class User(PermissionsMixin, AbstractBaseUser, index.Indexed):email = models.EmailField(unique=True)diff --git a/saleor/userprofile/utils.py b/saleor/userprofile/utils.pynew file mode 100644index 0000000000..1048fa42cc--- /dev/null+++ b/saleor/userprofile/utils.py@@ -0,0 +1,16 @@+from .models import Address+++def store_user_address(user, address, billing=False, shipping=False):+ data = Address.objects.as_data(address)+ entry = user.addresses.get_or_create(**data)[0]+ changed = False+ if billing and not user.default_billing_address_id:+ user.default_billing_address = entry+ changed = True+ if shipping and not user.default_shipping_address_id:+ user.default_shipping_address = entry+ changed = True+ if changed:+ user.save()+ return entry