Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Docstrings, extra test, help texts, labels
Pacu2c44682a3e5d0
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex 57108f7932..ad5afb35d0 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -75,6 +75,7 @@ def remove_unavailable_variants(cart):def get_variant_prices_from_lines(lines):+ """Get's price of each individual item within the lines."""return [line.variant.get_price()for line in lines@@ -82,7 +83,7 @@ def get_variant_prices_from_lines(lines):def get_prices_of_discounted_products(lines, discounted_products):- """Get variants and unit prices from cart lines matching the product."""+ """Get prices of variants belonging to the discounted products."""# If there's no discounted_products,# it means that all products are discountedif discounted_products:@@ -94,11 +95,7 @@ def get_prices_of_discounted_products(lines, discounted_products):def get_prices_of_products_in_discounted_collections(lines, discounted_collections):- """Get variants and unit prices from cart lines matching the category.-- Product is assumed to be in the category if it belongs to any of its- descendant subcategories.- """+ """Get prices of variants belonging to the discounted collections."""# If there's no discounted collections,# it means that all of them are discountedif discounted_collections:@@ -113,10 +110,10 @@ def get_prices_of_products_in_discounted_collections(def get_prices_of_products_in_discounted_categories(lines, discounted_categories):- """Get variants and unit prices from cart lines matching the category.+ """Get prices of variants belonging to the discounted categories.- Product is assumed to be in the category if it belongs to any of its- descendant subcategories.+ 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@@ -667,7 +664,8 @@ def _get_shipping_voucher_discount_for_cart(voucher, cart):def _get_products_voucher_discount(order_or_cart, voucher):- """Calculate discount value for a voucher of product or category type."""+ """Calculate products discount value for a voucher, depending on its type.+ """if voucher.type == VoucherType.PRODUCT:prices = get_prices_of_discounted_products(order_or_cart.lines.all(), voucher.products.all())diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex 541fe87225..f8935485be 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -15,6 +15,13 @@ from ...product.models import Category, Productfrom ...shipping.models import ShippingMethodCountryfrom ..forms import AjaxSelect2MultipleChoiceField+MinAmountSpent = MoneyField(+ min_value=ZERO_MONEY, required=False,+ currency=settings.DEFAULT_CURRENCY,+ label=pgettext_lazy(+ 'Lowest value for order to be able to use the voucher',+ 'Apply only if the purchase value is greater than or equal to'))+class SaleForm(forms.ModelForm):products = AjaxSelect2MultipleChoiceField(@@ -132,13 +139,7 @@ def country_choices():class ShippingVoucherForm(forms.ModelForm):-- min_amount_spent = MoneyField(- min_value=ZERO_MONEY, required=False,- currency=settings.DEFAULT_CURRENCY,- label=pgettext_lazy(- 'Lowest value for order to be able to use the voucher',- 'Apply only if the purchase value is greater than or equal to'))+ min_amount_spent = MinAmountSpentcountries = forms.MultipleChoiceField(choices=country_choices,required=False,@@ -150,18 +151,9 @@ class ShippingVoucherForm(forms.ModelForm):model = Voucherfields = ['countries', 'min_amount_spent']- def save(self, commit=True):- return super().save(commit)-class ValueVoucherForm(forms.ModelForm):-- min_amount_spent = MoneyField(- min_value=ZERO_MONEY, required=False,- currency=settings.DEFAULT_CURRENCY,- label=pgettext_lazy(- 'Lowest value for order to be able to use the voucher',- 'Apply only if the purchase value is greater than or equal to'))+ min_amount_spent = MinAmountSpentclass Meta:model = Voucher@@ -175,8 +167,17 @@ class ValueVoucherForm(forms.ModelForm):class CommonVoucherForm(forms.ModelForm):-use_required_attribute = False+ min_amount_spent = MinAmountSpent+ apply_once_per_order = forms.BooleanField(+ required=False,+ label=pgettext_lazy(+ 'Field label, apply discount value only once per order',+ 'Only apply once per order'),+ help_text=pgettext_lazy(+ 'Help text of checkbox for applying discount only once per order',+ 'If unchecked, discount value will be taken '+ 'off each suitable item in an order.'))class ProductVoucherForm(CommonVoucherForm):diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.pyindex fd6c9df4ab..f766062a52 100644--- a/saleor/dashboard/order/utils.py+++ b/saleor/dashboard/order/utils.py@@ -3,8 +3,7 @@ from django.contrib.sites.shortcuts import get_current_sitefrom django.template.loader import get_templatefrom ...checkout import AddressType-from ...checkout.utils import (- _get_products_voucher_discount)+from ...checkout.utils import _get_products_voucher_discountfrom ...core.utils.taxes import ZERO_MONEYfrom ...discount import VoucherTypefrom ...discount.utils import (diff --git a/saleor/discount/models.py b/saleor/discount/models.pyindex 202f94309e..abc01f00c2 100644--- a/saleor/discount/models.py+++ b/saleor/discount/models.py@@ -131,7 +131,7 @@ class Voucher(models.Model):'Voucher not applicable','This offer is only valid for orders over %(amount)s.')raise NotApplicable(- msg % { 'amount': amount(min_amount_spent)},+ msg % {'amount': amount(min_amount_spent)},min_amount_spent=min_amount_spent)diff --git a/tests/test_checkout.py b/tests/test_checkout.pyindex 45487779df..eee1848405 100644--- a/tests/test_checkout.py+++ b/tests/test_checkout.py@@ -618,7 +618,6 @@ def test_get_discount_for_cart_product_voucher_not_applicable(monkeypatch):assert str(e.value) == 'This offer is only valid for selected items.'-# FIXMEdef test_get_discount_for_cart_collection_voucher_not_applicable(monkeypatch):monkeypatch.setattr('saleor.checkout.utils.get_prices_of_products_in_discounted_collections', # noqadiff --git a/tests/test_discounts.py b/tests/test_discounts.pyindex 28e01ff4f5..52d52256d5 100644--- a/tests/test_discounts.py+++ b/tests/test_discounts.py@@ -212,3 +212,17 @@ def test_get_voucher_discount_all_products(voucher.save()discount = get_products_voucher_discount(voucher, prices)assert discount == Money(expected_value, 'USD')++[email protected]('current_date, is_active', (+ (date.today(), True),+ (date.today() + timedelta(days=1), True),+ (date.today() + timedelta(days=2), False),+ (date.today() - timedelta(days=2), False)))+def test_sale_active(current_date, is_active):+ Sale.objects.create(+ type=DiscountValueType.FIXED,+ value=5, start_date=date.today(),+ end_date=date.today() + timedelta(days=1))+ sale_is_active = Sale.objects.active(date=current_date).exists()+ assert is_active == sale_is_active