Skip to content

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

Remove deprecated voucher types

fowczarek515b2277f76f
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index 6ec0705b9f..8a49844b9c 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -135,78 +135,6 @@ def get_prices_of_discounted_specific_product(lines, voucher, discounts=None):
return line_prices
-def get_prices_of_discounted_products(checkout, discounted_products, discounts=None):
- """Get prices of variants belonging to the discounted products."""
- # If there's no discounted_products,
- # it means that all products are discounted
- line_prices = []
- if discounted_products:
- manager = get_extensions_manager()
- for line in checkout:
- if line.variant.product in discounted_products:
- line_total = manager.calculate_checkout_line_total(
- line, discounts or []
- ).gross
- line_unit_price = quantize_price(
- (line_total / line.quantity), line_total.currency
- )
- line_prices.extend([line_unit_price] * line.quantity)
- return line_prices
-
-
-def get_prices_of_products_in_discounted_collections(
- checkout, discounted_collections, discounts=None
-):
- """Get prices of variants belonging to the discounted collections."""
- # If there's no discounted collections,
- # it means that all of them are discounted
- line_prices = []
- if discounted_collections:
- manager = get_extensions_manager()
- for line in checkout:
- if not line.variant:
- continue
- product_collections = line.variant.product.collections.all()
- if set(product_collections).intersection(discounted_collections):
- line_total = manager.calculate_checkout_line_total(
- line, discounts or []
- ).gross
- line_unit_price = quantize_price(
- (line_total / line.quantity), line_total.currency
- )
- line_prices.extend([line_unit_price] * line.quantity)
- return line_prices
-
-
-def get_prices_of_products_in_discounted_categories(
- checkout, discounted_categories, discounts=None
-):
- """Get prices of variants belonging to the discounted categories.
-
- Product must be assigned directly to the discounted category, assigning
- product to child category won't work.
- """
- # If there's no discounted collections,
- # it means that all of them are discounted
- line_prices = []
- if discounted_categories:
- discounted_categories = set(discounted_categories)
- for line in checkout:
- if not line.variant:
- continue
- manager = get_extensions_manager()
- product_category = line.variant.product.category
- if product_category in discounted_categories:
- line_total = manager.calculate_checkout_line_total(
- line, discounts or []
- ).gross
- line_unit_price = quantize_price(
- (line_total / line.quantity), line_total.currency
- )
- line_prices.extend([line_unit_price] * line.quantity)
- return line_prices
-
-
def check_product_availability_and_warn(request, checkout):
"""Warn if checkout contains any lines that cannot be fulfilled."""
if contains_unavailable_variants(checkout):
@@ -800,18 +728,6 @@ def _get_products_voucher_discount(checkout, voucher, discounts=None):
prices = None
if voucher.type == VoucherType.SPECIFIC_PRODUCT:
prices = get_prices_of_discounted_specific_product(checkout, voucher, discounts)
- elif voucher.type == VoucherType.PRODUCT:
- prices = get_prices_of_discounted_products(
- checkout, voucher.products.all(), discounts
- )
- elif voucher.type == VoucherType.COLLECTION:
- prices = get_prices_of_products_in_discounted_collections(
- checkout, voucher.collections.all(), discounts
- )
- elif voucher.type == VoucherType.CATEGORY:
- prices = get_prices_of_products_in_discounted_categories(
- checkout, voucher.categories.all(), discounts
- )
if not prices:
msg = pgettext(
"Voucher not applicable", "This offer is only valid for selected items."
@@ -832,12 +748,7 @@ def get_voucher_discount_for_checkout(voucher, checkout, discounts=None) -> Mone
return voucher.get_discount_amount_for(subtotal)
if voucher.type == VoucherType.SHIPPING:
return _get_shipping_voucher_discount_for_checkout(voucher, checkout, discounts)
- if voucher.type in (
- VoucherType.PRODUCT,
- VoucherType.COLLECTION,
- VoucherType.CATEGORY,
- VoucherType.SPECIFIC_PRODUCT,
- ):
+ if voucher.type == VoucherType.SPECIFIC_PRODUCT:
return _get_products_voucher_discount(checkout, voucher, discounts)
raise NotImplementedError("Unknown discount type")
diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.py
index b5f99b7f10..c037dfa8cb 100644
--- a/saleor/dashboard/discount/forms.py
+++ b/saleor/dashboard/discount/forms.py
@@ -209,44 +209,3 @@ class SpecificProductVoucherForm(CommonVoucherForm):
self.fields["products"].set_initial(self.instance.products.all())
self.fields["categories"].required = False
self.fields["products"].required = False
-
-
-class ProductVoucherForm(CommonVoucherForm):
- products = AjaxSelect2MultipleChoiceField(
- queryset=Product.objects.all(),
- fetch_data_url=reverse_lazy("dashboard:ajax-products"),
- required=True,
- label=pgettext_lazy("Product", "Products"),
- )
-
- class Meta:
- model = Voucher
- fields = ["products", "apply_once_per_order", "min_checkout_items_quantity"]
-
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- if self.instance.pk:
- self.fields["products"].set_initial(self.instance.products.all())
-
-
-class CollectionVoucherForm(CommonVoucherForm):
- class Meta:
- model = Voucher
- fields = ["collections", "apply_once_per_order", "min_checkout_items_quantity"]
- labels = {"collections": pgettext_lazy("Collections", "Collections")}
-
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.fields["collections"].required = True
-
-
-class CategoryVoucherForm(CommonVoucherForm):
- categories = TreeNodeMultipleChoiceField(
- queryset=Category.objects.all(),
- required=True,
- label=pgettext_lazy("Categories", "Categories"),
- )
-
- class Meta:
- model = Voucher
- fields = ["categories", "apply_once_per_order", "min_checkout_items_quantity"]
diff --git a/saleor/dashboard/discount/views.py b/saleor/dashboard/discount/views.py
index a763693a47..a54de13758 100644
--- a/saleor/dashboard/discount/views.py
+++ b/saleor/dashboard/discount/views.py
@@ -28,15 +28,6 @@ def get_voucher_type_forms(voucher, data):
VoucherType.SPECIFIC_PRODUCT: forms.SpecificProductVoucherForm(
data or None, instance=voucher, prefix=VoucherType.SPECIFIC_PRODUCT
),
- VoucherType.PRODUCT: forms.ProductVoucherForm(
- data or None, instance=voucher, prefix=VoucherType.PRODUCT
- ),
- VoucherType.COLLECTION: forms.CollectionVoucherForm(
- data or None, instance=voucher, prefix=VoucherType.COLLECTION
- ),
- VoucherType.CATEGORY: forms.CategoryVoucherForm(
- data or None, instance=voucher, prefix=VoucherType.CATEGORY
- ),
}
diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.py
index 6ce5508581..ae052a8198 100644
--- a/saleor/dashboard/order/utils.py
+++ b/saleor/dashboard/order/utils.py
@@ -74,62 +74,9 @@ def update_order_with_user_addresses(order):
order.save(update_fields=["billing_address", "shipping_address"])
-def get_prices_of_discounted_products(order, discounted_products):
- """Get prices of variants belonging to the discounted products."""
- line_prices = []
- if discounted_products:
- for line in order:
- if line.variant.product in discounted_products:
- line_prices.extend([line.unit_price_gross_amount] * line.quantity)
- return line_prices
-
-
-def get_prices_of_products_in_discounted_collections(order, discounted_collections):
- """Get prices of variants belonging to the discounted collections."""
- line_prices = []
- if discounted_collections:
- for line in order:
- if not line.variant:
- continue
- product_collections = line.variant.product.collections.all()
- if set(product_collections).intersection(discounted_collections):
- line_prices.extend([line.unit_price_gross_amount] * line.quantity)
- return line_prices
-
-
-def get_prices_of_products_in_discounted_categories(order, discounted_categories):
- """Get prices of variants belonging to the discounted categories.
-
- Product must be assigned directly to the discounted category, assigning
- product to child category won't work.
- """
- # If there's no discounted collections,
- # it means that all of them are discounted
- line_prices = []
- if discounted_categories:
- discounted_categories = set(discounted_categories)
- for line in order:
- if not line.variant:
- continue
- product_category = line.variant.product.category
- if product_category in discounted_categories:
- line_prices.extend([line.unit_price_gross_amount] * line.quantity)
- return line_prices
-
-
def get_products_voucher_discount_for_order(order, voucher):
"""Calculate products discount value for a voucher, depending on its type."""
prices = None
- if voucher.type == VoucherType.PRODUCT:
- prices = get_prices_of_discounted_products(order, voucher.products.all())
- elif voucher.type == VoucherType.COLLECTION:
- prices = get_prices_of_products_in_discounted_collections(
- order, voucher.collections.all()
- )
- elif voucher.type == VoucherType.CATEGORY:
- prices = get_prices_of_products_in_discounted_categories(
- order, voucher.categories.all()
- )
if not prices:
msg = pgettext(
"Voucher not applicable", "This offer is only valid for selected items."
@@ -151,12 +98,7 @@ def get_voucher_discount_for_order(order):
return order.voucher.get_discount_amount_for(subtotal.gross)
if order.voucher.type == VoucherType.SHIPPING:
return order.voucher.get_discount_amount_for(order.shipping_price)
- if order.voucher.type in (
- VoucherType.PRODUCT,
- VoucherType.COLLECTION,
- VoucherType.CATEGORY,
- VoucherType.SPECIFIC_PRODUCT,
- ):
+ if order.voucher.type == VoucherType.SPECIFIC_PRODUCT:
return get_products_voucher_discount_for_order(order, order.voucher)
raise NotImplementedError("Unknown discount type")
diff --git a/saleor/discount/__init__.py b/saleor/discount/__init__.py
index 4eb1941514..39fe0e880d 100644
--- a/saleor/discount/__init__.py
+++ b/saleor/discount/__init__.py
@@ -16,25 +16,12 @@ class DiscountValueType:
class VoucherType:
- PRODUCT = "product"
- COLLECTION = "collection"
- CATEGORY = "category"
SHIPPING = "shipping"
- VALUE = "value"
ENTIRE_ORDER = "entire_order"
SPECIFIC_PRODUCT = "specific_product"
CHOICES = [
(ENTIRE_ORDER, pgettext_lazy("Voucher: discount for", "Entire order")),
- (PRODUCT, pgettext_lazy("Voucher: discount for", "Specific products")),
- (
- COLLECTION,
- pgettext_lazy("Voucher: discount for", "Specific collections of products"),
- ),
- (
- CATEGORY,
- pgettext_lazy("Voucher: discount for", "Specific categories of products"),
- ),
(SHIPPING, pgettext_lazy("Voucher: discount for", "Shipping")),
(
SPECIFIC_PRODUCT,
diff --git a/saleor/discount/migrations/0018_auto_20190827_0315.py b/saleor/discount/migrations/0018_auto_20190827_0315.py
new file mode 100644
index 0000000000..89a446b018
--- /dev/null
+++ b/saleor/discount/migrations/0018_auto_20190827_0315.py
@@ -0,0 +1,38 @@
+# Generated by Django 2.2.4 on 2019-08-27 08:15
+
+from django.db import migrations, models
+
+from saleor.discount import VoucherType
+
+
+def replace_removed_vocucher_type(apps, schema_editor):
+ cls = apps.get_model("discount", "Voucher")
+ cls.objects.filter(type="value").update(type=VoucherType.ENTIRE_ORDER)
+ cls.objects.filter(type__in=["category", "product", "collection"]).update(
+ type=VoucherType.SPECIFIC_PRODUCT
+ )
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [("discount", "0017_django_price_2")]
+
+ operations = [
+ migrations.RunPython(replace_removed_vocucher_type),
+ migrations.AlterField(
+ model_name="voucher",
+ name="type",
+ field=models.CharField(
+ choices=[
+ ("entire_order", "Entire order"),
+ ("shipping", "Shipping"),
+ (
+ "specific_product",
+ "Specific products, collections and categories",
+ ),
+ ],
+ default="entire_order",
+ max_length=20,
+ ),
+ ),
+ ]
diff --git a/saleor/discount/models.py b/saleor/discount/models.py
index 4c39b47aac..7817561552 100644
--- a/saleor/discount/models.py
+++ b/saleor/discount/models.py
@@ -104,24 +104,10 @@ class Voucher(models.Model):
return pgettext("Voucher type", "%(discount)s off shipping") % {
"discount": discount
}
- if self.type == VoucherType.PRODUCT:
- products = len(self.products.all())
- if products:
- return pgettext(
- "Voucher type", "%(discount)s off %(product_num)d products"
- ) % {"discount": discount, "product_num": products}
- if self.type == VoucherType.COLLECTION:
- collections = len(self.collections.all())
- if collections:
- return pgettext(
- "Voucher type", "%(discount)s off %(collections_num)d collections"
- ) % {"discount": discount, "collections_num": collections}
- if self.type == VoucherType.CATEGORY:
- categories = len(self.categories.all())
- if categories:
- return pgettext(
- "Voucher type", "%(discount)s off %(categories_num)d categories"
- ) % {"discount": discount, "categories_num": categories}
+ if self.type == VoucherType.SPECIFIC_PRODUCT:
+ return pgettext("Voucher type", "%(discount)s off specific products") % {
+ "discount": discount
+ }
return pgettext("Voucher type", "%(discount)s off") % {"discount": discount}
@property
diff --git a/saleor/graphql/discount/enums.py b/saleor/graphql/discount/enums.py
index e6c6808ade..7a8afe82a6 100644
--- a/saleor/graphql/discount/enums.py
+++ b/saleor/graphql/discount/enums.py
@@ -9,11 +9,7 @@ class DiscountValueTypeEnum(graphene.Enum):
class VoucherTypeEnum(graphene.Enum):
- PRODUCT = VoucherType.PRODUCT
- COLLECTION = VoucherType.COLLECTION
- CATEGORY = VoucherType.CATEGORY
SHIPPING = VoucherType.SHIPPING
- VALUE = VoucherType.VALUE
ENTIRE_ORDER = VoucherType.ENTIRE_ORDER
SPECIFIC_PRODUCT = VoucherType.SPECIFIC_PRODUCT
diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.py
index aae1e62551..e432cb19ec 100644
--- a/saleor/graphql/discount/mutations.py
+++ b/saleor/graphql/discount/mutations.py
@@ -154,10 +154,6 @@ class VoucherCreate(ModelMutation):
data["code"] = generate_promo_code()
elif not is_available_promo_code(code):
raise PromoCodeAlreadyExists()
- voucher_type = data.get("type", None)
- if voucher_type == VoucherTypeEnum.VALUE:
- data["type"] = VoucherTypeEnum.ENTIRE_ORDER.value
-
cleaned_input = super().clean_input(info, instance, data)
min_spent_amount = cleaned_input.pop("min_amount_spent", None)
diff --git a/tests/api/test_checkout_promo_codes.py b/tests/api/test_checkout_promo_codes.py
index 7ee58b593e..5895fbe91d 100644
--- a/tests/api/test_checkout_promo_codes.py
+++ b/tests/api/test_checkout_promo_codes.py
@@ -345,7 +345,7 @@ def test_checkout_add_products_voucher_code_checkout_with_sale(
checkout = checkout_with_item
product = checkout.lines.first().variant.product
voucher = voucher_percentage
- voucher.type = VoucherType.PRODUCT
+ voucher.type = VoucherType.SPECIFIC_PRODUCT
voucher.save()
voucher.products.add(product)
@@ -367,7 +367,7 @@ def test_checkout_add_collection_voucher_code_checkout_with_sale(
voucher = voucher_percentage
product = checkout.lines.first().variant.product
product.collections.add(collection)
- voucher.type = VoucherType.COLLECTION
+ voucher.type = VoucherType.SPECIFIC_PRODUCT
voucher.save()
voucher.collections.add(collection)
@@ -388,7 +388,7 @@ def test_checkout_add_category_code_checkout_with_sale(
checkout = checkout_with_item
category = checkout.lines.first().variant.product.category
voucher = voucher_percentage
- voucher.type = VoucherType.CATEGORY
+ voucher.type = VoucherType.SPECIFIC_PRODUCT
voucher.save()
voucher.categories.add(category)
diff --git a/tests/api/test_discount.py b/tests/api/test_discount.py
index a595e1b9c5..2149a7dad1 100644
--- a/tests/api/test_discount.py
+++ b/tests/api/test_discount.py
@@ -238,33 +238,6 @@ def test_create_voucher_with_empty_code(staff_api_client, permission_manage_disc
assert data["code"] != ""
-def test_create_voucher_with_deprecated_type(
- staff_api_client, permission_manage_discounts
-):
- start_date = timezone.now() - timedelta(days=365)
- end_date = timezone.now() + timedelta(days=365)
- variables = {
- "name": "test voucher",
- "type": VoucherTypeEnum.VALUE.name,
- "code": "",
- "discountValueType": DiscountValueTypeEnum.FIXED.name,
- "discountValue": 10.12,
- "minAmountSpent": 1.12,
- "startDate": start_date.isoformat(),
- "endDate": end_date.isoformat(),
- "usageLimit": 0,
- }
-
- response = staff_api_client.post_graphql(
- CREATE_VOUCHER_MUTATION, variables, permissions=[permission_manage_discounts]
- )
- content = get_graphql_content(response)
- data = content["data"]["voucherCreate"]["voucher"]
- assert data["name"] == variables["name"]
- assert data["code"] != ""
- assert data["type"] == VoucherTypeEnum.ENTIRE_ORDER.name
-
-
def test_create_voucher_with_existing_gift_card_code(
staff_api_client, gift_card, permission_manage_discounts
):
diff --git a/tests/dashboard/test_discounts.py b/tests/dashboard/test_discounts.py
index f4c4421eee..4f20753060 100644
--- a/tests/dashboard/test_discounts.py
+++ b/tests/dashboard/test_discounts.py
@@ -200,7 +200,7 @@ def test_product_voucher_checkout_discount_raises_not_applicable(
discounted_product = product_with_images
voucher = Voucher(
code="unique",
- type=VoucherType.PRODUCT,
+ type=VoucherType.SPECIFIC_PRODUCT,
discount_value_type=DiscountValueType.FIXED,
discount_value=10,
)
@@ -217,7 +217,7 @@ def test_category_voucher_checkout_discount_raises_not_applicable(order_with_lin
discounted_collection = Collection.objects.create(name="Discounted", slug="discou")
voucher = Voucher(
code="unique",
- type=VoucherType.COLLECTION,
+ type=VoucherType.SPECIFIC_PRODUCT,
discount_value_type=DiscountValueType.FIXED,
discount_value=10,
)
@@ -244,7 +244,7 @@ def test_ajax_voucher_list(admin_client, voucher):
@pytest.mark.parametrize(
- "voucher_type", ["collection", "category", "product", "entire_order", "shipping"]
+ "voucher_type", ["specific_product", "entire_order", "shipping"]
)
def test_voucher_form_min_spent_amount_is_changed_on_edit(
admin_client, product, collection, voucher_type
@@ -262,20 +262,10 @@ def test_voucher_form_min_spent_amount_is_changed_on_edit(
"product-products": [product.pk],
"category-categories": [product.category.pk],
"collection-collections": [collection.pk],
- "shipping-min_spent_0": "400",
- "product-min_spent_0": "400",
- "category-min_spent_0": "400",
- "collection-min_spent_0": "400",
- "value-min_spent_0": "400",
- "shipping-min_spent_1": "USD",
- "product-min_spent_1": "USD",
- "category-min_spent_1": "USD",
- "collection-min_spent_1": "USD",
- "value-min_spent_1": "USD",
- "entire_order-min_spent_1": "USD",
}
data["{}-min_spent_0".format(voucher_type)] = "800"
+ data["{}-min_spent_1".format(voucher_type)] = "USD"
response = admin_client.post(url, data, follow=True)
diff --git a/tests/test_cart.py b/tests/test_cart.py
index 313a0bfc80..14910cb4b1 100644
--- a/tests/test_cart.py
+++ b/tests/test_cart.py
@@ -294,18 +294,6 @@ def test_checkout_counter(monkeypatch):
assert ret == {"checkout_counter": 4}
-def test_get_prices_of_discounted_products(checkout_with_item):
- discounted_line = checkout_with_item.lines.first()
- discounted_product = discounted_line.variant.product
- prices = utils.get_prices_of_discounted_products(
- checkout_with_item, [discounted_product]
- )
- excepted_value = [
- discounted_line.variant.get_price() for item in range(discounted_line.quantity)
- ]
- assert list(prices) == excepted_value
-
-
def test_get_prices_of_discounted_specific_product(
checkout_with_item, collection, voucher_specific_product_type
):
@@ -678,20 +666,6 @@ def test_checkout_line_state(product, checkout_with_single_item):
assert line.quantity == 2
-def test_get_prices_of_products_in_discounted_collections(
- collection, product, checkout_with_item
-):
- discounted_line = checkout_with_item.lines.first()
- assert discounted_line.variant.product == product
- product.collections.add(collection)
- result = utils.get_prices_of_products_in_discounted_collections(
- checkout_with_item, [collection]
- )
- assert list(result) == [
- discounted_line.variant.get_price() for item in range(discounted_line.quantity)
- ]
-
-
def test_update_view_must_be_ajax(customer_user, rf):
request = rf.post(reverse("home"))
request.user = customer_user
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index 96f8805575..d71a01e7c8 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -21,7 +21,6 @@ from saleor.checkout.utils import (
clear_shipping_method,
create_order,
get_checkout_context,
- get_prices_of_products_in_discounted_categories,
get_shipping_price_estimate,
get_voucher_discount_for_checkout,
get_voucher_for_checkout,
@@ -37,7 +36,6 @@ from saleor.discount.models import NotApplicable, Voucher
from saleor.extensions.manager import ExtensionsManager, get_extensions_manager
from saleor.order import OrderEvents, OrderEventsEmails
from saleor.order.models import OrderEvent
-from saleor.product.models import Category
from saleor.shipping.models import ShippingZone
from .utils import get_redirect_location
@@ -889,7 +887,7 @@ def test_get_voucher_discount_for_checkout_voucher_validation(
("99", 9, 10, DiscountValueType.PERCENTAGE, 100, 10),
],
)
-def test_get_discount_for_checkout_value_voucher_not_applicable(
+def test_get_discount_for_checkout_entire_order_voucher_not_applicable(
total,
total_quantity,
discount_value,
@@ -1186,57 +1184,6 @@ def test_get_discount_for_checkout_shipping_voucher_not_applicable(
assert str(e.value) == error_msg
-def test_get_discount_for_checkout_product_voucher_not_applicable(monkeypatch):
- discounts = []
-
- monkeypatch.setattr(
- ExtensionsManager,
- "calculate_checkout_subtotal",
- Mock(return_value=TaxedMoney(net=Money("1", "USD"), gross=Money("1", "USD"))),
- )
- monkeypatch.setattr(
- "saleor.checkout.utils.get_prices_of_discounted_products",
- lambda checkout, discounts, product: [],
- )
- voucher = Voucher(
- code="unique",
- type=VoucherType.PRODUCT,
- discount_value_type=DiscountValueType.FIXED,
- discount_value=10,
- )
- voucher.save()
- checkout = Mock()
-
- with pytest.raises(NotApplicable) as e:
- get_voucher_discount_for_checkout(voucher, checkout, discounts)
- assert str(e.value) == "This offer is only valid for selected items."
-
-
-def test_get_discount_for_checkout_collection_voucher_not_applicable(monkeypatch):
- discounts = []
- monkeypatch.setattr(
- ExtensionsManager,
- "calculate_checkout_subtotal",
- Mock(return_value=TaxedMoney(net=Money("1", "USD"), gross=Money("1", "USD"))),
- )
- monkeypatch.setattr(
- "saleor.checkout.utils.get_prices_of_products_in_discounted_collections", # noqa
- lambda checkout, discounts, product: [],
- )
- voucher = Voucher(
- code="unique",
- type=VoucherType.COLLECTION,
- discount_value_type=DiscountValueType.FIXED,
- discount_value=10,
- )
- voucher.save()
- checkout = Mock()
-
- with pytest.raises(NotApplicable) as e:
- get_voucher_discount_for_checkout(voucher, checkout, discounts)
- assert str(e.value) == "This offer is only valid for selected items."
-
-
def test_checkout_voucher_form_invalid_voucher_code(
monkeypatch, request_checkout_with_item
):
@@ -1505,23 +1452,6 @@ def test_change_address_in_checkout_from_user_address_to_other(
assert Address.objects.filter(id=address_id).exists()
-def test_get_prices_of_products_in_discounted_categories(checkout_with_item, category):
- lines = checkout_with_item.lines.all()
- discounted_lines = get_prices_of_products_in_discounted_categories(
- checkout_with_item, [category]
- )
- assert [
- line.variant.get_price() for line in lines for item in range(line.quantity)
- ] == discounted_lines
-
- discounted_category = Category.objects.create(name="discounted", slug="discounted")
- discounted_lines = get_prices_of_products_in_discounted_categories(
- checkout_with_item, [discounted_category]
- )
- # None of the lines are belongs to the discounted category
- assert not discounted_lines
-
-
def test_add_voucher_to_checkout(checkout_with_item, voucher):
assert checkout_with_item.voucher_code is None
add_voucher_to_checkout(checkout_with_item, voucher)
diff --git a/tests/test_discounts.py b/tests/test_discounts.py
index 00f1c1dd23..3992d2c5b1 100644
--- a/tests/test_discounts.py
+++ b/tests/test_discounts.py
@@ -90,7 +90,7 @@ def test_voucher_queryset_active(voucher):
([10, 10, 10], 5, DiscountValueType.FIXED, False, 15),
],
)
-def test_products_voucher_checkout_discount_not(
+def test_specific_products_voucher_checkout_discount(
monkeypatch,
prices,
discount_value,
@@ -101,14 +101,14 @@ def test_products_voucher_checkout_discount_not(
):
discounts = []
monkeypatch.setattr(
- "saleor.checkout.utils.get_prices_of_discounted_products",
+ "saleor.checkout.utils.get_prices_of_discounted_specific_product",
lambda lines, discounts, discounted_products: (
Money(price, "USD") for price in prices
),
)
voucher = Voucher(
code="unique",
- type=VoucherType.PRODUCT,
+ type=VoucherType.SPECIFIC_PRODUCT,
discount_value_type=discount_type,
discount_value=discount_value,
apply_once_per_order=apply_once_per_order,