Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Unify the price display

Marcin Gębala5d80d3827502
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index d5745e34b4..f803bc5e57 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -7,6 +7,7 @@ from django.template.loader import render_to_string
from django.http import HttpResponse
from django.core.context_processors import csrf
from payments import PaymentError
+from prices import Price
from ...order.models import Order, OrderedItem, Address, DeliveryGroup
from ...userprofile.forms import AddressForm
@@ -38,39 +39,46 @@ class OrderDetails(StaffMemberOnlyMixin, DetailView):
def get_context_data(self, **kwargs):
ctx = super(OrderDetails, self).get_context_data(**kwargs)
-
- ctx['notes'] = self.object.notes.all()
- if 'note_form' not in ctx:
- ctx['note_form'] = self.note_form_class()
-
payment = self.get_object().payments.last()
- ctx['payment'] = payment
+ captured = refunded = preauthorized = None
+ payment_form_initial = {'amount': self.object.get_total().gross}
+
if payment:
ctx['can_capture'] = payment.status == 'preauth' \
and self.object.status != 'cancelled'
ctx['can_release'] = payment.status == 'preauth'
ctx['can_refund'] = payment.status == 'confirmed'
+
+ preauthorized = Price(payment.total, currency=payment.currency)
+
if payment.status == 'confirmed':
- amount = payment.captured_amount
- elif payment.status == 'preauth':
- amount = self.object.get_total().gross
- else:
- amount = None
- ctx['payment_form'] = self.payment_form_class(
- initial={'amount': amount})
- ctx['amount'] = amount
+ captured = Price(payment.captured_amount,
+ currency=payment.currency)
+ payment_form_initial = {'amount': captured.gross}
+
if payment.status == 'refunded':
- ctx['refunded_amount'] = payment.total - payment.captured_amount
+ refunded = Price(payment.total - payment.captured_amount,
+ currency=payment.currency)
else:
ctx['can_capture'] = ctx['can_release'] = ctx['can_refund'] = False
- ctx['payment_form'] = self.payment_form_class()
+ ctx['note_form'] = self.note_form_class()
+ ctx['payment_form'] = self.payment_form_class(payment_form_initial)
+
+ ctx['delivery_groups'] = self.get_delivery_groups(payment)
+ ctx['notes'] = self.object.notes.all()
+ ctx['payment'] = payment
+ ctx['captured'] = captured
+ ctx['preauthorized'] = preauthorized
+ ctx['refunded'] = refunded
+ return ctx
+
+ def get_delivery_groups(self, payment):
groups = self.object.groups.select_subclasses().all()
for group in groups:
group.can_ship = payment and payment.status == 'confirmed' and \
group.status == 'new'
- ctx['delivery_groups'] = groups
- return ctx
+ return groups
def get(self, request, *args, **kwargs):
self.object = self.get_object()
diff --git a/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.html b/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.html
index 0ebc1b511d..f2d1b0e64c 100644
--- a/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.html
+++ b/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.html
@@ -1,4 +1,5 @@
{% load i18n %}
+{% load babel %}
{% load bootstrap %}
<div class="modal-header">
@@ -9,7 +10,7 @@
<form id="modal-form" class="form-inline" role="form" method="post">
{% csrf_token %}
<div class="form-group">
- <label class="control-label"for="amount">{% blocktrans %}Amount to {{ action }}:{% endblocktrans %}</label>
+ <label class="control-label" for="amount">{% blocktrans %}Amount to {{ action }}:{% endblocktrans %}</label>
{% render_widget payment_form.amount class="form-control" %} {{ currency }}
<input id='id_action' type="hidden" name='payment_form' value={{ action }} />
<input id='id_captured' type="hidden" value={{ captured }} />
@@ -21,7 +22,7 @@
</ul>
<p>{% trans "After this action" %}</p>
<ul>
- <li>{% trans "Captured amount: " %}<span id="id_new_captured">{{ amount }}</span> {{ currency }}</li>
+ <li>{% trans "Captured amount: " %}{{ captured|currencyfmt:currency }} </li>
</ul>
</div>
<div class="modal-footer">
diff --git a/saleor/dashboard/templates/dashboard/index.html b/saleor/dashboard/templates/dashboard/index.html
index e456c9d951..22de959a9a 100644
--- a/saleor/dashboard/templates/dashboard/index.html
+++ b/saleor/dashboard/templates/dashboard/index.html
@@ -30,7 +30,7 @@
<td>{{ payment.variant }}</td>
<td>{{ payment.created }}</td>
<td>{{ payment.order.user|default:"Anonymous" }}</td>
- <td>{{ payment.total }}</td>
+ <td>{% gross payment.total %}</td>
</tr>
{% endfor %}
</tbody>
diff --git a/saleor/dashboard/templates/dashboard/order/detail.html b/saleor/dashboard/templates/dashboard/order/detail.html
index bc9084c2f3..ba39faee64 100644
--- a/saleor/dashboard/templates/dashboard/order/detail.html
+++ b/saleor/dashboard/templates/dashboard/order/detail.html
@@ -68,8 +68,13 @@
<div class="panel-heading"><span class="panel-title">{% trans "Manage payment" %}</span></div>
<div class="panel-body">
{% if payment %}
- <p>{% trans "Preauthorized amount:" %} {{ payment.total }} {{ payment.currency }}</p>
- <p>{% trans "Captured amount:" %} {{ payment.captured_amount }} {{ payment.currency }}</p>
+ <p>{% trans "Preauthorized amount:" %} {% if preauthorized %}{% gross preauthorized %}{% else %}-{% endif %}</p>
+ {% if captured %}
+ <p>Captured amount: {% gross captured %}</p>
+ {% endif %}
+ {% if refunded %}
+ <p>Refunded amount: {% gross refunded %}</p>
+ {% endif %}
{% if can_capture %}
<a class="btn btn-success" data-target="#base-modal" href="{% url 'dashboard:order-details' pk=order.pk %}?action=capture" data-toggle="modal">{% trans "Capture" %}</a>
{% elif can_refund %}
@@ -175,11 +180,14 @@
</div>
<div class="panel-body">
<p>Order date: {{ order.created }}</p>
- <p>Order status: {% render_status order.status order.get_status_display %}</p>
- <p>Payment status: {% render_status payment.status payment.get_status_display %}</p>
<p>Order total: {% gross order.get_total %}</p>
- {% if payment %}
- <p>Captured amount: {{ payment.captured_amount }} {{ payment.currency }}</p>
+ <p>Order status: {% render_status order.status order.get_status_display %}</p>
+ <p>Payment status: {% if payment %}{% render_status payment.status payment.get_status_display %}{% else %}-{% endif %}</p>
+ {% if captured %}
+ <p>Captured amount: {% gross captured %}</p>
+ {% endif %}
+ {% if refunded %}
+ <p>Refunded amount: {% gross refunded %}</p>
{% endif %}
</div>
</div>
diff --git a/saleor/dashboard/views.py b/saleor/dashboard/views.py
index 5395378178..29eb8df003 100644
--- a/saleor/dashboard/views.py
+++ b/saleor/dashboard/views.py
@@ -1,6 +1,7 @@
from django.contrib.auth.decorators import user_passes_test
from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
+from prices import Price
from ..order.models import Order, Payment
@@ -54,7 +55,10 @@ class IndexView(StaffMemberOnlyMixin, TemplateView):
return ctx
def get_preauthorized_payments(self):
- return Payment.objects.filter(status='preauth').order_by('-created')
+ payments = Payment.objects.filter(status='preauth').order_by('-created')
+ for payment in payments:
+ payment.total = Price(payment.total, currency=payment.currency)
+ return payments
def get_orders_to_ship(self):
return Order.objects.filter(status='fully-paid')