Skip to content

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

Fix price precision validation (#6572)

Iga Karbowiak6d340c25b230
diff --git a/saleor/graphql/core/tests/test_validators.py b/saleor/graphql/core/tests/test_validators.py
index 8d52482ed4..d1c2b27d41 100644
--- a/saleor/graphql/core/tests/test_validators.py
+++ b/saleor/graphql/core/tests/test_validators.py
@@ -16,6 +16,7 @@ from ..validators import validate_one_of_args_is_in_query, validate_price_precis
(Decimal("1"), "ISK"),
(Decimal("1.00"), "ISK"),
(Decimal("5.12"), None),
+ (Decimal("1000"), "USD"),
],
)
def test_validate_price_precision(value, currency):
diff --git a/saleor/graphql/core/validators.py b/saleor/graphql/core/validators.py
index 5f5c63703d..73958ef288 100644
--- a/saleor/graphql/core/validators.py
+++ b/saleor/graphql/core/validators.py
@@ -36,10 +36,9 @@ def validate_price_precision(value: Optional["Decimal"], currency: str):
# check no needed when there is no value
if not value:
return
-
currency_fraction = get_currency_fraction(currency)
value = value.normalize()
- if abs(value.as_tuple().exponent) > currency_fraction:
+ if value.as_tuple().exponent < -currency_fraction:
raise ValidationError(
f"Value cannot have more than {currency_fraction} decimal places."
)