Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add git card balance to checkout total price calculation
fowczarek91cd99b0b409
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.pyindex d63c4165e8..7ebbfb0814 100644--- a/saleor/checkout/models.py+++ b/saleor/checkout/models.py@@ -11,7 +11,7 @@ from django.utils.encoding import smart_strfrom django_prices.models import MoneyFieldfrom ..account.models import Address-from ..core.utils.taxes import ZERO_TAXED_MONEY, zero_money+from ..core.utils.taxes import ZERO_MONEY, ZERO_TAXED_MONEY, zero_moneyfrom ..core.weight import zero_weightfrom ..giftcard.models import GiftCardfrom ..shipping.models import ShippingMethod@@ -108,11 +108,22 @@ class Checkout(models.Model):def get_total(self, discounts=None, taxes=None):"""Return the total cost of the checkout."""- return (+ total = (self.get_subtotal(discounts, taxes)+ self.get_shipping_price(taxes)- self.discount_amount+ - self.get_total_gift_cards_balance())+ return max(total, ZERO_TAXED_MONEY)++ def get_total_gift_cards_balance(self):+ """Return the total balance of the gift cards assigned to the checkout"""+ gift_cards_total_balance = self.gift_cards.aggregate(+ models.Sum("current_balance")+ )["current_balance__sum"]+ if gift_cards_total_balance:+ return gift_cards_total_balance+ return ZERO_MONEYdef get_total_weight(self):# Cannot use `sum` as it parses an empty Weight to an int