Bug 499116

Summary: Incorrect output in column "Capital Gain" for report Capital Gain by account without conversion to base currency
Product: [Applications] kmymoney Reporter: Ralf Habacker <ralf.habacker>
Component: reportsAssignee: KMyMoney Devel Mailing List <kmymoney-devel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: 5.1.90   
Target Milestone: ---   
Platform: Other   
OS: All   
Latest Commit: Version Fixed In: 5.2
Sentry Crash Report:
Attachments: test file
Screenshot showing the issue
Screenshot showing investment gains by account after colum fix
Updated test file
Test file with 3 currencies involved

Description Ralf Habacker 2025-01-25 01:17:51 UTC
STEPS TO REPRODUCE
1. start kmymoney 
2. load attached test file
3. Open report "Investment Capital Gains by Account (Customized - no conversion)"
4. Inspect report

OBSERVED RESULT
In the column “Capital gains” there is an incorrect output in line 6

EXPECTED RESULT
Line 6 should be empty

SOFTWARE/OS VERSIONS
Operating System: openSUSE Leap 15.6
KDE Plasma Version: 5.27.11
KDE Frameworks Version: 5.115.0
Qt Version: 5.15.12

ADDITIONAL INFORMATION
Followup for bug 451392
Comment 1 Ralf Habacker 2025-01-25 01:19:03 UTC
Created attachment 177656 [details]
test file
Comment 2 Ralf Habacker 2025-01-25 01:21:28 UTC
Created attachment 177657 [details]
Screenshot showing the issue
Comment 3 Thomas Baumgart 2025-01-25 09:03:48 UTC
The mark on line 6 should not cover the right most column, because USD 0,00 as grand total is valid information.
Comment 4 Thomas Baumgart 2025-01-25 14:26:17 UTC
Git commit 8639f5773cc2d6b5afd18b75a030aad281e18948 by Thomas Baumgart.
Committed on 25/01/2025 at 14:25.
Pushed by tbaumgart into branch 'master'.

Fix grand total of multi currency list table report
FIXED-IN: 5.2

M  +2    -0    kmymoney/plugins/views/reports/core/listtable.cpp

https://invent.kde.org/office/kmymoney/-/commit/8639f5773cc2d6b5afd18b75a030aad281e18948
Comment 5 Ralf Habacker 2025-01-25 16:16:32 UTC
Git commit 1a28c87d8596294c3082793c284d220b219fb9ec by Ralf Habacker.
Committed on 25/01/2025 at 16:15.
Pushed by habacker into branch 'master'.

In ListTable class rename macro FORCE_FIRST_RANK to OPEN_BALANCE_RANK

In the source code this rank value is mentioned as "opening balance" rank.

M  +1    -1    kmymoney/plugins/views/reports/core/listtable.h
M  +2    -2    kmymoney/plugins/views/reports/core/querytable.cpp

https://invent.kde.org/office/kmymoney/-/commit/1a28c87d8596294c3082793c284d220b219fb9ec
Comment 6 Ralf Habacker 2025-01-25 16:16:38 UTC
Git commit 51be3149933ee9aec882fc7b798a389e5b6f1117 by Ralf Habacker.
Committed on 25/01/2025 at 16:14.
Pushed by habacker into branch 'master'.

Convert variable rank to be an enum for more visibility

M  +22   -27   kmymoney/plugins/views/reports/core/listtable.cpp
M  +4    -0    kmymoney/plugins/views/reports/core/listtable.h

https://invent.kde.org/office/kmymoney/-/commit/51be3149933ee9aec882fc7b798a389e5b6f1117
Comment 7 Ralf Habacker 2025-01-25 16:37:04 UTC
Created attachment 177674 [details]
Screenshot showing investment gains by account after colum fix

Thank you for fixing the column problem.

Looking at the updated report, it makes me wonder what the basic definition of Grant Total is, as currently it simply repeats the values of “Total investment”.
Comment 8 Thomas Baumgart 2025-01-25 16:55:09 UTC
Created attachment 177675 [details]
Updated test file

This test file shows why the grand total it is not simply a duplicate. Another question would be if it makes sense to show totals on price columns at all.
Comment 9 Ralf Habacker 2025-01-25 17:36:36 UTC
Created attachment 177676 [details]
Test file with 3 currencies involved

Thank you, i.e. the lines with “Total Investment” contain the totals of an investment (sub) account and the lines with “Grant Total” contain the totals grouped by currency, which becomes even clearer with the test case with 3 currencies.
Comment 10 Ralf Habacker 2025-01-25 17:45:00 UTC
(In reply to Thomas Baumgart from comment #8)
> Another question would be if it makes sense to show totals on price columns at all.

It does not make sense to add the prices together, as this leads to an incorrect percentage and capital gain. It may be possible to calculate the sum buy price as the sum of the purchase values / sum of the shares and sum last price as sum of ending market value / sum of shares
Comment 11 Ralf Habacker 2025-01-26 15:20:41 UTC
(In reply to Ralf Habacker from comment #7)
> the basic definition of Grant Total is

s/Grant total/Grand Total/  - thanks to Thomas for pointing out.
Comment 12 Thomas Baumgart 2025-01-26 16:25:52 UTC
Git commit 5cdf5c2374957ae4af41c23b2dd1fa65c7281234 by Thomas Baumgart.
Committed on 26/01/2025 at 16:25.
Pushed by tbaumgart into branch 'master'.

Prevent showing totals for columns where this does not make sense

For some columns it does not make sense to sum up the separate row
values. This change prevents from showing them. It also prevents from
showing a zero price in rows for which no price information is present.

M  +21   -6    kmymoney/plugins/views/reports/core/listtable.cpp
M  +2    -2    kmymoney/plugins/views/reports/core/tests/data/test-investment-report-querytable-Investment-Capital-Gains-by-Account-_Customized_.csv
M  +16   -16   kmymoney/plugins/views/reports/core/tests/data/test-investment-report-querytable-Investment-Transactions-_Customized_.csv

https://invent.kde.org/office/kmymoney/-/commit/5cdf5c2374957ae4af41c23b2dd1fa65c7281234