Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Change argument in Voucher.objects.active()

michal1b2218dc9db1
diff --git a/saleor/checkout/core.py b/saleor/checkout/core.py
index c847e3dd67..3e48566ad3 100644
--- a/saleor/checkout/core.py
+++ b/saleor/checkout/core.py
@@ -249,7 +249,7 @@ class Checkout(object):
@transaction.atomic
def create_order(self):
voucher = self._get_voucher(
- vouchers=Voucher.objects.active(today=date.today())
+ vouchers=Voucher.objects.active(date=date.today())
.select_for_update())
if self.voucher_code is not None and voucher is None:
# Voucher expired in meantime, abort order placement
@@ -310,7 +310,7 @@ class Checkout(object):
voucher_code = self.voucher_code
if voucher_code is not None:
if vouchers is None:
- vouchers = Voucher.objects.active(today=date.today())
+ vouchers = Voucher.objects.active(date=date.today())
try:
return vouchers.get(code=self.voucher_code)
except Voucher.DoesNotExist:
diff --git a/saleor/checkout/views/discount.py b/saleor/checkout/views/discount.py
index e961868598..b4fc2808a1 100644
--- a/saleor/checkout/views/discount.py
+++ b/saleor/checkout/views/discount.py
@@ -46,7 +46,7 @@ def validate_voucher(view):
def func(request, checkout, cart):
if checkout.voucher_code:
try:
- Voucher.objects.active(today=date.today()).get(
+ Voucher.objects.active(date=date.today()).get(
code=checkout.voucher_code)
except Voucher.DoesNotExist:
del checkout.voucher_code
diff --git a/saleor/discount/forms.py b/saleor/discount/forms.py
index bb89187cc5..b5cca7bce7 100644
--- a/saleor/discount/forms.py
+++ b/saleor/discount/forms.py
@@ -33,7 +33,7 @@ class CheckoutDiscountForm(forms.Form):
kwargs['initial'] = initial
super(CheckoutDiscountForm, self).__init__(*args, **kwargs)
self.fields['voucher'].queryset = Voucher.objects.active(
- today=date.today())
+ date=date.today())
def clean(self):
cleaned_data = super(CheckoutDiscountForm, self).clean()
diff --git a/saleor/discount/models.py b/saleor/discount/models.py
index f9d4ddcab1..2f157cbc3e 100644
--- a/saleor/discount/models.py
+++ b/saleor/discount/models.py
@@ -22,13 +22,13 @@ class NotApplicable(ValueError):
class VoucherQueryset(models.QuerySet):
- def active(self, today):
+ def active(self, date):
queryset = self.filter(
models.Q(usage_limit__isnull=True) |
models.Q(used__lt=models.F('usage_limit')))
queryset = queryset.filter(
- models.Q(end_date__isnull=True) | models.Q(end_date__gte=today))
- queryset = queryset.filter(start_date__lte=today)
+ models.Q(end_date__isnull=True) | models.Q(end_date__gte=date))
+ queryset = queryset.filter(start_date__lte=date)
return queryset
def increase_usage(self, voucher):
diff --git a/tests/test_discounts.py b/tests/test_discounts.py
index ce19c42cd7..a2b4a4e157 100644
--- a/tests/test_discounts.py
+++ b/tests/test_discounts.py
@@ -205,7 +205,7 @@ def test_voucher_queryset_active(voucher):
vouchers = Voucher.objects.all()
assert len(vouchers) == 1
active_vouchers = Voucher.objects.active(
- today=date.today() - timedelta(days=1))
+ date=date.today() - timedelta(days=1))
assert len(active_vouchers) == 0