Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix discount calculation logic
Artur Smęt784cd71fe24b
diff --git a/saleor/product/models/discounts.py b/saleor/product/models/discounts.pyindex 2853305c0a..a1abf780be 100644--- a/saleor/product/models/discounts.py+++ b/saleor/product/models/discounts.py@@ -31,9 +31,16 @@ class FixedProductDiscount(models.Model):return self.namedef modifier_for_product(self, variant):- if not self.products.filter(pk=variant.product.pk).exists():+ from ...product.models import ProductVariant+ if isinstance(variant, ProductVariant):+ pk = variant.product.pk+ check_price = variant.get_price_per_item()+ else:+ pk = variant.pk+ check_price = variant.get_price_per_item(variant)+ if not self.products.filter(pk=pk).exists():raise NotApplicable('Discount not applicable for this product')- if self.discount > variant.get_price(discounted=False):+ if self.discount > check_price:raise NotApplicable('Discount too high for this product')return FixedDiscount(self.discount, name=self.name)