add download link for invoices to order list
This commit is contained in:
parent
065d3f8660
commit
ef1d306617
|
@ -13,6 +13,7 @@
|
||||||
<th>Open?</th>
|
<th>Open?</th>
|
||||||
<th>Paid?</th>
|
<th>Paid?</th>
|
||||||
<th>Delivered?</th>
|
<th>Delivered?</th>
|
||||||
|
<th>Invoice</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -26,6 +27,14 @@
|
||||||
<td class="text-center">{{ order.paid|truefalseicon }}</td>
|
<td class="text-center">{{ order.paid|truefalseicon }}</td>
|
||||||
<td class="text-center">{{ order.handed_out_status }}</td>
|
<td class="text-center">{{ order.handed_out_status }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
{% if order.invoice.pdf %}
|
||||||
|
{% url 'shop:download_invoice' pk=order.pk as order_download_url %}
|
||||||
|
{% bootstrap_button "PDF" icon="save-file" href=order_download_url button_class="btn-primary btn-xs" %}
|
||||||
|
{% else %}
|
||||||
|
N/A
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
{% url 'shop:order_detail' pk=order.pk as order_detail_url %}
|
{% url 'shop:order_detail' pk=order.pk as order_detail_url %}
|
||||||
{% bootstrap_button "Order details" icon="th-list" href=order_detail_url button_class="btn-primary btn-xs" %}
|
{% bootstrap_button "Order details" icon="th-list" href=order_detail_url button_class="btn-primary btn-xs" %}
|
||||||
{% if not order.paid %}
|
{% if not order.paid %}
|
||||||
|
|
|
@ -8,6 +8,7 @@ urlpatterns = [
|
||||||
|
|
||||||
url(r'orders/$', OrderListView.as_view(), name='order_list'),
|
url(r'orders/$', OrderListView.as_view(), name='order_list'),
|
||||||
url(r'orders/(?P<pk>[0-9]+)/$', OrderDetailView.as_view(), name='order_detail'),
|
url(r'orders/(?P<pk>[0-9]+)/$', OrderDetailView.as_view(), name='order_detail'),
|
||||||
|
url(r'orders/(?P<pk>[0-9]+)/$', DownloadInvoiceView.as_view(), name='download_invoice'),
|
||||||
|
|
||||||
url(r'orders/(?P<pk>[0-9]+)/pay/creditcard/$', EpayFormView.as_view(), name='epay_form'),
|
url(r'orders/(?P<pk>[0-9]+)/pay/creditcard/$', EpayFormView.as_view(), name='epay_form'),
|
||||||
url(r'orders/(?P<pk>[0-9]+)/pay/creditcard/callback/$',EpayCallbackView.as_view(), name='epay_callback'),
|
url(r'orders/(?P<pk>[0-9]+)/pay/creditcard/callback/$',EpayCallbackView.as_view(), name='epay_callback'),
|
||||||
|
|
|
@ -60,6 +60,19 @@ class EnsureUnpaidOrderMixin(SingleObjectMixin):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EnsurePaidOrderMixin(SingleObjectMixin):
|
||||||
|
model = Order
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
if not self.get_object().paid:
|
||||||
|
messages.error(request, "This order is not paid for!")
|
||||||
|
return HttpResponseRedirect(reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk}))
|
||||||
|
|
||||||
|
return super(EnsurePaidOrderMixin, self).dispatch(
|
||||||
|
request, *args, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EnsureClosedOrderMixin(SingleObjectMixin):
|
class EnsureClosedOrderMixin(SingleObjectMixin):
|
||||||
model = Order
|
model = Order
|
||||||
|
|
||||||
|
@ -85,6 +98,18 @@ class EnsureOrderHasProductsMixin(SingleObjectMixin):
|
||||||
request, *args, **kwargs
|
request, *args, **kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class EnsureOrderHasInvoicePDFMixin(SingleObjectMixin):
|
||||||
|
model = Order
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
if not self.get_object().invoice.pdf:
|
||||||
|
messages.error(request, "This order has no invoice yet!")
|
||||||
|
return HttpResponseRedirect(reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk}))
|
||||||
|
|
||||||
|
return super(EnsureOrderHasInvoicePDFMixin, self).dispatch(
|
||||||
|
request, *args, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
#################################################################################
|
#################################################################################
|
||||||
|
|
||||||
class ShopIndexView(ListView):
|
class ShopIndexView(ListView):
|
||||||
|
@ -240,6 +265,16 @@ class OrderDetailView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureOrderH
|
||||||
|
|
||||||
return super(OrderDetailView, self).get(request, *args, **kwargs)
|
return super(OrderDetailView, self).get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadInvoiceView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsurePaidOrderMixin, EnsureOrderHasInvoicePDFMixin, SingleObjectMixin, View):
|
||||||
|
model = Order
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
response = HttpResponse(content_type='application/pdf')
|
||||||
|
response['Content-Disposition'] = 'attachment; filename="%s"' % self.get_object().invoice.filename
|
||||||
|
response.write(self.get_object().pdf.read())
|
||||||
|
return response
|
||||||
|
|
||||||
#################################################################################
|
#################################################################################
|
||||||
|
|
||||||
class EpayFormView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrderMixin, EnsureClosedOrderMixin, EnsureOrderHasProductsMixin, DetailView):
|
class EpayFormView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrderMixin, EnsureClosedOrderMixin, EnsureOrderHasProductsMixin, DetailView):
|
||||||
|
@ -263,7 +298,7 @@ class EpayFormView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrd
|
||||||
class EpayCallbackView(SingleObjectMixin, View):
|
class EpayCallbackView(SingleObjectMixin, View):
|
||||||
model = Order
|
model = Order
|
||||||
|
|
||||||
def get(self, request, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
callback = EpayCallback.objects.create(
|
callback = EpayCallback.objects.create(
|
||||||
payload=request.GET
|
payload=request.GET
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue