Skip to content

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

fixing bug no. 4134

MahmoudRizk7c6831fd19d7
diff --git a/saleor/product/utils/costs.py b/saleor/product/utils/costs.py
index 79350bde14..75aebf0aa1 100644
--- a/saleor/product/utils/costs.py
+++ b/saleor/product/utils/costs.py
@@ -58,5 +58,9 @@ def get_margin_for_variant(variant):
return None
base_price = variant.base_price
margin = base_price - variant.cost_price
- percent = round((margin / base_price) * 100, 0)
+ try:
+ percent = round((margin / base_price) * 100, 0)
+ except ZeroDivisionError:
+ sign = lambda margin: (1, -1)[margin.amount < 0]
+ percent = 9999999999999999999999 * sign(margin)
return percent