Skip to content

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

Revert changes from checkout models and utils

IKarbowiakb20b6fc9e2ef
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.py
index cc7e3561a7..2e96e47adc 100644
--- a/saleor/checkout/models.py
+++ b/saleor/checkout/models.py
@@ -1,4 +1,5 @@
"""Checkout-related ORM models."""
+from operator import attrgetter
from typing import TYPE_CHECKING, Optional
from uuid import uuid4
@@ -138,7 +139,8 @@ class Checkout(ModelWithMetadata):
return next(matching_lines, None)
def get_last_active_payment(self) -> Optional["Payment"]:
- return self.payments.filter(is_active=True).last()
+ payments = [payment for payment in self.payments.all() if payment.is_active]
+ return max(payments, default=None, key=attrgetter("pk"))
def set_country(
self, country_code: str, commit: bool = False, replace: bool = True
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index 1efa5649c1..b716f295f0 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -6,7 +6,6 @@ from typing import Iterable, List, Optional, Tuple
from django.core.exceptions import ValidationError
from django.db import transaction
from django.db.models import Max, Min, Sum
-from django.db.models.functions import Coalesce
from django.utils import timezone
from django.utils.encoding import smart_text
from django.utils.translation import get_language
@@ -761,9 +760,8 @@ def is_fully_paid(
Note that these payments may not be captured or charged at all.
"""
- total_paid = checkout.payments.filter(is_active=True).aggregate(
- total_sum=Coalesce(Sum("total"), 0)
- )["total_sum"]
+ payments = [payment for payment in checkout.payments.all() if payment.is_active]
+ total_paid = sum([p.total for p in payments])
checkout_total = (
calculations.checkout_total(checkout=checkout, lines=lines, discounts=discounts)
- checkout.get_total_gift_cards_balance()