Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add methods to get payment amount as Price object
Marcin Gębalaa8487bf4740b
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex f224494388..6415247412 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -56,10 +56,10 @@ def order_details(request, pk):order.status != 'cancelled')ctx['can_release'] = payment.status == 'preauth'ctx['can_refund'] = payment.status == 'confirmed'- preauthorized = Price(payment.total, currency=payment.currency)++ preauthorized = payment.get_total_price()if payment.status == 'confirmed':- captured = Price(payment.captured_amount,- currency=payment.currency)+ captured = payment.get_captured_price()if payment.status == 'refunded':refunded = Price(payment.total - payment.captured_amount,currency=payment.currency)diff --git a/saleor/dashboard/payments/views.py b/saleor/dashboard/payments/views.pyindex b7d98be918..bd6c54fc51 100644--- a/saleor/dashboard/payments/views.py+++ b/saleor/dashboard/payments/views.py@@ -2,7 +2,6 @@ from django.shortcuts import get_object_or_404from django.template.response import TemplateResponsefrom django.views.generic import ListViewfrom payments.models import PAYMENT_STATUS_CHOICES-from prices import Pricefrom ..views import (FilterByStatusMixin, StaffMemberOnlyMixin,staff_member_required)@@ -18,14 +17,6 @@ class PaymentList(StaffMemberOnlyMixin, FilterByStatusMixin, ListView):status_order = ['waiting', 'input', 'preauth', 'confirmed', 'refunded','rejected', 'error']- def get_context_data(self, **kwargs):- ctx = super(PaymentList, self).get_context_data(**kwargs)- for payment in ctx['payments']:- payment.total = Price(payment.total, currency=payment.currency)- payment.captured_amount = Price(payment.captured_amount,- currency=payment.currency)- return ctx-def get_queryset(self):qs = super(PaymentList, self).get_queryset()return qs.order_by('-created')@@ -34,8 +25,5 @@ class PaymentList(StaffMemberOnlyMixin, FilterByStatusMixin, ListView):@staff_member_requireddef payment_details(request, pk):payment = get_object_or_404(Payment, pk=pk)- currency = payment.currency- payment.total = Price(payment.total, currency=currency)- payment.captured_amount = Price(payment.captured_amount, currency=currency)return TemplateResponse(request, 'dashboard/payments/detail.html',{'payment': payment})diff --git a/saleor/dashboard/templates/dashboard/payments/detail.html b/saleor/dashboard/templates/dashboard/payments/detail.htmlindex 82c335a658..b3b2d7a279 100644--- a/saleor/dashboard/templates/dashboard/payments/detail.html+++ b/saleor/dashboard/templates/dashboard/payments/detail.html@@ -19,8 +19,8 @@<div class="panel-body"><p>Status: {% render_status payment.status payment.get_status_display %}</p><p>Fraud status: {% render_status payment.fraud_status payment.get_fraud_status_display %}</p>- <p>Amount: {% gross payment.total %}</p>- <p>Captured amount: {% gross payment.captured_amount %}</p>+ <p>Amount: {% gross payment.get_total_price %}</p>+ <p>Captured amount: {% gross payment.get_captured_price %}</p><p>Gateway: {{ payment.variant }}</p><p>Transaction id: {{ payment.transaction_id }}</p><p>Payment date: {{ payment.created }}</p>diff --git a/saleor/dashboard/templates/dashboard/payments/list.html b/saleor/dashboard/templates/dashboard/payments/list.htmlindex 527d7ec296..3fa36e3324 100644--- a/saleor/dashboard/templates/dashboard/payments/list.html+++ b/saleor/dashboard/templates/dashboard/payments/list.html@@ -33,9 +33,9 @@<td>{{ payment.variant }}</td><th>{{ payment.created }}</th><td>{{ payment.order.user|default:"Anonymous" }}</td>- <td>{% gross payment.total %}</td>+ <td>{% gross payment.get_total_price %}</td><td>{% render_status payment.status payment.get_status_display %}</td>- <td>{% gross payment.captured_amount %}</td>+ <td>{% gross payment.get_captured_price %}</td></tr>{% endfor %}</tbody>diff --git a/saleor/order/models.py b/saleor/order/models.pyindex 7492f65b45..df4266cedb 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -344,6 +344,13 @@ class Payment(BasePayment):for item in self.order.get_items()]return items+ def get_total_price(self):+ net = self.total - self.tax+ return Price(net, gross=self.total, currency=self.currency)++ def get_captured_price(self):+ return Price(self.captured_amount, currency=self.currency)+@python_2_unicode_compatibleclass OrderHistoryEntry(models.Model):