Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix last used on when use gift card
fowczarek6c71a4bfb017
diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 7eb06a53c6..55a3c1b57b 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -3,6 +3,7 @@ from functools import wrapsfrom django.conf import settingsfrom django.db import transactionfrom django.shortcuts import get_object_or_404, redirect+from django.utils import timezonefrom prices import Money, TaxedMoneyfrom ..account.utils import store_user_address@@ -300,11 +301,11 @@ def add_gift_card_to_order(order, gift_card, total_price_left):if total_price_left < gift_card.current_balance:gift_card.current_balance = gift_card.current_balance - total_price_lefttotal_price_left = ZERO_MONEY- gift_card.save(update_fields=["current_balance"])else:total_price_left = total_price_left - gift_card.current_balancegift_card.current_balance = 0- gift_card.save(update_fields=["current_balance"])+ gift_card.last_used_on = timezone.now()+ gift_card.save(update_fields=["current_balance", "last_used_on"])return total_price_leftdiff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex 5b5952eeff..fa3f43082d 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -881,6 +881,8 @@ def test_checkout_complete(address,shipping_method,):+ assert not gift_card.last_used_on+checkout = checkout_with_gift_cardcheckout.shipping_address = addresscheckout.shipping_method = shipping_method@@ -924,8 +926,10 @@ def test_checkout_complete(order_payment = order.payments.first()assert order_payment == paymentassert payment.transactions.count() == 1+gift_card.refresh_from_db()assert gift_card.current_balance == ZERO_MONEY+ assert gift_card.last_used_on# assert that the checkout instance has been deleted after checkoutwith pytest.raises(Checkout.DoesNotExist):