aboutsummaryrefslogtreecommitdiff
path: root/saleor/discount
diff options
context:
space:
mode:
authorArtur Smęt <artur.smet@mirumee.com>2016-02-17 14:14:05 +0100
committerArtur Smęt <artur.smet@mirumee.com>2016-02-17 14:14:05 +0100
commit6d3182a7d24c90dace5ffccc3e174c63f61442e1 (patch)
tree62582171cdf9e9b0b2c4bb31636362b8ccade2ac /saleor/discount
parent5752f6cff4cbc392888762fb09608ae077fe026b (diff)
downloadsaleor-frontend-6d3182a7d24c90dace5ffccc3e174c63f61442e1.tar.gz
saleor-frontend-6d3182a7d24c90dace5ffccc3e174c63f61442e1.tar.bz2
saleor-frontend-6d3182a7d24c90dace5ffccc3e174c63f61442e1.zip
Extract voucher usage increase/decrease methods to Voucher manager
Diffstat (limited to 'saleor/discount')
-rw-r--r--saleor/discount/models.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/saleor/discount/models.py b/saleor/discount/models.py
index 3b7ee9ae..7bf7ec29 100644
--- a/saleor/discount/models.py
+++ b/saleor/discount/models.py
@@ -4,6 +4,7 @@ from decimal import Decimal
from django.conf import settings
from django.db import models
+from django.db.models import F
from django.utils.translation import pgettext, pgettext_lazy
from django.utils.encoding import python_2_unicode_compatible, smart_text
from django_countries import countries
@@ -32,6 +33,14 @@ class VoucherQueryset(models.QuerySet):
queryset = queryset.filter(start_date__lte=today)
return queryset
+ def increase_usage(self, voucher):
+ voucher.used = F('used') + 1
+ voucher.save(update_fields=['used'])
+
+ def decrease_usage(self, voucher):
+ voucher.used = F('used') - 1
+ voucher.save(update_fields=['used'])
+
@python_2_unicode_compatible
class Voucher(models.Model):