Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve code
Anna Siwik18801d2e3cfd
diff --git a/saleor/discount/models.py b/saleor/discount/models.pyindex f21e260c03..2e117026a3 100644--- a/saleor/discount/models.py+++ b/saleor/discount/models.py@@ -11,8 +11,6 @@ from django_prices.models import PriceFieldfrom django_prices.templatetags.prices_i18n import netfrom prices import FixedDiscount, Price, percentage_discount-from ..cart.utils import (- get_category_variants_and_prices, get_product_variants_and_prices)from . import DiscountValueType, VoucherApplyToProduct, VoucherType@@ -63,12 +61,6 @@ class Voucher(models.Model):objects = VoucherQueryset.as_manager()- @property- def is_free(self):- return (- self.discount_value == Decimal(100) and- self.discount_value_type == DiscountValueType.PERCENTAGE)-class Meta:permissions = (('view_voucher',@@ -100,6 +92,12 @@ class Voucher(models.Model):return pgettext('Voucher type', '%(discount)s off') % {'discount': discount}+ @property+ def is_free(self):+ return (+ self.discount_value == Decimal(100) and+ self.discount_value_type == DiscountValueType.PERCENTAGE)+def get_apply_to_display(self):if self.type == VoucherType.SHIPPING and self.apply_to:return countries.name(self.apply_to)@@ -113,8 +111,8 @@ class Voucher(models.Model):def get_fixed_discount_for(self, amount):if self.discount_value_type == DiscountValueType.FIXED:- discount_price = Price(net=self.discount_value,- currency=settings.DEFAULT_CURRENCY)+ discount_price = Price(+ net=self.discount_value, currency=settings.DEFAULT_CURRENCY)discount = FixedDiscount(amount=discount_price, name=smart_text(self))elif self.discount_value_type == DiscountValueType.PERCENTAGE:@@ -130,7 +128,7 @@ class Voucher(models.Model):return discountdef validate_limit(self, value):- limit = self.limit if self.limit is not None else value+ limit = self.limit or valueif value < limit:msg = pgettext('Voucher not applicable',diff --git a/saleor/discount/utils.py b/saleor/discount/utils.pyindex 03dae42a51..e0b46c72f9 100644--- a/saleor/discount/utils.py+++ b/saleor/discount/utils.py@@ -21,7 +21,7 @@ def decrease_voucher_usage(voucher):voucher.save(update_fields=['used'])-def get_product_discounts(product, discounts, **kwargs):+def get_product_discounts(product, discounts):for discount in discounts:try:yield get_product_discount_on_sale(discount, product)@@ -29,10 +29,10 @@ def get_product_discounts(product, discounts, **kwargs):pass-def calculate_discounted_price(product, price, discounts, **kwargs):+def calculate_discounted_price(product, price, discounts):if discounts:discounts = list(- get_product_discounts(product, discounts, **kwargs))+ get_product_discounts(product, discounts))if discounts:price = min(price | discount for discount in discounts)return pricediff --git a/saleor/product/models.py b/saleor/product/models.pyindex 4402ac0ec0..d291559711 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -159,8 +159,7 @@ class Product(models.Model, ItemRange):def get_price_range(self, discounts=None, **kwargs):if self.variants.exists():return super().get_price_range(discounts=discounts, **kwargs)- price = calculate_discounted_price(- self, self.price, discounts, **kwargs)+ price = calculate_discounted_price(self, self.price, discounts)return PriceRange(price, price)def get_gross_price_range(self, **kwargs):@@ -198,8 +197,7 @@ class ProductVariant(models.Model, Item):def get_price_per_item(self, discounts=None, **kwargs):price = self.price_override or self.product.price- price = calculate_discounted_price(self.product, price, discounts,- **kwargs)+ price = calculate_discounted_price(self.product, price, discounts)return pricedef get_absolute_url(self):