Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Discuss
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

Float division by zero

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
3 Replies
4558 Tampilan
Avatar
Pete Charalampopoulos

Hi.

I have put a simple division together but when the denominator is 0 then i get the 

float division by zero error

Here in my code: 

i found some examples and tried them but nothing works.


Any help would be appreciated

 

0
Avatar
Buang
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Jawaban Terbai

Hi,

It seems like you want to avoid the "float division by zero" error when record.price_subtotal is zero. You can add a check to handle this situation. Here's an example of how you can modify your code to handle division by zero:

for record in self:
if record.price_subtotal != 0:
    record['x_studio_gross_margin'] = record.x_studio_gross_profit / record.price_subtotal
else:
    # Handle the division by zero case, for example, set x_studio_gross_margin to a default value
    record['x_studio_gross_margin'] = 0.0  # You can choose any default value here


This modification checks if record.price_subtotal is not equal to zero before performing the division. If it's zero, it sets x_studio_gross_margin to a default value (in this case, 0.0). You can adjust the default value according to your requirements.

or you can try


for record in self:
try:
    record['x_studio_gross_margin'] = record.x_studio_gross_profit / record.price_subtotal
except ZeroDivisionError:
    # Handle the division by zero case, for example, set x_studio_gross_margin to a default value
    record['x_studio_gross_margin'] = 0.0  # You can choose any default value here


Hope it helps

0
Avatar
Buang
Pete Charalampopoulos
Penulis

Thank you, Both work

Avatar
Jainesh Shah(Aktiv Software)
Jawaban Terbai

Hello Pete Charalampopoulos,


To resolve this error you just need to add a condition to check price_subtotal as follow and if the price_subtotal is zero then x_studio_gross_margin should also be zero.


for record in self:

    record['x_studio_gross_margin'] = (record.x_studio_gross_profit / record.price_subtotal) if record.price_subtotal else 0

I hope this will help you. 

Thanks & Regards,
Email:   odoo@aktivsoftware.com      

Skype: kalpeshmaheshwari

0
Avatar
Buang
Avatar
Charles Edouard TOUTAIN
Jawaban Terbai

To handle the "float division by zero" error in Python, you can use a try-except block to catch the `ZeroDivisionError` exception. This way, you can manage the situation when the denominator is zero without having your program crash.


Here's an example of how you might modify your code to handle this:


```python

try:

    # Your division code here

    # Example: result = numerator / denominator

except ZeroDivisionError:

    # Handle the division by zero error

    # or

    # result = None

```


In this example, replace the comment `# Your division code here` with your actual division operation. If the denominator in your division is zero, the `ZeroDivisionError` will be raised, and the code within the `except` block will execute. This allows you to handle the error gracefully, such as by printing an error message or setting the result to a default value like `None`.

0
Avatar
Buang
Pete Charalampopoulos
Penulis

Hi Charles

i have added your recommendation on the bottom of my code

and i get the following error:
except ZeroDivisionError:
IndentationError: unexpected indent

here is the code:

for record in self:
record['x_studio_gross_margin'] = record.x_studio_gross_profit / record.price_subtotal
except ZeroDivisionError:
result = None

Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now