Skip to content

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

fixing the bug with suggested approach

MahmoudRizk46b74f1589b0
diff --git a/saleor/product/utils/costs.py b/saleor/product/utils/costs.py
index 75aebf0aa1..d01a49f0af 100644
--- a/saleor/product/utils/costs.py
+++ b/saleor/product/utils/costs.py
@@ -57,10 +57,8 @@ def get_margin_for_variant(variant):
if variant.cost_price is None:
return None
base_price = variant.base_price
+ if not base_price:
+ return None
margin = base_price - variant.cost_price
- try:
- percent = round((margin / base_price) * 100, 0)
- except ZeroDivisionError:
- sign = lambda margin: (1, -1)[margin.amount < 0]
- percent = 9999999999999999999999 * sign(margin)
+ percent = round((margin / base_price) * 100, 0)
return percent