odoo/odoo#181104
Created by Cyrus Robins (cyro)
Blocked
- Merge method
- Review
-
CI
- legal/cla: Contributor License Agreement check
- ci/runbot: Odoo Test Suite
- ci/upgrade_enterprise: Test upgrades for enterprise master
- ci/template: Contact runbot team on discord for help.
- ci/style: Optional style check. Ignore it only if strictly necessary.
- ci/security: Required security check. Can only be ignored by security team.
- label
- odoo-dev:17.0-opw-4078865-cyro
- head
- 8dcfeff5aba294e6958f5b19affd339fe9fecdda
odoo/odoo | |
---|---|
17.0 | #181104 missing statuses missing r+ |
18.0 | |
saas-18.2 | |
saas-18.3 | |
saas-18.4 | |
19.0 | |
master |
[FIX] account: Fix currency rounding issues when syncing invoice
Currently, it is possible to create currency rounding issues on invoices with very specific workflows. Here is the setup to reproduce:
1. Create a 20% tax
2. Add currency exchange rates for 2 different dates. For the older date, set it to 0.233661237937 and for the newer date set the rate to 0.233666697822.
3. Create an invoice in the foreign currency for any product with a unit price of 88.54, and set the 20% tax on it. DO NOT set a date on the invoice yet
4. Save the Invoice
5. Change the date to the older date of the currency exchange rates, try to save again and the error will appear
This is due to the sync_invoices method doing a raw rounding of each aml balance, including the payment_term
line, which can cause rounding mismatches. In the above example, the product line computes to 378.924638 in foreign currency, and the tax line rounds to 75.793487 in foreign currency. These will both round down, summing to 454.71. The payment_term line of 106.25 will be converted directly to foreign currency, yielding a value of 454.718125 which will round up. This will create an unbalanced journal entry which cannot be made. This only occurs when updating an existing invoice with a new date, as the create
flow for account_move
records creates the payment_term line based on the sum of the individual line balances.
The fix I have implemented translates this logic into the sync_invoices
method; when sync invoices is called, the new logic will specifically check if the currency_rate
has been updated in the recordset. If it has, then we go into a new flow which will re-round the non-payment term lines using the new rate, and aggregate those values. After all of the rounded values have been aggregated, the payment_term line's balance will be updated accordingly.
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr