Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Checkout discount amount should be decimal (#10663)
Filip Owczarekb2e3652af826
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.pyindex 237f143a69..e68369ae54 100644--- a/saleor/checkout/models.py+++ b/saleor/checkout/models.py@@ -143,7 +143,7 @@ class Checkout(ModelWithMetadata):discount_amount = models.DecimalField(max_digits=settings.DEFAULT_MAX_DIGITS,decimal_places=settings.DEFAULT_DECIMAL_PLACES,- default=0,+ default=Decimal("0.0"),)discount = MoneyField(amount_field="discount_amount", currency_field="currency")discount_name = models.CharField(max_length=255, blank=True, null=True)diff --git a/saleor/checkout/tests/test_checkout.py b/saleor/checkout/tests/test_checkout.pyindex 3af36684af..4cde534962 100644--- a/saleor/checkout/tests/test_checkout.py+++ b/saleor/checkout/tests/test_checkout.py@@ -869,9 +869,15 @@ def test_remove_voucher_from_checkout(checkout_with_voucher, voucher_translationassert not checkout.voucher_codeassert not checkout.discount_nameassert not checkout.translated_discount_name+ assert isinstance(checkout.discount_amount, Decimal)assert checkout.discount == zero_money(checkout.channel.currency_code)+def test_checkout_discount_amount_should_be_decimal():+ checkout = Checkout()+ assert isinstance(checkout.discount_amount, Decimal)++def test_recalculate_checkout_discount(checkout_with_voucher,voucher,diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex cd1c82ab6c..9029ca3578 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -1,4 +1,5 @@"""Checkout-related utility functions."""+from decimal import Decimalfrom typing import TYPE_CHECKING, Iterable, List, Optional, Tuple, Union, castimport graphene@@ -756,7 +757,7 @@ def remove_voucher_from_checkout(checkout: Checkout):checkout.voucher_code = Nonecheckout.discount_name = Nonecheckout.translated_discount_name = None- checkout.discount_amount = 0+ checkout.discount_amount = Decimal("0")checkout.save(update_fields=["voucher_code",