Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve error messages
Patryk Zawadzki7ca83288f70b
diff --git a/requirements.txt b/requirements.txtindex 167d67d43c..e9a66e8d96 100644--- a/requirements.txt+++ b/requirements.txt@@ -4,8 +4,8 @@## pip-compile requirements.in#-babel==2.2.0-babeldjango==0.2.2+Babel==2.2.0 # via babeldjango, django-prices+BabelDjango==0.2.2 # via django-pricesboto==2.39.0 # via django-offsite-storagebraintree==3.24.0 # via django-paymentscffi==1.5.0 # via cryptography@@ -28,15 +28,12 @@ django-prices==0.4.11django-redis==4.3.0django-selectable==0.9.0django-versatileimagefield==1.3-django==1.9.2+Django==1.9.2 # via django-absolute, django-emailit, django-model-utils, django-mptt, django-offsite-storage, django-payments, django-prices, jsonfielddjangorestframework==3.3.2-enum34==1.1.2 # via cryptographyfake-factory==0.5.3google-i18n-address==1.0.7google-measurement-protocol==0.1.5idna==2.0 # via cryptography-ipaddr==2.1.11 # via maxminddb-ipaddress==1.0.16 # via cryptographyjsonfield==1.0.3lxml==3.5.0 # via premailermarkdown==2.6.5@@ -44,7 +41,7 @@ maxminddb-geolite2==2015.708maxminddb==1.2.0mock==1.3.0pbr==1.8.1 # via mock-pillow==3.1.1 # via django-versatileimagefield+Pillow==3.1.1 # via django-versatileimagefieldpremailer==2.9.7 # via django-emailitprices==0.5.7psycopg2==2.6.1@@ -52,7 +49,7 @@ purl==1.2py==1.4.31 # via pytestpyasn1==0.1.9 # via cryptographypycparser==2.14 # via cffi-pyjwt==1.4.0 # via django-payments+PyJWT==1.4.0 # via django-paymentspytest-django==2.9.1pytest==2.8.7pytz==2015.7 # via babeldiff --git a/saleor/discount/models.py b/saleor/discount/models.pyindex 03a3682d6e..088c53c839 100644--- a/saleor/discount/models.py+++ b/saleor/discount/models.py@@ -8,6 +8,7 @@ from django.utils.translation import pgettext, pgettext_lazyfrom django.utils.encoding import python_2_unicode_compatible, smart_textfrom django_countries import countriesfrom django_prices.models import PriceField+from django_prices.templatetags.prices_i18n import netfrom prices import FixedDiscount, percentage_discount, Pricefrom ..cart.utils import (@@ -154,35 +155,33 @@ class Voucher(models.Model):cart_total = checkout.cart.get_total()limit = self.limit if self.limit is not None else cart_totalif cart_total < limit:- msg = pgettext('voucher', 'Discount applicable only for cart '- 'total equal or greater than %(amount)s'- '%(currency)s')- raise NotApplicable(msg % {- 'amount': limit.net,- 'currency': limit.currency})+ msg = pgettext(+ 'voucher',+ 'This offer is only valid for orders over %(amount)s.')+ raise NotApplicable(msg % {'amount': net(limit)})return self.get_fixed_discount_for(cart_total)elif self.type == Voucher.SHIPPING_TYPE:if not checkout.is_shipping_required:- msg = pgettext('voucher', 'Checkout is not shippable')+ msg = pgettext(+ 'voucher', 'Your order does not require shipping.')raise NotApplicable(msg)shipping_method = checkout.shipping_methodif not shipping_method:- msg = pgettext('voucher', 'Select shipping method first')+ msg = pgettext(+ 'voucher', 'Please select a shipping method first.')raise NotApplicable(msg)if (self.apply_to is not None andshipping_method.country_code != self.apply_to):msg = pgettext(- 'voucher', 'Discount apply only for %(country)s')+ 'voucher', 'This offer is only valid in %(country)s.')raise NotApplicable(msg % {'country': self.get_apply_to_display()})if self.limit is not None and shipping_method.price > self.limit:msg = pgettext(- 'voucher', 'Discount applicable only for shipping price '- 'equal or greater than %(amount)s%(currency)s')- raise NotApplicable(msg % {- 'amount': self.limit.net,- 'currency': self.limit.currency})+ 'voucher',+ 'This offer is only valid for shipping over %(amount)s.')+ raise NotApplicable(msg % {'amount': net(self.limit)})return self.get_fixed_discount_for(shipping_method.price)elif self.type in (Voucher.PRODUCT_TYPE, Voucher.CATEGORY_TYPE):@@ -196,7 +195,7 @@ class Voucher(models.Model):checkout.cart, self.category)))if len(prices) == 0:msg = pgettext(- 'voucher', 'Any product in cart matches discount')+ 'voucher', 'This offer is only valid for selected items.')raise NotApplicable(msg)if self.apply_to == Voucher.APPLY_TO_ALL_PRODUCTS:discounts = (diff --git a/saleor/discount/test_discounts.py b/saleor/discount/test_discounts.pyindex c2b22a3679..f0c5620816 100644--- a/saleor/discount/test_discounts.py+++ b/saleor/discount/test_discounts.py@@ -91,8 +91,7 @@ def test_value_voucher_checkout_discount_not_applicable(settings):return_value=Price(10, currency='USD'))))with pytest.raises(NotApplicable) as e:voucher.get_discount_for_checkout(checkout)- assert str(e.value) == ('Discount applicable only for cart total '- 'equal or greater than 100USD')+ assert str(e.value) == 'This offer is only valid for orders over $100.00.'@pytest.mark.parametrize(@@ -121,14 +120,14 @@ def test_shipping_voucher_checkout_discount(settings, shipping_cost,@pytest.mark.parametrize('is_shipping_required, shipping_method, discount_value, discount_type, apply_to, limit, error_msg', [ # noqa(True, Mock(country_code='PL'), 10, Voucher.DISCOUNT_VALUE_FIXED, 'US',- None, 'Discount apply only for United States of America'),+ None, 'This offer is only valid in United States of America.'),(True, None, 10, Voucher.DISCOUNT_VALUE_FIXED, None, None,- 'Select shipping method first'),+ 'Please select a shipping method first.'),(False, None, 10, Voucher.DISCOUNT_VALUE_FIXED, None, None,- 'Checkout is not shippable'),+ 'Your order does not require shipping.'),(True, Mock(price=Price(10, currency='USD')), 10,Voucher.DISCOUNT_VALUE_FIXED, None, 5,- 'Discount applicable only for shipping price equal or greater than 5USD')]) # noqa+ 'This offer is only valid for shipping over $5.00.')]) # noqadef test_shipping_voucher_checkout_discountnot_applicable(settings,is_shipping_required,shipping_method,@@ -163,7 +162,7 @@ def test_product_voucher_checkout_discount_not_applicable(settings,checkout = Mock(cart=Mock())with pytest.raises(NotApplicable) as e:voucher.get_discount_for_checkout(checkout)- assert str(e.value) == 'Any product in cart matches discount'+ assert str(e.value) == 'This offer is only valid for selected items.'def test_category_voucher_checkout_discount_not_applicable(settings,@@ -179,7 +178,7 @@ def test_category_voucher_checkout_discount_not_applicable(settings,checkout = Mock(cart=Mock())with pytest.raises(NotApplicable) as e:voucher.get_discount_for_checkout(checkout)- assert str(e.value) == 'Any product in cart matches discount'+ assert str(e.value) == 'This offer is only valid for selected items.'