Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Should Odoo be using decimal.Decimal for rounding precision?

By
George Mengelberg
on 10/30/14, 10:54 AM 2,255 views

Based on the following, it seems as though Decimal is a more appropriate type to 
use when dealing with currency and accounting data.  Is there reason to be 
concerned about rounding accuracy in Odoo?
http://chimera.labs.oreilly.com/books/1230000000393/ch03.html#_solution_42

1

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 10/30/14, 11:17 AM

Your statement is true.. decimal indeed is better for accounting and financial number representation
But whole odoo ( ex openerp, ex-ex tiny erp) orm is developed on float numbers, there is a number of tools developed to handle floating numbers in odoo /openerp (check openerp/tools/float_utils.py ...) and you just need to learn how to use it and will probably not get into problems with floating point number rounding accuracy... The reason for this decision is most likely overall speed... 
Math functions with float numbers are way faster than with decimal... 

On the other hand.. if you are so eager to use decimal numbers ( and once again i agree it is more precise ) .. you can try using tryton...
wich is a fork of tiny erp  and wich is completly based on decimal numbers... 

i will not post link to it on this forum, but our old friend google mingt know a site or two that will clearify this issue a bit more... 

as for me... i'll stick to odoo even if it is based on float numbers... 
you just need to be aware what you are doing...

p.s. i have encountered problem with acuracy and number represenation a few times....
and found an easy and fast workaround  : i let postgres do the math instead of python... (just write correct sql)
it is fast and accurate... (with no floating point problems) :) 


 

Bole, Thanks for the response. I ran into rounding problems as well but, at the time, I could not find a good work around.

George Mengelberg
on 10/30/14, 8:12 PM

George, I think you'll run into rounding problems whether or not you use Decimal. Consider if you have multiple figures to sum with decimal points. You may have a different result if you round the figures first then sum compared to if you sum the figures first then round. For the most part Odoo has tried to be very careful in those calculation. For instance, In Odoo, Invoice Tax is calculated from Invoice Line's Subtotal which is discounted first. In my country discount is applied to the Invoice's total, not individual lines. This difference has pose some interesting cases in my project when dealing with Invoice figures that are rounded.

Ivan
on 10/31/14, 9:23 AM
1

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 10/31/14, 12:23 AM

For me, the solution is to know when to round amount currency. I set 10 for decimal precision rate (because IDR/USD) and do floating point calculation. At the end round the amount to decimal precision already defined (2, for example).

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/30/14, 10:54 AM
Seen: 2255 times
Last updated: 3/16/15, 8:10 AM