diff --git a/src/profiles/templates/shop/creditnote_list.html b/src/shop/templates/creditnote_list.html similarity index 100% rename from src/profiles/templates/shop/creditnote_list.html rename to src/shop/templates/creditnote_list.html diff --git a/src/profiles/templates/shop/order_detail.html b/src/shop/templates/order_detail.html similarity index 92% rename from src/profiles/templates/shop/order_detail.html rename to src/shop/templates/order_detail.html index 50cd05eb..0444bebc 100644 --- a/src/profiles/templates/shop/order_detail.html +++ b/src/shop/templates/order_detail.html @@ -71,8 +71,8 @@ {% if not order.open == None %}

Comment:

- {% elif order.open == None and order.comment %} -
{{ order.comment|linebreaks }}
+ {% elif order.open == None and order.customer_comment %} +
{{ order.customer_comment|linebreaks }}
{% endif %} {% if not order.open == None %} @@ -90,9 +90,7 @@ {% bootstrap_button "Cancel order" button_type="submit" button_class="btn-danger" name="cancel_order" %} {% endif %} {% if not order.paid %} - - Review and pay - + {% bootstrap_button "Review and pay" button_type="submit" button_class="btn btn-success btn-lg pull-right" name="review_and_pay" %} {% endif %} diff --git a/src/profiles/templates/shop/order_list.html b/src/shop/templates/order_list.html similarity index 100% rename from src/profiles/templates/shop/order_list.html rename to src/shop/templates/order_list.html diff --git a/src/profiles/templates/shop/order_review.html b/src/shop/templates/order_review.html similarity index 97% rename from src/profiles/templates/shop/order_review.html rename to src/shop/templates/order_review.html index 17577151..9e4bb1ab 100644 --- a/src/profiles/templates/shop/order_review.html +++ b/src/shop/templates/order_review.html @@ -63,9 +63,9 @@ - {% if order.comment %} + {% if order.customer_comment %}

Comment:

-
{{ order.comment|linebreaks }}
+
{{ order.customer_comment|linebreaks }}
{% endif %} {% if order.invoice_address %} diff --git a/src/shop/tests.py b/src/shop/tests.py index c45a9dae..38607056 100644 --- a/src/shop/tests.py +++ b/src/shop/tests.py @@ -313,6 +313,32 @@ class TestOrderDetailView(TestCase): self.assertEquals(response.status_code, 200) self.assertIn("quantity", response.context["order_product_formset"].errors[0]) + def test_review_and_pay_saves_and_redirects(self): + self.client.force_login(self.user) + + opr = OrderProductRelationFactory(order=self.order) + + data = self.base_form_data + data["review_and_pay"] = "" + data["form-0-id"] = opr.pk + data["form-0-quantity"] = 5 + data["customer_comment"] = "A comment" + data["invoice_address"] = "An invoice address" + + response = self.client.post(self.path, data=data) + self.assertRedirects( + response, reverse("shop:order_review_and_pay", kwargs={"pk": self.order.pk}) + ) + + # Get the updated objects + opr.refresh_from_db() + self.order.refresh_from_db() + + # Check them + self.assertEqual(opr.quantity, 5) + self.assertEqual(self.order.invoice_address, "An invoice address") + self.assertEqual(self.order.customer_comment, "A comment") + class TestOrderReviewAndPay(TestCase): def setUp(self): diff --git a/src/shop/views.py b/src/shop/views.py index d6813045..7330f683 100644 --- a/src/shop/views.py +++ b/src/shop/views.py @@ -271,7 +271,7 @@ class ProductDetailView(FormView, DetailView): class OrderListView(LoginRequiredMixin, ListView): model = Order - template_name = "shop/order_list.html" + template_name = "order_list.html" context_object_name = "orders" def get_queryset(self): @@ -287,7 +287,7 @@ class OrderDetailView( DetailView, ): model = Order - template_name = "shop/order_detail.html" + template_name = "order_detail.html" context_object_name = "order" def get_context_data(self, **kwargs): @@ -336,8 +336,8 @@ class OrderDetailView( self.get_context_data(order_product_formset=formset) ) - # No stock issues, proceed to check if the user is updating the order. - if "update_order" in request.POST: + # No stock issues, proceed to check if the user is updating or proceeding to review and pay the order. + if "update_order" or "review_and_pay" in request.POST: # We have already made sure the formset is valid, so just save it to update quantities. formset.save() @@ -345,6 +345,11 @@ class OrderDetailView( order.invoice_address = request.POST.get("invoice_address") or "" order.save() + if "review_and_pay" in request.POST: + return HttpResponseRedirect( + reverse("shop:order_review_and_pay", kwargs={"pk": order.pk}) + ) + return super(OrderDetailView, self).get(request, *args, **kwargs) @@ -355,7 +360,7 @@ class OrderReviewAndPayView( EnsureOrderIsNotCancelledMixin, DetailView, ): - template_name = "shop/order_review.html" + template_name = "order_review.html" context_object_name = "order" def post(self, request, *args, **kwargs): @@ -415,7 +420,7 @@ class DownloadInvoiceView( class CreditNoteListView(LoginRequiredMixin, ListView): model = CreditNote - template_name = "shop/creditnote_list.html" + template_name = "creditnote_list.html" context_object_name = "creditnotes" def get_queryset(self):