Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move InsufficientStock exception to separate file
Anna Siwik060db8ee28b5
diff --git a/saleor/cart/forms.py b/saleor/cart/forms.pyindex de945402d9..48146e074e 100644--- a/saleor/cart/forms.py+++ b/saleor/cart/forms.py@@ -4,8 +4,8 @@ from django.conf import settingsfrom django.core.exceptions import NON_FIELD_ERRORS, ObjectDoesNotExistfrom django.utils.translation import npgettext_lazy, pgettext_lazyfrom django_countries.fields import LazyTypedChoiceField, countries-from satchless.item import InsufficientStock+from ..core.exceptions import InsufficientStockfrom ..shipping.utils import get_shipment_optionsdiff --git a/saleor/cart/utils.py b/saleor/cart/utils.pyindex 98e9bdbfcd..00db83dea1 100644--- a/saleor/cart/utils.py+++ b/saleor/cart/utils.py@@ -8,9 +8,9 @@ from django.db import transactionfrom django.utils.timezone import nowfrom django.utils.translation import pgettext_lazyfrom prices import PriceRange-from satchless.item import InsufficientStockfrom . import CartStatus+from ..core.exceptions import InsufficientStockfrom ..core.utils import to_local_currencyfrom .models import Cartdiff --git a/saleor/checkout/views/summary.py b/saleor/checkout/views/summary.pyindex 36c0c34670..c8790b3eba 100644--- a/saleor/checkout/views/summary.py+++ b/saleor/checkout/views/summary.py@@ -2,8 +2,8 @@ from django.contrib import messagesfrom django.shortcuts import redirectfrom django.template.response import TemplateResponsefrom django.utils.translation import pgettext, pgettext_lazy-from satchless.item import InsufficientStock+from ...core.exceptions import InsufficientStockfrom ...account.forms import get_address_formfrom ...account.models import Addressfrom ..forms import (diff --git a/saleor/core/exceptions.py b/saleor/core/exceptions.pynew file mode 100644index 0000000000..5282685f94--- /dev/null+++ b/saleor/core/exceptions.py@@ -0,0 +1,5 @@+class InsufficientStock(Exception):++ def __init__(self, item):+ super().__init__('Insufficient stock for %r' % (item,))+ self.item = itemdiff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex f92026e850..56afdfa234 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -5,9 +5,9 @@ from django.urls import reverse, reverse_lazyfrom django.utils.translation import npgettext_lazy, pgettext_lazyfrom django_prices.forms import PriceFieldfrom payments import PaymentError, PaymentStatus-from satchless.item import InsufficientStockfrom ...cart.forms import QuantityField+from ...core.exceptions import InsufficientStockfrom ...core.utils import build_absolute_urifrom ...discount.utils import decrease_voucher_usagefrom ...order import GroupStatusdiff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex b7fca98536..06a0b2b9db 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -10,8 +10,8 @@ from django.utils.translation import pgettext_lazyfrom django_prices.templatetags.prices_i18n import grossfrom payments import PaymentStatusfrom prices import Price-from satchless.item import InsufficientStock+from ...core.exceptions import InsufficientStockfrom ...core.utils import get_paginator_itemsfrom ...order import GroupStatusfrom ...order.models import DeliveryGroup, Order, OrderLine, OrderNotediff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 006c8c30ca..c054b6d89e 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -5,9 +5,9 @@ from django.db.models import Ffrom django.shortcuts import get_object_or_404, redirectfrom django.utils.translation import pgettext_lazyfrom prices import Price-from satchless.item import InsufficientStockfrom ..account.utils import store_user_address+from ..core.exceptions import InsufficientStockfrom ..product.utils import allocate_stockfrom . import GroupStatusdiff --git a/saleor/product/models.py b/saleor/product/models.pyindex 99f7c23bd1..641a8e13ce 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -14,10 +14,10 @@ from django_prices.models import Price, PriceFieldfrom mptt.managers import TreeManagerfrom mptt.models import MPTTModelfrom prices import PriceRange-from satchless.item import InsufficientStockfrom text_unidecode import unidecodefrom versatileimagefield.fields import PPOIField, VersatileImageField+from ..core.exceptions import InsufficientStockfrom ..discount.utils import calculate_discounted_pricefrom .utils import get_attributes_display_mapdiff --git a/tests/test_cart.py b/tests/test_cart.pyindex 58037e57a5..eb5d9551ff 100644--- a/tests/test_cart.py+++ b/tests/test_cart.py@@ -10,12 +10,12 @@ from django.http import HttpResponsefrom django.urls import reversefrom django_babel.templatetags.babel import currencyfmtfrom prices import Price-from satchless.item import InsufficientStockfrom saleor.cart import CartStatus, forms, utilsfrom saleor.cart.context_processors import cart_counterfrom saleor.cart.models import Cart, ProductGroup, find_open_cart_for_userfrom saleor.cart.views import update+from saleor.core.exceptions import InsufficientStockfrom saleor.discount.models import Salefrom saleor.shipping.utils import get_shipment_optionsdiff --git a/tests/test_checkout.py b/tests/test_checkout.pyindex d931d0651a..6bd7a3365d 100644--- a/tests/test_checkout.py+++ b/tests/test_checkout.py@@ -4,12 +4,12 @@ import pytestfrom django.conf import settingsfrom django.contrib.auth.models import AnonymousUserfrom prices import Price-from satchless.item import InsufficientStockfrom saleor.account.models import Addressfrom saleor.checkout import viewsfrom saleor.checkout.core import STORAGE_SESSION_KEY, Checkoutfrom saleor.checkout.forms import NoteForm+from saleor.core.exceptions import InsufficientStockfrom saleor.shipping.models import ShippingMethodCountry