Redirect to review if the order is closed but not paid. Also remove the option to remove products when the order is closed.

This commit is contained in:
Víðir Valberg Guðmundsson 2019-07-09 10:46:30 +02:00
parent effd900b62
commit 3ba33649cb
3 changed files with 20 additions and 3 deletions

View file

@ -26,7 +26,9 @@
Price
<th>
Total
{% if not order.open == None %}
<th></th>
{% endif %}
<tbody>
{% for form in order_product_formset %}
@ -47,8 +49,10 @@
{{ form.instance.product.price|currency }}
<td>
{{ form.instance.total|currency }}
{% if not order.open == None %}
<td>
{% bootstrap_button '<i class="glyphicon glyphicon-remove"></i>' button_type="submit" button_class="btn-danger" name="remove_product" value=form.instance.pk %}
{% bootstrap_button '<i class="glyphicon glyphicon-remove"></i>' button_type="submit" button_class="btn-danger" name="remove_product" value=form.instance.pk %}
{% endif %}
{% endfor %}

View file

@ -4,12 +4,13 @@
{% block profile_content %}
{% if order.open is not None %}
<div>
Not ready to pay for your order yet?
<a href="{% url "shop:order_detail" pk=order.pk %}">Go back and edit it</a>
</div>
<hr />
{% endif %}
<div class="panel panel-default">
<div class="panel-heading">
@ -18,7 +19,11 @@
<div class="panel-body">
<p>
Please review your order to make sure the quantities are right.
{% if order.open is not None %}
Please review your order to make sure the quantities are right.
{% else %}
This order is closed, but not paid.
{% endif %}
</p>
<table class="table table-bordered">

View file

@ -275,6 +275,14 @@ 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(