Commit b075c99b authored by Jérome Perrin's avatar Jérome Perrin

accounting: always compare rounded values when indexing balance transactions

To prevent rounding errors, we always compare rounded values to the
precision of the accounting currency. There was a place here where we
were using -= without rounding, which caused to detect a difference
between new and current stock and insert a line for 0 in an existing
instance for which some accounting lines were created with too precise
values - but not in a way that was detected by the assertions in
AccountingPeriod_createBalanceTransaction.

Rounding here as well solved the problem with that data.
parent fb18e4e2
...@@ -355,7 +355,9 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -355,7 +355,9 @@ class BalanceTransaction(AccountingTransaction, Inventory):
# matching_diff are negated later # matching_diff are negated later
if matching_diff: if matching_diff:
matching_diff['quantity'] -= round(new_stock['quantity'], precision) matching_diff['quantity'] = round(
matching_diff['quantity'] - new_stock['quantity'],
precision)
# Matching_diff and new_stock must be consistent. # Matching_diff and new_stock must be consistent.
# both with total price or none. # both with total price or none.
if matching_diff['total_price'] and new_stock['total_price']: if matching_diff['total_price'] and new_stock['total_price']:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment