跳至內容
選單
此問題已被標幟
1 回覆
39436 瀏覽次數

I am doing:

line.sale_margin_percent = 100-((line.purchase_price*100)/line.price_unit)

Whe line.price_unit is 0 I get:

ZeroDivisionError: float division by zero

Which is the regular way to avoid that in python/odoo?    

頭像
捨棄
最佳答案

Hello E.M

This will occur when price_unit is Zero

You can add condition before doing this

if line.price_unit > 0:
     line.sale_margin_percent = 100-((line.purchase_price*100)/line.price_unit)
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
5月 25
3443
0
3月 15
4952
0
7月 24
1297
0
8月 18
7104
2
12月 16
9744