Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Improve error messages

Patryk Zawadzki7ca83288f70b
diff --git a/requirements.txt b/requirements.txt
index 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-prices
boto==2.39.0 # via django-offsite-storage
braintree==3.24.0 # via django-payments
cffi==1.5.0 # via cryptography
@@ -28,15 +28,12 @@ django-prices==0.4.11
django-redis==4.3.0
django-selectable==0.9.0
django-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, jsonfield
djangorestframework==3.3.2
-enum34==1.1.2 # via cryptography
fake-factory==0.5.3
google-i18n-address==1.0.7
google-measurement-protocol==0.1.5
idna==2.0 # via cryptography
-ipaddr==2.1.11 # via maxminddb
-ipaddress==1.0.16 # via cryptography
jsonfield==1.0.3
lxml==3.5.0 # via premailer
markdown==2.6.5
@@ -44,7 +41,7 @@ maxminddb-geolite2==2015.708
maxminddb==1.2.0
mock==1.3.0
pbr==1.8.1 # via mock
-pillow==3.1.1 # via django-versatileimagefield
+Pillow==3.1.1 # via django-versatileimagefield
premailer==2.9.7 # via django-emailit
prices==0.5.7
psycopg2==2.6.1
@@ -52,7 +49,7 @@ purl==1.2
py==1.4.31 # via pytest
pyasn1==0.1.9 # via cryptography
pycparser==2.14 # via cffi
-pyjwt==1.4.0 # via django-payments
+PyJWT==1.4.0 # via django-payments
pytest-django==2.9.1
pytest==2.8.7
pytz==2015.7 # via babel
diff --git a/saleor/discount/models.py b/saleor/discount/models.py
index 03a3682d6e..088c53c839 100644
--- a/saleor/discount/models.py
+++ b/saleor/discount/models.py
@@ -8,6 +8,7 @@ from django.utils.translation import pgettext, pgettext_lazy
from django.utils.encoding import python_2_unicode_compatible, smart_text
from django_countries import countries
from django_prices.models import PriceField
+from django_prices.templatetags.prices_i18n import net
from prices import FixedDiscount, percentage_discount, Price
from ..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_total
if 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_method
if 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 and
shipping_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.py
index 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.')]) # noqa
def 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.'