Skip to content

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

Remove unused code from core, product and seo schema

IKarbowiak99946d5b9105
diff --git a/saleor/core/utils/filters.py b/saleor/core/utils/filters.py
deleted file mode 100644
index 7ebac07310..0000000000
--- a/saleor/core/utils/filters.py
+++ /dev/null
@@ -1,7 +0,0 @@
-def get_now_sorted_by(filter_set, default_sort="name"):
- sort_by = filter_set.form.cleaned_data.get("sort_by")
- if sort_by:
- sort_by = sort_by[0].strip("-")
- else:
- sort_by = default_sort
- return sort_by
diff --git a/saleor/product/utils/__init__.py b/saleor/product/utils/__init__.py
index ed9e5e8127..9be41df7d6 100644
--- a/saleor/product/utils/__init__.py
+++ b/saleor/product/utils/__init__.py
@@ -7,18 +7,14 @@ from django.db.models import F
from ...core.taxes import TaxedMoney, zero_taxed_money
from ..tasks import update_products_minimal_variant_prices_task
-from .availability import products_with_availability
if TYPE_CHECKING:
# flake8: noqa
from datetime import date, datetime
from django.db.models.query import QuerySet
- from django.http import HttpRequest
- from ...account.models import User
- from ..models import Product, ProductVariant, Collection, ProductImage, Category
- from ..filters import ProductCategoryFilter
+ from ..models import Product, ProductVariant, Category
def allocate_stock(variant: "ProductVariant", quantity: int):
diff --git a/saleor/product/utils/availability.py b/saleor/product/utils/availability.py
index ffa93f0e3a..35bc435f9e 100644
--- a/saleor/product/utils/availability.py
+++ b/saleor/product/utils/availability.py
@@ -12,8 +12,7 @@ from ...extensions.manager import get_extensions_manager
from .. import ProductAvailabilityStatus, VariantAvailabilityStatus
if TYPE_CHECKING:
- from django.db.models.query import QuerySet
-
+ # flake8: noqa
from ...extensions.manager import ExtensionsManager
@@ -39,22 +38,6 @@ class VariantAvailability:
discount_local_currency: Optional[TaxedMoney]
-def products_with_availability(
- products: "QuerySet[Product]",
- discounts,
- country: str,
- local_currency: str,
- extensions: "ExtensionsManager",
-):
- for product in products:
- yield (
- product,
- get_product_availability(
- product, discounts, country, local_currency, extensions=extensions
- ),
- )
-
-
def get_product_availability_status(product: "Product") -> ProductAvailabilityStatus:
is_visible = product.is_visible
are_all_variants_in_stock = all(
diff --git a/saleor/seo/schema/product.py b/saleor/seo/schema/product.py
index ca8e9cd4ed..a92ff41d1f 100644
--- a/saleor/seo/schema/product.py
+++ b/saleor/seo/schema/product.py
@@ -1,51 +1,7 @@
-from typing import Optional
-
-from django.db.models import Q, QuerySet
-from django.utils.encoding import smart_text
-
-from ...product.models import Product
-
IN_STOCK = "http://schema.org/InStock"
OUT_OF_STOCK = "http://schema.org/OutOfStock"
-BRAND_SLUGS = ["brand", "publisher"]
-
-
-def get_brand_from_attributes(attributes: QuerySet) -> Optional[str]:
- qs_filter_conditions = Q(assignment__attribute__slug__in=BRAND_SLUGS)
- qs = attributes.filter(qs_filter_conditions).prefetch_related("values")
- attribute = qs.first()
- if attribute is not None:
- return ", ".join([str(value) for value in attribute.values.all()])
- return None
-
-
-def product_json_ld(product: Product):
- """Generate JSON-LD data for product."""
- data = {
- "@context": "http://schema.org/",
- "@type": "Product",
- "name": smart_text(product),
- "image": [product_image.image.url for product_image in product.images.all()],
- "description": product.plain_text_description,
- "offers": [],
- }
-
- for variant in product.variants.all():
- price = variant.get_price()
- in_stock = True
- if not product.is_visible or not variant.is_in_stock():
- in_stock = False
- variant_data = variant_json_ld(price, variant, in_stock)
- data["offers"].append(variant_data)
-
- brand = get_brand_from_attributes(product.attributes)
- if brand:
- data["brand"] = {"@type": "Thing", "name": brand}
- return data
-
-
def variant_json_ld(price, variant, in_stock):
schema_data = {
"@type": "Offer",
diff --git a/tests/test_discounts.py b/tests/test_discounts.py
index e134bc5fc2..c6f71406b5 100644
--- a/tests/test_discounts.py
+++ b/tests/test_discounts.py
@@ -7,6 +7,7 @@ from prices import Money
from saleor.checkout.utils import get_voucher_discount_for_checkout
from saleor.discount import DiscountInfo, DiscountValueType, VoucherType
from saleor.discount.models import NotApplicable, Sale, Voucher, VoucherCustomer
+from saleor.discount.templatetags.voucher import discount_as_negative
from saleor.discount.utils import (
add_voucher_usage_by_customer,
decrease_voucher_usage,
@@ -307,3 +308,21 @@ def test_sale_active(current_date, start_date, end_date, is_active):
)
sale_is_active = Sale.objects.active(date=current_date).exists()
assert is_active == sale_is_active
+
+
+def test_discount_as_negative():
+ discount = Money(10, "USD")
+ result = discount_as_negative(discount)
+ assert result == "-$10.00"
+
+
+def test_discount_as_negative_for_zero_value():
+ discount = Money(0, "USD")
+ result = discount_as_negative(discount)
+ assert result == "$0.00"
+
+
+def test_discount_as_negative_for_html():
+ discount = Money(10, "USD")
+ result = discount_as_negative(discount, True)
+ assert result == '-<span class="currency">$</span>10.00'
diff --git a/tests/test_seo_schema.py b/tests/test_seo_schema.py
index a0eac4712d..f54f134b03 100644
--- a/tests/test_seo_schema.py
+++ b/tests/test_seo_schema.py
@@ -2,15 +2,11 @@ import json
import pytest
-from saleor.product import AttributeInputType
-from saleor.product.models import Attribute, AttributeValue
-from saleor.product.utils.attributes import associate_attribute_values_to_instance
from saleor.seo.schema.email import (
get_order_confirmation_markup,
get_organization,
get_product_data,
)
-from saleor.seo.schema.product import get_brand_from_attributes
def test_get_organization(site_settings):
@@ -55,35 +51,3 @@ def test_get_order_confirmation_markup(order_with_lines):
json.loads(result)
except ValueError:
pytest.fail("Response is not a valid json")
-
-
-def test_get_brand_from_attributes(product):
- attribute = Attribute.objects.create(
- slug="brand", name="Brand", input_type=AttributeInputType.MULTISELECT
- )
- product.product_type.product_attributes.add(attribute)
-
- # Set the brand attribute as a multi-value attribute
- attribute.input_type = AttributeInputType.MULTISELECT
- attribute.save(update_fields=["input_type"])
-
- # Add some brands names
- brands = AttributeValue.objects.bulk_create(
- [
- AttributeValue(attribute=attribute, name="Saleor", slug="saleor"),
- AttributeValue(attribute=attribute, name="Mirumee", slug="mirumee"),
- ]
- )
-
- # Associate the brand names to the product
- associate_attribute_values_to_instance(product, attribute, *tuple(brands))
-
- # Retrieve the brand names from the product attributes
- brand_names_str = get_brand_from_attributes(product.attributes)
- assert brand_names_str == "Saleor, Mirumee"
-
-
-def test_get_brand_from_attributes_no_brand_associated(product):
- # Retrieve the brand names from the product attributes
- brand_names_str = get_brand_from_attributes(product.attributes)
- assert brand_names_str is None