Skip to content

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

Fix discounts logic in right place.

Artur Smęt019f87908f57
diff --git a/saleor/discount/models.py b/saleor/discount/models.py
index 088c53c839..3b7ee9ae88 100644
--- a/saleor/discount/models.py
+++ b/saleor/discount/models.py
@@ -171,7 +171,7 @@ class Voucher(models.Model):
msg = pgettext(
'voucher', 'Please select a shipping method first.')
raise NotApplicable(msg)
- if (self.apply_to is not None and
+ if (self.apply_to and
shipping_method.country_code != self.apply_to):
msg = pgettext(
'voucher', 'This offer is only valid in %(country)s.')
diff --git a/saleor/discount/test_discounts.py b/saleor/discount/test_discounts.py
index f0c5620816..6db69fa99c 100644
--- a/saleor/discount/test_discounts.py
+++ b/saleor/discount/test_discounts.py
@@ -98,6 +98,7 @@ def test_value_voucher_checkout_discount_not_applicable(settings):
'shipping_cost, shipping_country_code, discount_value, discount_type, apply_to, expected_value', [ # noqa
(10, None, 50, Voucher.DISCOUNT_VALUE_PERCENTAGE, None, 5),
(10, None, 20, Voucher.DISCOUNT_VALUE_FIXED, None, 10),
+ (10, 'PL', 20, Voucher.DISCOUNT_VALUE_FIXED, '', 10),
(5, 'PL', 5, Voucher.DISCOUNT_VALUE_FIXED, 'PL', 5)])
def test_shipping_voucher_checkout_discount(settings, shipping_cost,
shipping_country_code,