Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add categories limit in discounts
Artur Smętb596c5044d5a
diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex 43cd3610bc..ab134019be 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -5,4 +5,5 @@ from ...product.models import FixedProductDiscountclass FixedProductDiscountForm(forms.ModelForm):class Meta:model = FixedProductDiscount- fields = ['name', 'products', 'discount', 'percentage_discount']+ fields = ['name', 'products', 'categories',+ 'discount', 'percentage_discount']diff --git a/saleor/dashboard/templates/dashboard/discount/list.html b/saleor/dashboard/templates/dashboard/discount/list.htmlindex 47c916b7b4..2de8deaf29 100644--- a/saleor/dashboard/templates/dashboard/discount/list.html+++ b/saleor/dashboard/templates/dashboard/discount/list.html@@ -33,7 +33,12 @@<li class="collection-item list-item list--attributes-item list-item--two-lines"><a class="list-item-name" href="{% url 'dashboard:discount-update' pk=discount.pk %}">{{ discount }}</a><p class="list-item-desc">- {% gross discount.discount %}+ {% if discount.discount %}+ {% gross discount.discount %}+ {% endif %}+ {% if discount.percentage_discount %}+ {{ discount.percentage_discount }} %+ {% endif %}</p></li>{% endfor %}diff --git a/saleor/product/migrations/0008_fixedproductdiscount_categories.py b/saleor/product/migrations/0008_fixedproductdiscount_categories.pynew file mode 100644index 0000000000..fb1f786318--- /dev/null+++ b/saleor/product/migrations/0008_fixedproductdiscount_categories.py@@ -0,0 +1,20 @@+# -*- coding: utf-8 -*-+# Generated by Django 1.9.1 on 2016-01-12 14:43+from __future__ import unicode_literals++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ('product', '0007_auto_20160112_0623'),+ ]++ operations = [+ migrations.AddField(+ model_name='fixedproductdiscount',+ name='categories',+ field=models.ManyToManyField(blank=True, to='product.Category'),+ ),+ ]diff --git a/saleor/product/models/discounts.py b/saleor/product/models/discounts.pyindex 3be0c5b2e9..34d49bb194 100644--- a/saleor/product/models/discounts.py+++ b/saleor/product/models/discounts.py@@ -17,6 +17,7 @@ class NotApplicable(ValueError):class FixedProductDiscount(models.Model):name = models.CharField(max_length=255)products = models.ManyToManyField('Product', blank=True)+ categories = models.ManyToManyField('Category', blank=True)discount = PriceField(pgettext_lazy('Discount field', 'discount value'),currency=settings.DEFAULT_CURRENCY,max_digits=12, decimal_places=2, null=True,@@ -46,10 +47,13 @@ class FixedProductDiscount(models.Model):from ...product.models import ProductVariantif isinstance(variant, ProductVariant):pk = variant.product.pk+ categories = variant.product.categories.all()else:pk = variant.pk+ categories = variant.categories.all()check_price = variant.get_price_per_item()- if not self.products.filter(pk=pk).exists():+ if not (self.products.filter(pk=pk).exists() and+ any(c in self.categories.all() for c in categories)):raise NotApplicable('Discount not applicable for this product')discount = self.get_discount()after_discount = discount.apply(check_price)