From 6e6033294800e9737385727bc06d07b3590ad109 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sat, 26 Mar 2016 15:26:30 +0100 Subject: [PATCH] Fixed #133 -- Transparent quota calculation --- src/pretix/base/models/items.py | 23 ++-- .../templates/pretixcontrol/items/quota.html | 116 ++++++++++++------ 2 files changed, 87 insertions(+), 52 deletions(-) diff --git a/src/pretix/base/models/items.py b/src/pretix/base/models/items.py index 1d74681d6..c449a14fe 100644 --- a/src/pretix/base/models/items.py +++ b/src/pretix/base/models/items.py @@ -488,15 +488,11 @@ class Quota(LoggedModel): return Quota.AVAILABILITY_OK, None # TODO: Test for interference with old versions of Item-Quota-relations, etc. - # TODO: Prevent corner-cases like people having ordered an item before it got - # its first variationsadde - paid, pending = self.count_orders() - - size_left -= paid + size_left -= self.count_paid_orders() if size_left <= 0: return Quota.AVAILABILITY_GONE, 0 - size_left -= pending + size_left -= self.count_pending_orders() if size_left <= 0: return Quota.AVAILABILITY_ORDERED, 0 @@ -527,17 +523,20 @@ class Quota(LoggedModel): self._position_lookup ).distinct().count() - def count_orders(self) -> dict: + def count_pending_orders(self) -> dict: from pretix.base.models import Order, OrderPosition - paid = OrderPosition.objects.filter( - self._position_lookup, order__status=Order.STATUS_PAID - ).distinct().count() - pending = OrderPosition.objects.filter( + return OrderPosition.objects.filter( self._position_lookup, order__status=Order.STATUS_PENDING, order__expires__gte=now() ).distinct().count() - return paid, pending + + def count_paid_orders(self): + from pretix.base.models import Order, OrderPosition + + return OrderPosition.objects.filter( + self._position_lookup, order__status=Order.STATUS_PAID + ).distinct().count() @cached_property def _position_lookup(self) -> Q: diff --git a/src/pretix/control/templates/pretixcontrol/items/quota.html b/src/pretix/control/templates/pretixcontrol/items/quota.html index 6f1b08038..c866e2081 100644 --- a/src/pretix/control/templates/pretixcontrol/items/quota.html +++ b/src/pretix/control/templates/pretixcontrol/items/quota.html @@ -3,48 +3,84 @@ {% load bootstrap3 %} {% block title %}{% trans "Quota" %}{% endblock %} {% block inside %} -

{% trans "Quota" %}

-
- {% csrf_token %} - {% bootstrap_form_errors form %} -
- {% trans "General information" %} - {% bootstrap_field form.name layout="horizontal" %} - {% bootstrap_field form.size layout="horizontal" %} - {% trans "Items" %} -

- {% blocktrans trimmed %} - Please select the products or product variations this quota should be applied to. If you apply two - quotas to the same product, it will only be available if both quotas have capacity - left. - {% endblocktrans %} -

-
- {% for item in items %} -
- -
-
-
- {% bootstrap_field item.field layout="horizontal" %} +

{% trans "Quota" %}

+
+
+ + {% csrf_token %} + {% bootstrap_form_errors form %} +
+ {% trans "General information" %} + {% bootstrap_field form.name layout="horizontal" %} + {% bootstrap_field form.size layout="horizontal" %} + {% trans "Items" %} +

+ {% blocktrans trimmed %} + Please select the products or product variations this quota should be applied to. If you apply two + quotas to the same product, it will only be available if + both quotas have capacity + left. + {% endblocktrans %} +

+
+ {% for item in items %} +
+ +
+
+
+ {% bootstrap_field item.field layout="horizontal" %} +
+
-
+ {% endfor %}
- {% endfor %} +
+
+ + {% if quota.pk and quota.size != None %} +
+
+ {% trans "Availability calculation" %} +
+
{% trans "Total quota" %}
+
{{ quota.size }}
+
+
+
{% trans "Paid orders" %}
+
– {{ quota.count_paid_orders }}
+
+
+
{% trans "Pending orders" %}
+
– {{ quota.count_pending_orders }}
+
+
+
{% trans "Vouchers" %}
+
– {{ quota.count_blocking_vouchers }}
+
+
+
{% trans "Current user's carts" %}
+
– {{ quota.count_in_cart }}
+
+
+
{% trans "Current availability" %}
+
{{ quota.availability.1 }}
+
+
- -
- -
- + {% endif %} + +
+ +
{% endblock %}