Bug 365177 - Changing investment fraction doesn't change rounding behavior
Summary: Changing investment fraction doesn't change rounding behavior
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: general (show other bugs)
Version: 4.8.0
Platform: Arch Linux Linux
: NOR minor
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
: 377087 (view as bug list)
Depends on:
Blocks: 388698
  Show dependency treegraph
 
Reported: 2016-07-07 03:56 UTC by David Chamberlain
Modified: 2018-03-28 08:00 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.0.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Chamberlain 2016-07-07 03:56:46 UTC
Changed the "Fraction" field on the investment details dialog from "1000" to "10000" so I could accurately record some dividend reinvestment transactions. On the ledger, the quantity is now shown with 4 decimal places, but any quantity I enter is still rounded to 3 decimal places.

A workaround is to change the "Fraction", then exit and restart kmymoney before updating quantities on the ledger.

Reproducible: Always

Steps to Reproduce:
1.Create an investment, accept default "Fraction" of 100
2.Edit the investment and increase the "Fraction" to 1000
3.Open investment account ledger and create a transaction involving the above investment. Use a quantity with three numbers after the decimal, such as 1.123.

Actual Results:  
The quantity on the ledger will be 1.120.

Expected Results:  
The quantity on the ledger should be 1.123

It appears that the transaction price is correctly calculated using the unrounded quantity, causing the transaction data recorded in the ledger to be inconsistent. I.e. Quantity x Share price != Transaction price
Comment 1 Jack 2016-07-07 15:24:31 UTC
Please clarify:  do you see the correct numbers after restarting KMM?  If so, the issue is not that the rounding behaviour isn't change, but that it isn't changed immediately, and requires a restart of KMM to take effect.  One is a real bug, the other is simply an inconvenience, although it might be possible to have the change take effect immediately.
Comment 2 David Chamberlain 2016-07-08 03:44:41 UTC
No, if you restart after step 3 (above) the incorrectly rounded number is still on the ledger. However, after the restart you can edit the transaction, reenter the precise quantity, and then the rounding is correct.

In order to get the correct quantity recorded in the ledger, you must: change investment "Fraction", restart, then create/edit transaction.

BTW, I've only tried this with Stock type investments. Not sure if it matters.
Comment 3 NSLW 2017-03-27 17:45:07 UTC
*** Bug 377087 has been marked as a duplicate of this bug. ***
Comment 4 NSLW 2017-04-01 06:19:11 UTC
Git commit c6e31c96a03ad5a7ec5e3695bbfa8336181ab81c by Łukasz Wojniłowicz.
Committed on 01/04/2017 at 06:16.
Pushed by wojnilowicz into branch 'master'.

Fix rounding problem with investments

Patch introduces rounding rules per security for fixing bug #372163. It
seems that this broker always rounds amounts down while my broker rounds
amounts depending on the outlying digit, so it couldn't work for both of
us without rules.

Rounding is done in InvestTransactionEditor because it has all needed
informations at hand.

No rounding of shares is done in InvestTransactionEditor::setupPrice.
Transaction from bug #372163 looks as follows:
brokerage:
shares = 1,009 ; value = 1,009
investment:
shares = -1 ; value = 1,009

InvestTransactionEditor::setupPrice causes brokerage to look as follows:
shares = 1,01 ; value = 1,009
As we can see shares and value diverge, which is unacceptable here.

Patch makes assumption that transaction has only single split of
stock/mutual fund/bond.
Related: bug 345655, bug 357784, bug 372163
FIXED-IN:5.0

Differential Revision: https://phabricator.kde.org/D5187

Signed-off-by: Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>

M  +32   -15   kmymoney/dialogs/investtransactioneditor.cpp
M  +31   -0    kmymoney/kmymoneyutils.cpp
M  +22   -0    kmymoney/kmymoneyutils.h
M  +39   -0    kmymoney/mymoney/mymoneysecurity.cpp
M  +27   -8    kmymoney/mymoney/mymoneysecurity.h
M  +1    -0    kmymoney/mymoney/storage/mymoneydbdef.cpp
M  +3    -0    kmymoney/mymoney/storage/mymoneystoragesql.cpp
M  +4    -3    kmymoney/widgets/transaction.cpp
M  +11   -0    kmymoney/wizards/newinvestmentwizard/kinvestmentdetailswizardpage.cpp
M  +104  -90   kmymoney/wizards/newinvestmentwizard/kinvestmentdetailswizardpagedecl.ui
M  +2    -0    kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.cpp

https://commits.kde.org/kmymoney/c6e31c96a03ad5a7ec5e3695bbfa8336181ab81c
Comment 5 Joe Byers 2018-01-09 18:54:09 UTC
Was this fixed so a restart is not required?  I see this issue in Version 4.8.0.