Skip to content

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

Adjust old dashboard to work properly after migrations

Pacu23ee20a407a6b
diff --git a/saleor/order/models.py b/saleor/order/models.py
index c2835a87c5..42b33310bd 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -169,8 +169,7 @@ class Order(models.Model):
return None
def get_last_payment_status_display(self):
- last_payment = max(
- self.payments.all(), default=None, key=attrgetter('pk'))
+ last_payment = self.get_last_payment()
if last_payment:
return last_payment.get_charge_status_display()
return None
diff --git a/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py b/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py
index 6d966f0947..1688c2f942 100644
--- a/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py
+++ b/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py
@@ -30,11 +30,10 @@ def get_charge_status(payment):
return ChargeStatus.NOT_CHARGED
-def get_is_active(status):
- non_active_statuses = [
- PaymentStatus.WAITING, PaymentStatus.REFUNDED, PaymentStatus.INPUT,
- PaymentStatus.REJECTED]
- if status in non_active_statuses:
+def get_is_active(status, payment):
+ if status == PaymentStatus.INPUT:
+ return False
+ if status == PaymentStatus.REFUNDED and is_fully_refunded(payment):
return False
return True
@@ -50,10 +49,7 @@ def create_transaction(method, transaction_type, created, amount, is_success):
def create_transactions(method, payment):
# Those payments are inactive and need no transactions
- if payment.status in [
- PaymentStatus.INPUT, PaymentStatus.WAITING, PaymentStatus.PREAUTH]:
- method.is_active = False
- method.save()
+ if payment.status == PaymentStatus.INPUT:
return
# Other payments needed to be authorized first
@@ -79,9 +75,6 @@ def create_transactions(method, payment):
create_transaction(
method=method, transaction_type=TransactionType.REFUND,
created=created, amount=amount, is_success=True)
- if is_fully_refunded(payment):
- method.is_active = False
- method.save()
def transfer_payments_to_payment_methods(apps, schema_editor):
@@ -116,7 +109,7 @@ def transfer_payments_to_payment_methods(apps, schema_editor):
token=pay.token,
captured_amount=Money(pay.captured_amount, pay.currency),
total=Money(pay.total, pay.currency),
- is_active=get_is_active(pay.status),
+ is_active=get_is_active(pay.status, pay),
charge_status=get_charge_status(pay))
create_transactions(payment_method, pay)
diff --git a/saleor/payment/models.py b/saleor/payment/models.py
index 6175c2f419..a8fe6efa1e 100644
--- a/saleor/payment/models.py
+++ b/saleor/payment/models.py
@@ -1,3 +1,5 @@
+from operator import attrgetter
+
from django.conf import settings
from django.contrib.postgres.fields import JSONField
from django.db import models
@@ -73,6 +75,9 @@ class Payment(models.Model):
def __iter__(self):
return iter(self.transactions.all())
+ def get_last_transaction(self):
+ return max(self.transactions.all(), default=None, key=attrgetter('pk'))
+
def get_auth_transaction(self):
txn = self.transactions.get(
transaction_type=TransactionType.AUTH, is_success=True)
diff --git a/templates/dashboard/index.html b/templates/dashboard/index.html
index 0ac28cddcd..14be0872cd 100644
--- a/templates/dashboard/index.html
+++ b/templates/dashboard/index.html
@@ -48,7 +48,7 @@
{{ payment.order.user|default:_("Guest") }}
</td>
<td class="right-align">
- {% price payment.get_total.gross %}
+ {% price payment.total %}
</td>
</tr>
{% endfor %}
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index da4997d5b4..71a7f3309b 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -137,8 +137,8 @@
{% trans "Preauthorized amount" context "Order summary card header" %}
</td>
<td class="right-align">
- {% if preauthorized.gross %}
- {% price preauthorized.gross %}
+ {% if preauthorized %}
+ {% price preauthorized %}
{% else %}
{% trans "N/A" context "Preauthorized amount not available" %}
{% endif %}