From 3ba33649cb40a7d79471c456decef6a360b95a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Tue, 9 Jul 2019 10:46:30 +0200 Subject: [PATCH] Redirect to review if the order is closed but not paid. Also remove the option to remove products when the order is closed. --- src/shop/templates/order_detail.html | 6 +++++- src/shop/templates/order_review.html | 9 +++++++-- src/shop/views.py | 8 ++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/shop/templates/order_detail.html b/src/shop/templates/order_detail.html index 07c92b9f..0274f574 100644 --- a/src/shop/templates/order_detail.html +++ b/src/shop/templates/order_detail.html @@ -26,7 +26,9 @@ Price Total + {% if not order.open == None %} + {% endif %} {% for form in order_product_formset %} @@ -47,8 +49,10 @@ {{ form.instance.product.price|currency }} {{ form.instance.total|currency }} + {% if not order.open == None %} - {% bootstrap_button '' button_type="submit" button_class="btn-danger" name="remove_product" value=form.instance.pk %} + {% bootstrap_button '' button_type="submit" button_class="btn-danger" name="remove_product" value=form.instance.pk %} + {% endif %} {% endfor %} diff --git a/src/shop/templates/order_review.html b/src/shop/templates/order_review.html index 9e4bb1ab..bb1efd9e 100644 --- a/src/shop/templates/order_review.html +++ b/src/shop/templates/order_review.html @@ -4,12 +4,13 @@ {% block profile_content %} + {% if order.open is not None %}
Not ready to pay for your order yet? Go back and edit it
-
+ {% endif %}
@@ -18,7 +19,11 @@

- 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 %}

diff --git a/src/shop/views.py b/src/shop/views.py index 4c859081..96e24efd 100644 --- a/src/shop/views.py +++ b/src/shop/views.py @@ -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(