Skip to content

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

Rename 'limit' to 'minimum amount spent'

Pacu23942a0805165
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index 14250b077d..79c044124f 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -620,11 +620,6 @@ def get_cart_data_for_checkout(cart, discounts, taxes):
'cart_total': total}
-def _get_value_voucher_discount_for_cart(voucher, cart):
- """Calculate discount value for a voucher of value type."""
- return get_value_voucher_discount(voucher, cart.get_subtotal())
-
-
def _get_shipping_voucher_discount_for_cart(voucher, cart):
"""Calculate discount value for a voucher of shipping type."""
if not cart.is_shipping_required():
@@ -672,12 +667,10 @@ def get_voucher_discount_for_cart(voucher, cart):
Raise NotApplicable if voucher of given type cannot be applied.
"""
if voucher.type == VoucherType.VALUE:
- return _get_value_voucher_discount_for_cart(voucher, cart)
+ return get_value_voucher_discount(voucher, cart.get_subtotal())
if voucher.type == VoucherType.SHIPPING:
return _get_shipping_voucher_discount_for_cart(voucher, cart)
- if voucher.type == VoucherType.PRODUCT:
- return _get_products_voucher_discount(cart, voucher)
- if voucher.type == VoucherType.CATEGORY:
+ if voucher.type in (VoucherType.PRODUCT, VoucherType.CATEGORY):
return _get_products_voucher_discount(cart, voucher)
raise NotImplementedError('Unknown discount type')
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 152468c9dd..c16bca832b 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -531,7 +531,7 @@ def create_vouchers():
'name': 'Big order discount',
'discount_value_type': DiscountValueType.FIXED,
'discount_value': 25,
- 'limit': 200})
+ 'min_amount_spent': 200})
if created:
yield 'Voucher #%d' % voucher.id
else:
diff --git a/saleor/dashboard/discount/filters.py b/saleor/dashboard/discount/filters.py
index 3029c94330..177b2091c3 100644
--- a/saleor/dashboard/discount/filters.py
+++ b/saleor/dashboard/discount/filters.py
@@ -22,7 +22,8 @@ SORT_BY_FIELDS_LABELS_VOUCHER = {
'start_date': pgettext_lazy('Voucher list sorting option', 'start_date'),
'end_date': pgettext_lazy('Voucher list sorting option', 'end_date'),
'used': pgettext_lazy('Voucher list sorting option', 'used'),
- 'limit': pgettext_lazy('Voucher list sorting option', 'limit')}
+ 'min_amount_spent': pgettext_lazy(
+ 'Voucher list sorting option', 'min_amount_spent')}
DISCOUNT_TYPE_CHOICES = (
('fixed', pgettext_lazy('Sale type filter choice', 'USD')),
@@ -79,9 +80,10 @@ class VoucherFilter(SortedFilterSet):
label=pgettext_lazy(
'Order list sorting filter label', 'Period of validity'),
name='created', widget=DateRangeWidget, method='filter_by_date_range')
- limit = RangeFilter(
- label=pgettext_lazy('Voucher list sorting filter', 'Limit'),
- name='limit')
+ min_amount_spent = RangeFilter(
+ label=pgettext_lazy(
+ 'Voucher list sorting filter', 'Minimum amount spent'),
+ name='min_amount_spent')
sort_by = OrderingFilter(
label=pgettext_lazy('Voucher list sorting filter label', 'Sort by'),
fields=SORT_BY_FIELDS_LABELS_VOUCHER.keys(),
diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.py
index 5572ab7552..7273007b8a 100644
--- a/saleor/dashboard/discount/forms.py
+++ b/saleor/dashboard/discount/forms.py
@@ -12,7 +12,7 @@ from ...discount import DiscountValueType
from ...discount.models import Sale, Voucher
from ...product.models import Product
from ...shipping.models import ShippingMethodCountry
-from ..forms import AjaxSelect2ChoiceField, AjaxSelect2MultipleChoiceField
+from ..forms import AjaxSelect2MultipleChoiceField
class SaleForm(forms.ModelForm):
@@ -70,7 +70,7 @@ class VoucherForm(forms.ModelForm):
class Meta:
model = Voucher
- exclude = ['limit', 'countries', 'products', 'collections', 'used']
+ exclude = ['min_amount_spent', 'countries', 'products', 'collections', 'used']
labels = {
'type': pgettext_lazy(
'Discount type',
@@ -124,7 +124,7 @@ def country_choices():
class ShippingVoucherForm(forms.ModelForm):
- limit = MoneyField(
+ min_amount_spent = MoneyField(
min_value=ZERO_MONEY, required=False,
currency=settings.DEFAULT_CURRENCY,
label=pgettext_lazy(
@@ -139,7 +139,7 @@ class ShippingVoucherForm(forms.ModelForm):
class Meta:
model = Voucher
- fields = ['countries', 'limit']
+ fields = ['countries', 'min_amount_spent']
def save(self, commit=True):
return super().save(commit)
@@ -147,7 +147,7 @@ class ShippingVoucherForm(forms.ModelForm):
class ValueVoucherForm(forms.ModelForm):
- limit = MoneyField(
+ min_amount_spent = MoneyField(
min_value=ZERO_MONEY, required=False,
currency=settings.DEFAULT_CURRENCY,
label=pgettext_lazy(
@@ -156,7 +156,7 @@ class ValueVoucherForm(forms.ModelForm):
class Meta:
model = Voucher
- fields = ['limit']
+ fields = ['min_amount_spent']
def save(self, commit=True):
self.instance.category = None
@@ -170,16 +170,16 @@ class CommonVoucherForm(forms.ModelForm):
use_required_attribute = False
def save(self, commit=True):
- self.instance.limit = None
+ self.instance.min_amount_spent = None
return super().save(commit)
class ProductVoucherForm(CommonVoucherForm):
- product = AjaxSelect2ChoiceField(
+ products = AjaxSelect2MultipleChoiceField(
queryset=Product.objects.all(),
fetch_data_url=reverse_lazy('dashboard:ajax-products'),
required=True,
- label=pgettext_lazy('Product', 'Product'))
+ label=pgettext_lazy('Product', 'Products'))
class Meta:
model = Voucher
diff --git a/saleor/discount/models.py b/saleor/discount/models.py
index 59391c7560..6d12452834 100644
--- a/saleor/discount/models.py
+++ b/saleor/discount/models.py
@@ -17,13 +17,14 @@ from . import DiscountValueType, VoucherType
class NotApplicable(ValueError):
"""Exception raised when a discount is not applicable to a checkout.
- If the error is raised because the order value is too low the minimum
- price limit will be available as the `limit` attribute.
+ The error is raised if the order value is below the minimum required
+ price.
+ Minimum price will be available as the `min_amount_spent` attribute.
"""
- def __init__(self, msg, limit=None):
+ def __init__(self, msg, min_amount_spent=None):
super().__init__(msg)
- self.limit = limit
+ self.min_amount_spent = min_amount_spent
class VoucherQueryset(models.QuerySet):
@@ -52,7 +53,7 @@ class Voucher(models.Model):
# not mandatory fields, usage depends on type
countries = CountryField(multiple=True, blank=True)
- limit = MoneyField(
+ min_amount_spent = MoneyField(
currency=settings.DEFAULT_CURRENCY, max_digits=12,
decimal_places=settings.DEFAULT_DECIMAL_PLACES, null=True, blank=True)
products = models.ManyToManyField('product.Product', blank=True)
@@ -110,13 +111,15 @@ class Voucher(models.Model):
return gross_price
return gross_price - gross_after_discount
- def validate_limit(self, value):
- limit = self.limit or value.gross
- if value.gross < limit:
+ def validate_min_amount_spent(self, value):
+ min_amount_spent = self.min_amount_spent
+ if min_amount_spent and value.gross < min_amount_spent:
msg = pgettext(
'Voucher not applicable',
'This offer is only valid for orders over %(amount)s.')
- raise NotApplicable(msg % {'amount': amount(limit)}, limit=limit)
+ raise NotApplicable(msg % {
+ 'amount': amount(min_amount_spent)},
+ min_amount_spent=min_amount_spent)
class Sale(models.Model):
diff --git a/saleor/discount/utils.py b/saleor/discount/utils.py
index 200e7ff17b..6818bab059 100644
--- a/saleor/discount/utils.py
+++ b/saleor/discount/utils.py
@@ -66,13 +66,13 @@ def calculate_discounted_price(product, price, discounts):
def get_value_voucher_discount(voucher, total_price):
"""Calculate discount value for a voucher of value type."""
- voucher.validate_limit(total_price)
+ voucher.validate_min_amount_spent(total_price)
return voucher.get_discount_amount_for(total_price)
def get_shipping_voucher_discount(voucher, total_price, shipping_price):
"""Calculate discount value for a voucher of shipping type."""
- voucher.validate_limit(total_price)
+ voucher.validate_min_amount_spent(total_price)
return voucher.get_discount_amount_for(shipping_price)
diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.py
index 594c105a46..ea8900601b 100644
--- a/saleor/graphql/discount/mutations.py
+++ b/saleor/graphql/discount/mutations.py
@@ -34,7 +34,8 @@ class VoucherInput(graphene.InputObjectType):
graphene.ID, description='Products discounted by the voucher.')
collections = graphene.List(
graphene.ID, description='Collections discounted by the voucher.')
- limit = Decimal(description='Limit value of the discount.')
+ min_amount_spent = Decimal(
+ description='Min purchase amount required to apply the voucher.')
countries = graphene.List(
graphene.String,
description='Country codes that can be used with '
diff --git a/saleor/graphql/discount/resolvers.py b/saleor/graphql/discount/resolvers.py
index c099fe5384..467d850cb9 100644
--- a/saleor/graphql/discount/resolvers.py
+++ b/saleor/graphql/discount/resolvers.py
@@ -3,7 +3,7 @@ from ..utils import filter_by_query_param
VOUCHER_SEARCH_FIELDS = (
'name', 'code', 'discount_value', 'collections__name', 'products__name',
- 'limit', 'countries', 'discount_value_type')
+ 'min_amount_spent', 'countries', 'discount_value_type')
SALE_SEARCH_FIELDS = ('name', 'value', 'type')
diff --git a/saleor/graphql/discount/types.py b/saleor/graphql/discount/types.py
index 01e5041c07..8acd1a42c4 100644
--- a/saleor/graphql/discount/types.py
+++ b/saleor/graphql/discount/types.py
@@ -17,7 +17,7 @@ class Voucher(CountableDjangoObjectType):
'discount_value': ['gte', 'lte'],
'start_date': ['exact'],
'end_date': ['exact'],
- 'limit': ['gte', 'lte']}
+ 'min_amount_spent': ['gte', 'lte']}
model = models.Voucher
diff --git a/templates/dashboard/discount/voucher/list.html b/templates/dashboard/discount/voucher/list.html
index a5934a589f..d82bd68685 100644
--- a/templates/dashboard/discount/voucher/list.html
+++ b/templates/dashboard/discount/voucher/list.html
@@ -55,8 +55,8 @@
{% trans "Used" context "Voucher table header" as label %}
{% sorting_header 'used' label is_wide=True %}
- {% trans "Limit" context "Voucher table header" as label %}
- {% sorting_header 'limit' label is_wide=True %}
+ {% trans "Min amount spent" context "Voucher table header" as label %}
+ {% sorting_header 'min_amount_spent' label is_wide=True %}
</tr>
</thead>
{% for voucher in vouchers %}
@@ -82,8 +82,8 @@
{% endif %}
</td>
<td class="right-align">
- {% if voucher.limit %}
- {% price voucher.limit %}
+ {% if voucher.min_amount_spent %}
+ {% price voucher.min_amount_spent %}
{% else %}
-
{% endif %}
diff --git a/tests/api/test_discount.py b/tests/api/test_discount.py
index 7280d30184..5b428945d6 100644
--- a/tests/api/test_discount.py
+++ b/tests/api/test_discount.py
@@ -104,18 +104,18 @@ def test_create_voucher(user_api_client, admin_api_client):
mutation voucherCreate(
$type: VoucherTypeEnum, $name: String, $code: String,
$discountValueType: DiscountValueTypeEnum,
- $discountValue: Decimal, $limit: Decimal) {
+ $discountValue: Decimal, $minAmountSpent: Decimal) {
voucherCreate(input: {
name: $name, type: $type, code: $code,
discountValueType: $discountValueType, discountValue: $discountValue,
- limit: $limit}) {
+ minAmountSpent: $minAmountSpent}) {
errors {
field
message
}
voucher {
type
- limit {
+ minAmountSpent {
amount
}
name
@@ -131,7 +131,7 @@ def test_create_voucher(user_api_client, admin_api_client):
'code': 'testcode123',
'discountValueType': DiscountValueTypeEnum.FIXED.name,
'discountValue': '10.12',
- 'limit': '1.12'})
+ 'minAmountSpent': '1.12'})
response = user_api_client.post(
reverse('api'), {'query': query, 'variables': variables})
assert_no_permission(response)
@@ -142,7 +142,7 @@ def test_create_voucher(user_api_client, admin_api_client):
assert 'errors' not in content
data = content['data']['voucherCreate']['voucher']
assert data['type'] == VoucherType.VALUE.upper()
- assert data['limit']['amount'] == float('1.12')
+ assert data['minAmountSpent']['amount'] == float('1.12')
assert data['name'] == 'test voucher'
assert data['code'] == 'testcode123'
assert data['discountValueType'] == DiscountValueType.FIXED.upper()
diff --git a/tests/api/test_fulfillment.py b/tests/api/test_fulfillment.py
index e26c97b377..cae7cdbae4 100644
--- a/tests/api/test_fulfillment.py
+++ b/tests/api/test_fulfillment.py
@@ -1,15 +1,10 @@
import json
-from unittest.mock import MagicMock, Mock
import graphene
-import pytest
from django.shortcuts import reverse
from tests.utils import get_graphql_content
-from saleor.account.models import Address
-from saleor.graphql.order.mutations.draft_orders import (
- check_for_draft_order_errors)
-from saleor.order.models import Order, OrderStatus, PaymentStatus, FulfillmentStatus
+from saleor.order.models import FulfillmentStatus
def test_create_fulfillment(admin_api_client, order_with_lines):
diff --git a/tests/dashboard/test_discounts.py b/tests/dashboard/test_discounts.py
index 34d6873264..b23eebbeee 100644
--- a/tests/dashboard/test_discounts.py
+++ b/tests/dashboard/test_discounts.py
@@ -33,7 +33,7 @@ def test_voucher_shipping_add(admin_client):
'start_date': '2018-01-01', 'end_date': '2018-06-01',
'type': VoucherType.SHIPPING, 'discount_value': '15.99',
'discount_value_type': DiscountValueType.FIXED,
- 'shipping-limit': '59.99'}
+ 'shipping-min_amount_spent': '59.99'}
response = admin_client.post(url, data, follow=True)
assert response.status_code == 200
assert Voucher.objects.count() == 1
@@ -46,7 +46,7 @@ def test_voucher_shipping_add(admin_client):
assert voucher.end_date == date(2018, 6, 1)
assert voucher.discount_value_type == DiscountValueType.FIXED
assert voucher.discount_value == Decimal('15.99')
- assert voucher.limit == Money('59.99', 'USD')
+ assert voucher.min_amount_spent == Money('59.99', 'USD')
def test_view_sale_add(admin_client, default_category, collection):
@@ -94,16 +94,16 @@ def test_view_sale_add_requires_product_category_or_collection(
@pytest.mark.parametrize(
- 'total, discount_value, discount_type, limit, expected_value', [
+ 'total, discount_value, discount_type, min_amount_spent, expected_value', [
('100', 10, DiscountValueType.FIXED, None, 10),
('100.05', 10, DiscountValueType.PERCENTAGE, 100, 10)])
def test_value_voucher_order_discount(
- settings, total, discount_value, discount_type, limit, expected_value):
+ settings, total, discount_value, discount_type, min_amount_spent, expected_value):
voucher = Voucher(
code='unique', type=VoucherType.VALUE,
discount_value_type=discount_type,
discount_value=discount_value,
- limit=Money(limit, 'USD') if limit is not None else None)
+ min_amount_spent=Money(min_amount_spent, 'USD') if min_amount_spent is not None else None)
subtotal = TaxedMoney(net=Money(total, 'USD'), gross=Money(total, 'USD'))
order = Mock(get_subtotal=Mock(return_value=subtotal), voucher=voucher)
discount = get_voucher_discount_for_order(order)
@@ -120,7 +120,7 @@ def test_shipping_voucher_order_discount(
code='unique', type=VoucherType.SHIPPING,
discount_value_type=discount_type,
discount_value=discount_value,
- limit=None)
+ min_amount_spent=None)
subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
shipping_total = TaxedMoney(
net=Money(shipping_cost, 'USD'), gross=Money(shipping_cost, 'USD'))
@@ -137,7 +137,7 @@ def test_shipping_voucher_checkout_discount_not_applicable_returns_zero():
code='unique', type=VoucherType.SHIPPING,
discount_value_type=DiscountValueType.FIXED,
discount_value=10,
- limit=Money(20, 'USD'))
+ min_amount_spent=Money(20, 'USD'))
price = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
order = Mock(
get_subtotal=Mock(return_value=price),
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index a410b6cd1c..d1f4e77458 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -504,18 +504,18 @@ def test_note_in_created_order_empty_note(request_cart_with_item, address):
@pytest.mark.parametrize(
- 'total, discount_value, discount_type, limit, discount_amount', [
+ 'total, discount_value, discount_type, min_amount_spent, discount_amount', [
('100', 10, DiscountValueType.FIXED, None, 10),
('100.05', 10, DiscountValueType.PERCENTAGE, 100, 10)])
def test_get_discount_for_cart_value_voucher(
- total, discount_value, discount_type, limit,
+ total, discount_value, discount_type, min_amount_spent,
discount_amount):
voucher = Voucher(
code='unique',
type=VoucherType.VALUE,
discount_value_type=discount_type,
discount_value=discount_value,
- limit=Money(limit, 'USD') if limit is not None else None)
+ min_amount_spent=Money(min_amount_spent, 'USD') if min_amount_spent is not None else None)
subtotal = TaxedMoney(net=Money(total, 'USD'), gross=Money(total, 'USD'))
cart = Mock(get_subtotal=Mock(return_value=subtotal))
discount = get_voucher_discount_for_cart(voucher, cart)
@@ -528,12 +528,12 @@ def test_get_discount_for_cart_value_voucher_not_applicable():
type=VoucherType.VALUE,
discount_value_type=DiscountValueType.FIXED,
discount_value=10,
- limit=Money(100, 'USD'))
+ min_amount_spent=Money(100, 'USD'))
subtotal = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
cart = Mock(get_subtotal=Mock(return_value=subtotal))
with pytest.raises(NotApplicable) as e:
get_voucher_discount_for_cart(voucher, cart)
- assert e.value.limit == Money(100, 'USD')
+ assert e.value.min_amount_spent == Money(100, 'USD')
@pytest.mark.parametrize(
@@ -561,14 +561,14 @@ def test_get_discount_for_cart_shipping_voucher(
discount_value_type=discount_type,
discount_value=discount_value,
countries=countries,
- limit=None)
+ min_amount_spent=None)
discount = get_voucher_discount_for_cart(voucher, cart)
assert discount == Money(expected_value, 'USD')
@pytest.mark.parametrize(
'is_shipping_required, shipping_method, discount_value, discount_type,'
- 'countries, limit, subtotal, error_msg', [
+ 'countries, min_amount_spent, subtotal, error_msg', [
(True, Mock(country_code='PL'), 10, DiscountValueType.FIXED,
['US'], None, Money(10, 'USD'),
'This offer is not valid in your country.'),
@@ -583,7 +583,7 @@ def test_get_discount_for_cart_shipping_voucher(
'This offer is only valid for orders over $5.00.')])
def test_get_discount_for_cart_shipping_voucher_not_applicable(
is_shipping_required, shipping_method, discount_value,
- discount_type, countries, limit, subtotal, error_msg):
+ discount_type, countries, min_amount_spent, subtotal, error_msg):
subtotal_price = TaxedMoney(net=subtotal, gross=subtotal)
cart = Mock(
get_subtotal=Mock(return_value=subtotal_price),
@@ -593,7 +593,7 @@ def test_get_discount_for_cart_shipping_voucher_not_applicable(
code='unique', type=VoucherType.SHIPPING,
discount_value_type=discount_type,
discount_value=discount_value,
- limit=Money(limit, 'USD') if limit is not None else None,
+ min_amount_spent=Money(min_amount_spent, 'USD') if min_amount_spent is not None else None,
countries=countries)
with pytest.raises(NotApplicable) as e:
get_voucher_discount_for_cart(voucher, cart)
@@ -642,7 +642,7 @@ def test_cart_voucher_form_invalid_voucher_code(
def test_cart_voucher_form_voucher_not_applicable(
voucher, request_cart_with_item):
- voucher.limit = 200
+ voucher.min_amount_spent = 200
voucher.save()
form = CartVoucherForm(
{'voucher': voucher.code}, instance=request_cart_with_item)
@@ -758,7 +758,7 @@ def test_recalculate_cart_discount(cart_with_voucher, voucher):
def test_recalculate_cart_discount_voucher_not_applicable(
cart_with_voucher, voucher):
cart = cart_with_voucher
- voucher.limit = 100
+ voucher.min_amount_spent = 100
voucher.save()
recalculate_cart_discount(cart_with_voucher, None, None)
diff --git a/tests/test_discounts.py b/tests/test_discounts.py
index b01798d65c..4554b4fda6 100644
--- a/tests/test_discounts.py
+++ b/tests/test_discounts.py
@@ -15,15 +15,21 @@ from saleor.discount.utils import (
from saleor.product.models import Product, ProductVariant
[email protected]('limit, value', [
+def get_min_amount_spent(min_amount_spent):
+ if min_amount_spent is not None:
+ return Money(min_amount_spent, 'USD')
+ return None
+
+
[email protected]('min_amount_spent, value', [
(Money(5, 'USD'), Money(10, 'USD')),
(Money(10, 'USD'), Money(10, 'USD'))])
-def test_valid_voucher_limit(settings, limit, value):
+def test_valid_voucher_min_amount_spent(settings, min_amount_spent, value):
voucher = Voucher(
code='unique', type=VoucherType.SHIPPING,
discount_value_type=DiscountValueType.FIXED,
- discount_value=Money(10, 'USD'), limit=limit)
- voucher.validate_limit(TaxedMoney(net=value, gross=value))
+ discount_value=Money(10, 'USD'), min_amount_spent=min_amount_spent)
+ voucher.validate_min_amount_spent(TaxedMoney(net=value, gross=value))
@pytest.mark.integration
@@ -65,7 +71,7 @@ def test_voucher_queryset_active(voucher):
date=date.today() - timedelta(days=1))
assert len(active_vouchers) == 0
-#FIXME What is this test?
+# FIXME What is this test?
# @pytest.mark.parametrize(
# 'prices, discount_value, discount_type, expected_value', [
# (
@@ -141,18 +147,19 @@ def test_decrease_voucher_usage():
@pytest.mark.parametrize(
- 'total, limit, discount_value, discount_value_type, expected_value', [
+ 'total, min_amount_spent, discount_value, discount_value_type, expected_value', [
(20, 15, 50, DiscountValueType.PERCENTAGE, 10),
(20, None, 50, DiscountValueType.PERCENTAGE, 10),
(20, 15, 5, DiscountValueType.FIXED, 5),
(20, None, 5, DiscountValueType.FIXED, 5)])
def test_get_value_voucher_discount(
- total, limit, discount_value, discount_value_type, expected_value):
+ total, min_amount_spent, discount_value, discount_value_type,
+ expected_value):
voucher = Voucher(
code='unique', type=VoucherType.VALUE,
discount_value_type=discount_value_type,
discount_value=discount_value,
- limit=Money(limit, 'USD') if limit is not None else None)
+ min_amount_spent=get_min_amount_spent(min_amount_spent))
voucher.save()
total_price = TaxedMoney(
net=Money(total, 'USD'), gross=Money(total, 'USD'))
@@ -161,19 +168,20 @@ def test_get_value_voucher_discount(
@pytest.mark.parametrize(
- 'total, limit, shipping_price, discount_value, discount_value_type, expected_value', [ # noqa
+ 'total, min_amount_spent, shipping_price, discount_value, '
+ 'discount_value_type, expected_value', [
(20, 15, 10, 50, DiscountValueType.PERCENTAGE, 5),
(20, None, 10, 50, DiscountValueType.PERCENTAGE, 5),
(20, 15, 10, 5, DiscountValueType.FIXED, 5),
(20, None, 10, 5, DiscountValueType.FIXED, 5)])
def test_get_shipping_voucher_discount(
- total, limit, shipping_price, discount_value, discount_value_type,
- expected_value):
+ total, min_amount_spent, shipping_price, discount_value,
+ discount_value_type, expected_value):
voucher = Voucher(
code='unique', type=VoucherType.VALUE,
discount_value_type=discount_value_type,
discount_value=discount_value,
- limit=Money(limit, 'USD') if limit is not None else None)
+ min_amount_spent=get_min_amount_spent(min_amount_spent))
voucher.save()
total = TaxedMoney(
net=Money(total, 'USD'), gross=Money(total, 'USD'))
@@ -184,7 +192,7 @@ def test_get_shipping_voucher_discount(
@pytest.mark.parametrize(
- 'prices, discount_value_type, discount_value, voucher_type, expected_value', [ # noqa
+ 'prices, discount_value_type, discount_value, voucher_type, ''expected_value', [ # noqa
([5, 10, 15], DiscountValueType.PERCENTAGE, 10, VoucherType.PRODUCT, 3),
([5, 10, 15], DiscountValueType.FIXED, 2, VoucherType.PRODUCT, 2),
([5, 10, 15], DiscountValueType.FIXED, 2, VoucherType.CATEGORY, 2)])