Add cancel and proforma buttons to review and pay template.

This commit is contained in:
Víðir Valberg Guðmundsson 2019-07-09 10:59:03 +02:00
parent 3ba33649cb
commit fa855fb69e
2 changed files with 23 additions and 15 deletions

View file

@ -78,6 +78,19 @@
<div class="alert alert-info">{{ order.invoice_address|linebreaks }}</div>
{% endif %}
{% if not order.paid and order.open is None %}
<form action="{% url "shop:order_detail" pk=order.pk %}" method="POST">
{% csrf_token %}
{% bootstrap_button "Cancel order" button_type="submit" button_class="btn-danger btn-lg" name="cancel_order" icon="remove" %}
{% if order.pdf %}
{% url 'shop:download_invoice' pk=order.pk as invoice_download_url %}
{% bootstrap_button "Proforma Invoice PDF" icon="save-file" href=invoice_download_url button_class="btn-primary btn-lg pull-right" %}
{% endif %}
</form>
{% endif %}
</div>
</div>

View file

@ -275,14 +275,6 @@ class OrderDetailView(
template_name = "order_detail.html"
context_object_name = "order"
def dispatch(self, request, *args, **kwargs):
order = self.get_object()
if order.open is None and not order.paid:
return HttpResponseRedirect(
reverse("shop:order_review_and_pay", kwargs={"pk": order.pk})
)
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
if "order_product_formset" not in kwargs:
kwargs["order_product_formset"] = OrderProductRelationFormSet(
@ -291,6 +283,14 @@ class OrderDetailView(
return super().get_context_data(**kwargs)
def get(self, request, *args, **kwargs):
order = self.get_object()
if order.open is None and not order.paid:
return HttpResponseRedirect(
reverse("shop:order_review_and_pay", kwargs={"pk": order.pk})
)
return super().get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
self.object = self.get_object()
order = self.object
@ -393,10 +393,7 @@ class OrderReviewAndPayView(
class DownloadInvoiceView(
LoginRequiredMixin,
EnsureUserOwnsOrderMixin,
SingleObjectMixin,
View,
LoginRequiredMixin, EnsureUserOwnsOrderMixin, SingleObjectMixin, View
):
model = Order
@ -417,9 +414,7 @@ class DownloadInvoiceView(
reverse_lazy("shop:order_detail", kwargs={"pk": self.get_object().pk})
)
response = HttpResponse(content_type="application/pdf")
response["Content-Disposition"] = (
'attachment; filename="%s"' % pdfobj.filename
)
response["Content-Disposition"] = 'attachment; filename="%s"' % pdfobj.filename
response.write(pdfobj.pdf.read())
return response