aboutsummaryrefslogtreecommitdiff
path: root/saleor/discount
diff options
context:
space:
mode:
authorArtur Smęt <artur.smet@mirumee.com>2016-10-12 09:31:03 +0200
committerArtur Smęt <artur.smet@mirumee.com>2016-10-12 09:31:52 +0200
commitcffe3db3073ec54f437e3ef26815c57787db1679 (patch)
tree262c6b012183deb93b0db4d148018c3fbc7abd3b /saleor/discount
parent65748447458adccb77a5107330c08a061f473a1b (diff)
downloadsaleor-frontend-cffe3db3073ec54f437e3ef26815c57787db1679.tar.gz
saleor-frontend-cffe3db3073ec54f437e3ef26815c57787db1679.tar.bz2
saleor-frontend-cffe3db3073ec54f437e3ef26815c57787db1679.zip
Fix variants filter in discounts
Diffstat (limited to 'saleor/discount')
-rw-r--r--saleor/discount/models.py3
-rw-r--r--saleor/discount/test_discounts.py17
2 files changed, 18 insertions, 2 deletions
diff --git a/saleor/discount/models.py b/saleor/discount/models.py
index 7f4d8ed0..77d58642 100644
--- a/saleor/discount/models.py
+++ b/saleor/discount/models.py
@@ -265,10 +265,9 @@ class Sale(models.Model):
return False
def modifier_for_variant(self, variant):
- check_price = variant.get_price_per_item()
discounted_products = [p.pk for p in self.products.all()]
discounted_categories = list(self.categories.all())
- if discounted_products and variant.pk not in discounted_products:
+ if discounted_products and variant.product.pk not in discounted_products:
raise NotApplicable('Discount not applicable for this product')
if (discounted_categories and not
self._product_has_category_discount(
diff --git a/saleor/discount/test_discounts.py b/saleor/discount/test_discounts.py
index ed8198ab..78e7fc66 100644
--- a/saleor/discount/test_discounts.py
+++ b/saleor/discount/test_discounts.py
@@ -206,3 +206,20 @@ def test_products_voucher_checkout_discount_not(settings, monkeypatch, prices,
checkout = Mock(cart=Mock())
discount = voucher.get_discount_for_checkout(checkout)
assert discount.amount == Price(expected_value, currency='USD')
+
+
+@pytest.mark.django_db
+def test_sale_applies_to_correct_products():
+ product = Product.objects.create(name='Test Product', price=10, weight=1,
+ description='', pk=10)
+ variant = ProductVariant.objects.create(product=product, sku='firstvar')
+ product2 = Product.objects.create(name='Second product', price=15, weight=1,
+ description='')
+ sec_variant = ProductVariant.objects.create(product=product2, sku='secvar',
+ pk=10)
+ sale = Sale.objects.create(name='Test sale', value=5, type=Sale.FIXED)
+ sale.products.add(product)
+ assert product2 not in sale.products.all()
+ assert sale.modifier_for_variant(variant).amount == Price(net=5, currency='USD')
+ with pytest.raises(NotApplicable):
+ sale.modifier_for_variant(sec_variant)