diff --git a/shop/models.py b/shop/models.py
index 1ff29a4b..24402164 100644
--- a/shop/models.py
+++ b/shop/models.py
@@ -122,9 +122,9 @@ class Order(CreatedUpdatedModel):
def mark_as_paid(self):
self.paid = True
+ self.open = None
for order_product in self.orderproductrelation_set.all():
category_pk = str(order_product.product.category.pk)
- print(order_product, category_pk, settings.TICKET_CATEGORY_ID)
if category_pk == settings.TICKET_CATEGORY_ID:
for _ in range(0, order_product.quantity):
ticket = Ticket(
diff --git a/shop/templates/admin/change_order_form.html b/shop/templates/admin/change_order_form.html
index 7f065f1e..685943ea 100644
--- a/shop/templates/admin/change_order_form.html
+++ b/shop/templates/admin/change_order_form.html
@@ -6,6 +6,11 @@
{% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
{% trans "History" %}
+{% if not original.paid and original.open != None %}
+
+ Mark as paid
+
+{% endif %}
{% if original.paid and original.invoice %}
{% url 'shop:download_invoice' original.pk|admin_urlquote as invoice_url %}
diff --git a/shop/urls.py b/shop/urls.py
index 761beea3..ca92c421 100644
--- a/shop/urls.py
+++ b/shop/urls.py
@@ -9,6 +9,7 @@ urlpatterns = [
url(r'orders/$', OrderListView.as_view(), name='order_list'),
url(r'orders/(?P[0-9]+)/$', OrderDetailView.as_view(), name='order_detail'),
url(r'orders/(?P[0-9]+)/invoice/$', DownloadInvoiceView.as_view(), name='download_invoice'),
+ url(r'orders/(?P[0-9]+)/mark_as_paid/$', OrderMarkAsPaidView.as_view(), name='mark_order_as_paid'),
#url(r'orders/(?P[0-9]+)/pay/creditcard/$', EpayFormView.as_view(), name='epay_form'),
#url(r'orders/(?P[0-9]+)/pay/creditcard/callback/$',EpayCallbackView.as_view(), name='epay_callback'),
diff --git a/shop/views.py b/shop/views.py
index 08cc0f03..2891cab6 100644
--- a/shop/views.py
+++ b/shop/views.py
@@ -566,3 +566,20 @@ class TicketDetailView(LoginRequiredMixin, UpdateView, DetailView):
if ticket.order.user != request.user:
return Http404
return super(TicketDetailView, self).dispatch(request, *args, **kwargs)
+
+
+class OrderMarkAsPaidView(LoginRequiredMixin, SingleObjectMixin, View):
+
+ model = Order
+
+ def get(self, request, *args, **kwargs):
+ if not request.user.is_staff:
+ messages.error(request, 'You do not have permissions to do that.')
+ return HttpResponseRedirect(reverse_lazy('shop:index'))
+ else:
+ messages.success(request, 'The order has been marked as paid.')
+ order = self.get_object()
+ order.mark_as_paid()
+ return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
+
+