Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Handle order detail view for order with no payments
Marcin Gębala66983d166f59
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex 03a601a7a1..c36b134a38 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -34,16 +34,17 @@ class OrderDetails(StaffMemberOnlyMixin, DetailView):def get_context_data(self, **kwargs):ctx = super(OrderDetails, self).get_context_data(**kwargs)- payment = self.get_object().payments.last()+ ctx['notes'] = self.object.notes.all()if 'note_form' not in ctx:ctx['note_form'] = self.note_form_class()- ctx['can_capture'] = payment.status == 'preauth'- ctx['can_release'] = payment.status == 'preauth'- ctx['can_refund'] = payment.status == 'confirmed'-- if 'payment_form' not in ctx:+ payment = self.get_object().payments.last()+ ctx['payment'] = payment+ if payment:+ ctx['can_capture'] = payment.status == 'preauth'+ ctx['can_release'] = payment.status == 'preauth'+ ctx['can_refund'] = payment.status == 'confirmed'if payment.status == 'confirmed':amount = payment.captured_amountelif payment.status == 'preauth':@@ -52,9 +53,9 @@ class OrderDetails(StaffMemberOnlyMixin, DetailView):amount = Nonectx['payment_form'] = self.payment_form_class(initial={'amount': amount})-- ctx['notes'] = self.object.notes.all()- ctx['payment'] = self.object.payments.last()+ else:+ ctx['can_capture'] = ctx['can_release'] = ctx['can_refund'] = False+ ctx['payment_form'] = self.payment_form_class()return ctxdef get_delivery_info(self):diff --git a/saleor/dashboard/templates/dashboard/order/detail.html b/saleor/dashboard/templates/dashboard/order/detail.htmlindex 782f2e11cc..49f45c58f0 100644--- a/saleor/dashboard/templates/dashboard/order/detail.html+++ b/saleor/dashboard/templates/dashboard/order/detail.html@@ -159,9 +159,9 @@<p>Order status: {% include 'dashboard/includes/_status_label.html' with status=order.status status_display=order.get_status_display %}</p><p>Payment status: {% include 'dashboard/includes/_status_label.html' with status=order.get_last_payment_status status_display=order.get_last_payment_status_display %}</p><p>Total: {% gross order.get_total %}</p>- {% with order.payments.last as payment %}+ {% if payment %}<p>Captured: {{ payment.captured_amount }} {{ payment.currency }}</p>- {% endwith %}+ {% endif %}<form method="post">{% csrf_token %}<input type="submit" class="btn btn-warning" name='payment_form' value="Release" {% if not can_release %} disabled {% endif %}/>