summaryrefslogtreecommitdiff
path: root/saleor/discount
diff options
context:
space:
mode:
authorMichaƂ Ociepka <michal@ociepka.info>2016-02-04 19:54:49 +0100
committerPatryk Zawadzki <patrys@room-303.com>2016-02-08 12:05:30 +0100
commit4da8f9a0c8ea12c1a339ac58a4e67959dec5eb99 (patch)
treeac00231aaa41275f94ded85e2edfa8f1b1de94a9 /saleor/discount
parent335d994e95517f7635219a17348a97abbdb7d1ea (diff)
downloadsaleor-frontend-4da8f9a0c8ea12c1a339ac58a4e67959dec5eb99.tar.gz
saleor-frontend-4da8f9a0c8ea12c1a339ac58a4e67959dec5eb99.tar.bz2
saleor-frontend-4da8f9a0c8ea12c1a339ac58a4e67959dec5eb99.zip
Add voucher model
Diffstat (limited to 'saleor/discount')
-rw-r--r--saleor/discount/migrations/0002_voucher.py38
-rw-r--r--saleor/discount/models.py62
2 files changed, 98 insertions, 2 deletions
diff --git a/saleor/discount/migrations/0002_voucher.py b/saleor/discount/migrations/0002_voucher.py
new file mode 100644
index 00000000..4c599e28
--- /dev/null
+++ b/saleor/discount/migrations/0002_voucher.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.1 on 2016-02-04 17:07
+from __future__ import unicode_literals
+
+import datetime
+from django.db import migrations, models
+import django.db.models.deletion
+import django_prices.models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('product', '0010_auto_20160129_0826'),
+ ('discount', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Voucher',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('type', models.CharField(choices=[('product', 'Product'), ('category', 'Category'), ('shipping', 'Shipping'), ('basket', 'Baskets over')], max_length=20)),
+ ('name', models.CharField(blank=True, max_length=255, null=True)),
+ ('code', models.CharField(db_index=True, max_length=12, unique=True)),
+ ('usage_limit', models.PositiveIntegerField(blank=True, help_text='Unlimited if empty', null=True)),
+ ('used', models.PositiveIntegerField(default=0, editable=False)),
+ ('start_date', models.DateField(default=datetime.date.today)),
+ ('end_date', models.DateField(blank=True, help_text='Never expire if empty', null=True)),
+ ('discount_value_type', models.CharField(choices=[('fixed', 'USD'), ('percentage', '%')], default='fixed', max_length=10)),
+ ('discount_value', models.DecimalField(decimal_places=2, max_digits=12)),
+ ('apply_to', models.CharField(blank=True, max_length=20, null=True)),
+ ('limit', django_prices.models.PriceField(blank=True, currency='USD', decimal_places=2, max_digits=12, null=True)),
+ ('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='product.Category')),
+ ('product', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='product.Product')),
+ ],
+ ),
+ ]
diff --git a/saleor/discount/models.py b/saleor/discount/models.py
index b5096ec7..3dca6980 100644
--- a/saleor/discount/models.py
+++ b/saleor/discount/models.py
@@ -1,9 +1,11 @@
from __future__ import unicode_literals
+from datetime import date
from django.conf import settings
from django.db import models
from django.utils.translation import pgettext_lazy
from django.utils.encoding import python_2_unicode_compatible
+from django_prices.models import PriceField
from prices import FixedDiscount, percentage_discount, Price
@@ -12,13 +14,69 @@ class NotApplicable(ValueError):
@python_2_unicode_compatible
+class Voucher(models.Model):
+
+ APPLY_TO_ONE_PRODUCT = 'one'
+ APPLY_TO_ALL_PRODUCTS = 'all'
+
+ DISCOUNT_VALUE_FIXED = 'fixed'
+ DISCOUNT_VALUE_PERCENTAGE = 'percentage'
+
+ DISCOUNT_VALUE_TYPE_CHOICES = (
+ (DISCOUNT_VALUE_FIXED, pgettext_lazy('voucher_model', settings.DEFAULT_CURRENCY)), # noqa
+ (DISCOUNT_VALUE_PERCENTAGE, pgettext_lazy('voucher_model', '%')))
+
+ PRODUCT_TYPE = 'product'
+ CATEGORY_TYPE = 'category'
+ SHIPPING_TYPE = 'shipping'
+ BASKET_TYPE = 'basket'
+
+ TYPE_CHOICES = (
+ (PRODUCT_TYPE, pgettext_lazy('voucher_model', 'Product')),
+ (CATEGORY_TYPE, pgettext_lazy('voucher_model', 'Category')),
+ (SHIPPING_TYPE, pgettext_lazy('voucher_model', 'Shipping')),
+ (BASKET_TYPE, pgettext_lazy('voucher_model', 'Baskets over'))
+ )
+
+ FIELDS_DEPENDED_ON_TYPE = ('product', 'category', 'apply_to', 'limit')
+
+ type = models.CharField(max_length=20, choices=TYPE_CHOICES)
+ name = models.CharField(max_length=255, null=True, blank=True)
+ code = models.CharField(max_length=12, unique=True, db_index=True)
+ usage_limit = models.PositiveIntegerField(
+ null=True, blank=True,
+ help_text=pgettext_lazy('voucher_model', 'Unlimited if empty'))
+ used = models.PositiveIntegerField(default=0, editable=False)
+ start_date = models.DateField(default=date.today)
+ end_date = models.DateField(null=True, blank=True, help_text=pgettext_lazy(
+ 'voucher_model', 'Never expire if empty'))
+
+ discount_value_type = models.CharField(
+ max_length=10, choices=DISCOUNT_VALUE_TYPE_CHOICES, default=DISCOUNT_VALUE_FIXED)
+ discount_value = models.DecimalField(max_digits=12, decimal_places=2)
+
+ # not mandatory fields, usage depends on type
+ product = models.ForeignKey('product.Product', blank=True, null=True)
+ category = models.ForeignKey('product.Category', blank=True, null=True)
+ apply_to = models.CharField(max_length=20, blank=True, null=True)
+ limit = PriceField(max_digits=12, decimal_places=2, null=True,
+ blank=True, currency=settings.DEFAULT_CURRENCY)
+
+
+ def __str__(self):
+ if self.name:
+ return self.name
+ return self.type
+
+
+@python_2_unicode_compatible
class Sale(models.Model):
FIXED = 'fixed'
PERCENTAGE = 'percentage'
DISCOUNT_TYPE_CHOICES = (
- (FIXED, pgettext_lazy('discount type', 'Fixed amount')),
- (PERCENTAGE, pgettext_lazy('discount_type', 'Percentage discount')))
+ (FIXED, pgettext_lazy('discount_type', settings.DEFAULT_CURRENCY)),
+ (PERCENTAGE, pgettext_lazy('discount_type', '%')))
name = models.CharField(max_length=255)
type = models.CharField(max_length=10, choices=DISCOUNT_TYPE_CHOICES,