Skip to content

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

Use early return when discount_amount = 0 for webhook payload

Ania Warzecha0c4ed3a52d8a
diff --git a/saleor/core/prices.py b/saleor/core/prices.py
index e01dd9d61d..b8be0d03d5 100644
--- a/saleor/core/prices.py
+++ b/saleor/core/prices.py
@@ -14,8 +14,6 @@ PriceType = TypeVar("PriceType", TaxedMoney, Money, Decimal, TaxedMoneyRange)
def quantize_price(price: PriceType, currency: str) -> PriceType:
precision = get_currency_precision(currency)
number_places = Decimal(10) ** -precision
- if not price:
- return Decimal(0)
return price.quantize(number_places)
diff --git a/saleor/core/tests/test_prices.py b/saleor/core/tests/test_prices.py
deleted file mode 100644
index 873204c4af..0000000000
--- a/saleor/core/tests/test_prices.py
+++ /dev/null
@@ -1,14 +0,0 @@
-from decimal import Decimal
-
-import pytest
-
-from ..prices import quantize_price
-
-
- ("price", "currency", "expected_value"),
- [(0, "USD", 0), (Decimal(5), "USD", Decimal(5.00))],
-)
-def test_quantize_price(price, currency, expected_value):
- price = quantize_price(price, currency)
- assert price == expected_value
diff --git a/saleor/webhook/payloads.py b/saleor/webhook/payloads.py
index c379fbc6a7..abc2fa61a1 100644
--- a/saleor/webhook/payloads.py
+++ b/saleor/webhook/payloads.py
@@ -1314,13 +1314,16 @@ def generate_checkout_payload_for_tax_calculation(
and checkout_info.voucher.type == VoucherType.ENTIRE_ORDER
and not checkout_info.voucher.apply_once_per_order
)
- discount_amount = quantize_price(checkout.discount_amount, checkout.currency)
- discount_name = checkout.discount_name
- discounts = (
- [{"name": discount_name, "amount": discount_amount}]
- if discount_amount and discount_not_included
- else []
- )
+ if not checkout.discount_amount:
+ discounts = []
+ else:
+ discount_amount = quantize_price(checkout.discount_amount, checkout.currency)
+ discount_name = checkout.discount_name
+ discounts = (
+ [{"name": discount_name, "amount": discount_amount}]
+ if discount_amount and discount_not_included
+ else []
+ )
# Prepare shipping data
shipping_method = checkout.shipping_method