Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
39920 Tampilan

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?    

Avatar
Buang
Jawaban Terbai

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)
Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
3
Mei 25
4060
0
Mar 15
5451
0
Jul 24
1659
0
Agu 18
7636
2
Des 16
10364