Trouble rounding residual amount into invoice : may be a client trouble

Bug #497078 reported by Joël Grand-Guillaume @ camptocamp
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
High
vir (Open ERP)

Bug Description

Hi !

On the last stable from today, the residual amount shown into the client is may be erroneous or the _amount_residual function of invoice.py is wrong. Depends on the point of view...

When you pay an invoice with pay invoice wizard with the values listed bellow, you get :

- Residual amount given by the _amount_residual function = 0,0096... This is perfectly correct according to computation.
- The value shown into the client is : 0,01.

According to the server settings and currency setting, this is wrong: I should see 0,00. So the question is here:

Should the _amount_residual function return 0,00 (even if it's not really the case) to have 0,00 shown into the client or should the client "cut" the number following the third floating number : 0,0096... => 0,00 ?

I think this should be corrected in the client, but may be I'm wrong...

Thanks for your opinion.

To reproduce it, do the following:
------------------------------------------
Given I am loged as admin user with password admin used
      And the company currency is set to EUR
      And the following currency rate settings are:
      |code|rate|name|
      |EUR|1.000|01-01-2009|
      |CHF|1.644|01-01-2009|
      |CHF|1.500|09-09-2009|
      |USD|1.3785|01-01-2009|
      And a cash journal in USD exists
      And a cash journal in CHF exists
      And a cash journal in EUR exists

    Given I have recorded on the 1 jan 2009 a supplier invoice (in_invoice) of 1000,0 CHF without tax called MyFirstSupplierInvoiceBankStatement
    When I press the valiate button
    Then I should see the invoice MyFirstSupplierInvoiceBankStatement open
    And the residual amount = 1000,0

    Given I have recorded on the 1 jan 2009 a supplier invoice (in_invoice) of 1000,0 CHF without tax called MySecondSupplierInvoiceBankStatement
    When I press the valiate button
    Then I should see the invoice MySecondSupplierInvoiceBankStatement open
    And the residual amount = 1000,0

    Given I create a new bank statement called MyBankStatement with a CHF account journal
    And I import on the 1 jan 2009, the following invoice : MyFirstSupplierInvoiceBankStatement,MySecondSupplierInvoiceBankStatement
    Then I should see an draft bank statement

    Given I take the created invoice MySecondSupplierInvoiceBankStatement
    When I call the Pay invoice wizard
    And I completely pay the residual amount in CHF on the 13 sep 2009
    Then I should see a residual amount of 0.0 CHF.-

Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) wrote :

Hello,

You need to set --price-accuracy=4 in the configuration.

If you are using Ubuntu then start the server from terminal with following way :

./openerp-server --addons-path=../../addons-5.0.6 --price_accuracy=4

Hope this will help you.

Thanks.

Changed in openobject-addons:
status: New → Incomplete
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi !

I try with this option on my test server, but it doesn't change my test results :( The accuracy trouble is still here .

I also create a new database with this option, and in this case it return : 0.0096 instead of 0.01 which is better. But I still have a difference...

I don't really know how to handle this the right way. _amount_residual function should may be return 0,0 in that case, but it's not a good solution neither cause this difference could mean the invoice still has an open amount...

Thanks to give your opinion,

Changed in openobject-addons:
status: Incomplete → Confirmed
Revision history for this message
Jan Verlaan (jan-verlaan) wrote :

This problem with handling multi-currency (e.g. comp = EUR and invoice = CHF) is common for all financial packages due to rounding from one to another currency.
From technical point of view best way to handle this for OpenERP would be storing the financial values in database without rounding. Then round the value when displaying/print the value and only round in the database at the end of a workflow. Currently OpenERP doesn't do this.
Resulting you can expect this kind of rounding issues. Even when above methode would be used, you still can get rounding issues, but the diffs are smaller, thus more accurate.

The only way you can handle this for now is to accept the diff due to the multi-currency rounding and use of a write-off account to reconcile the invoice. As far I know this is allowed in every European country and common practice.
On the end of year this write-off account is more or less zero, because all rounding write-offs booked will equalize this account.

On the long term we could think of a redesign for all financial fields to store without rounding, change the forms to round the display fields, same for reports and add a new function to round the database value only at the end of a workflow.

Revision history for this message
Jan Verlaan (jan-verlaan) wrote :

In addition to my above #3 comment.

OpenERP is rounding every stored value, resulting in several roundings during the total workflow. This will lead ad the end (reconcile part) to more inaccuracy as needed. Thus this is not only a multi-currency problem, but a general rounding problem, where it is more visible with multi-currency. Above mentioned technical outline could solve most of the rounding issues in OpenERP, but needs a big rework.

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

can we do something about it in 5.0? I'm planning it on 5.2 because it's seems very important to have this fixed in 5.2. Nonetheless would also be nice to have it fixed in 5.0, but given the amount of change and work required I'm not sure Tiny can do it and accept it, while it would absorb a lot of resource if they attempt doing it in a backward compatible way that would better be assigned to fixing other important bugs. Thoughts?

Changed in openobject-addons:
importance: Undecided → High
milestone: none → v5.2
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi,

So I reference it in my BP about rounding trouble into OpenERP here:

https://blueprints.launchpad.net/openobject-server/+spec/generic-accuracy-improvement

Regards,

Joël

Revision history for this message
Cloves Almeida (cjalmeida) wrote :

We have two issues: better rounding accuracy and what to do with rounding differences. IMO, writing-off the difference is the right thing to do we should just automate the process (like configuring a default write-off account, change methods that do the rounding to create a write-off move, etc.)

Changed in openobject-addons:
assignee: nobody → vir (Open ERP) (vir-tinyerp)
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Subscribers,

Would you please recheck with the lastest codes?

Here are the steps I followed:
1. Change the system date back to 1st jan.Restart the server.
2. New supplier Invoice of 1000 CHF on date 1st of Jan 2009.(Provided, the CHF rates are as per the discussion above).
3. I validate the invoice.
4. Create a new bank statement ,import the mentioned move lines.(wasn't this step useless ,guys?)
5. Change the system date to today's date.
6. Pay the invoice via wizard from invoice.
7. Observe the Residual amount. I get 0.00 in my case.

Thank you.

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi !

According to the same scenario (made with OERPScenario), this bug is no longer here !

It's probably because you change the rounding into res_currency : well done !

Regards,

Joël

Changed in openobject-addons:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.