Skip to content

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

Checkout discount amount should be decimal (#10663)

Filip Owczarekb2e3652af826
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.py
index 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.py
index 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_translation
assert not checkout.voucher_code
assert not checkout.discount_name
assert 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.py
index cd1c82ab6c..9029ca3578 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -1,4 +1,5 @@
"""Checkout-related utility functions."""
+from decimal import Decimal
from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple, Union, cast
import graphene
@@ -756,7 +757,7 @@ def remove_voucher_from_checkout(checkout: Checkout):
checkout.voucher_code = None
checkout.discount_name = None
checkout.translated_discount_name = None
- checkout.discount_amount = 0
+ checkout.discount_amount = Decimal("0")
checkout.save(
update_fields=[
"voucher_code",