Bug 451392 - Capital Gains report lists wrong cost value when purchase is in foreign currency
Summary: Capital Gains report lists wrong cost value when purchase is in foreign currency
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: reports (show other bugs)
Version: 5.1.2
Platform: Mint (Ubuntu based) Linux
: NOR major
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks: 488491
  Show dependency treegraph
 
Reported: 2022-03-11 12:23 UTC by Mark Medoff
Modified: 2025-01-25 01:22 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
possible test file (28.96 KB, text/xml)
2024-10-25 14:18 UTC, Ralf Habacker
Details
Screenshot showing investment gains by account report with KMyMoney 4.8 (32.98 KB, image/png)
2024-10-25 14:20 UTC, Ralf Habacker
Details
Screenshot showing investment gains by account report with KMyMoney 5.1.80 (24.47 KB, image/png)
2024-10-25 14:25 UTC, Ralf Habacker
Details
test file (updated) (5.56 KB, text/xml)
2024-12-24 13:29 UTC, Ralf Habacker
Details
Screenshot showing Capital Gains report (only owned) (93.06 KB, image/png)
2024-12-24 13:30 UTC, Ralf Habacker
Details
Screenshot from version 5.1.90 - Investment Capital Gains by Account (Customized) (65.65 KB, image/png)
2025-01-24 20:47 UTC, Ralf Habacker
Details
Screenshot from version 5.1.90 - Copy of Investment Capital Gains by Account (Customized - no conversion) (94.21 KB, image/png)
2025-01-24 20:48 UTC, Ralf Habacker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Medoff 2022-03-11 12:23:35 UTC
SUMMARY
My Brokerage account and investments are in local currency (US$) with one exception. One investment was purchased in a foreign currency (JPY) and that investment account is designated in JPY. When I run the Capital Gains report (for investments I still own), it lists the correct market value for the JPY investment but cost is wrong. It appears to have divided the cost in JPY twice by the US$ to JPY rate. In this case, correct cost per share is $52.24 (5550 JPY @ 106.2392 JPY/USD) but the program reports a cost of $0.49. Reviewing Price pairs, only the correct price pair of USD -> JPY = 106.2392 exists for that date. There is no JPY -> USD pair that might conflict. Investment Ledger also shows all amounts correctly.


STEPS TO REPRODUCE
1.  Setup a foreign currency investment account
2.  Purchase an investment in the foreign currency
3.  Run Capital Gains report for owned investments

OBSERVED RESULT
Market value of foreign currency is correctly displayed in local currency but cost is wrong

EXPECTED RESULT
Cost should be calculated correctly in local currency

SOFTWARE/OS VERSIONS

(available in About System) 
KDE Frameworks 
Version 5.91.0

Qt 
Version 5.15.2 (built against 5.15.2)

ADDITIONAL INFORMATION
Comment 1 Ralf Habacker 2024-10-24 04:31:11 UTC
A test file would be helpful to determine whether the problem is also reproducible on the current git master branch.
Comment 2 Ralf Habacker 2024-10-25 14:18:49 UTC
Created attachment 175230 [details]
possible test file
Comment 3 Ralf Habacker 2024-10-25 14:20:07 UTC
Created attachment 175231 [details]
Screenshot showing investment gains by account report with KMyMoney 4.8
Comment 4 Ralf Habacker 2024-10-25 14:25:33 UTC
Created attachment 175232 [details]
Screenshot showing investment gains by account report with KMyMoney 5.1.80

With kmymoney 5.1.80 the same report is empty.
Comment 5 Bug Janitor Service 2024-11-09 03:46:43 UTC
🐛🧹 ⚠️ This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information, then set the bug status to REPORTED. If there is no change for at least 30 days, it will be automatically closed as RESOLVED WORKSFORME.

For more information about our bug triaging procedures, please read https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging.

Thank you for helping us make KDE software even better for everyone!
Comment 6 Ralf Habacker 2024-12-24 10:07:15 UTC
(In reply to Ralf Habacker from comment #2)
> Created attachment 175230 [details]
> possible test file

This test file does not match the initial reported error. An update is required.
Comment 7 Ralf Habacker 2024-12-24 12:16:37 UTC
(In reply to Ralf Habacker from comment #6)
> This test file does not match the initial reported error. An update is
> required.

It looks not to be possible to create an according test file for an investment using a security.

How to produce
1. start kmymoney
2. select tab investments
3. Create new account
4. enter values
5. enable "creating security"
6. finish creating

After processing step 6. there is no security account added.
Comment 8 Ralf Habacker 2024-12-24 13:29:20 UTC
(In reply to Ralf Habacker from comment #7)
> (In reply to Ralf Habacker from comment #6)
> > This test file does not match the initial reported error. An update is
> > required.
> 
> It looks not to be possible to create an according test file for an
> investment using a security.
> 
> How to produce
> 1. start kmymoney
> 2. select tab investments
> 3. Create new account
> 4. enter values
> 5. enable "creating security"
> 6. finish creating
> 
> After processing step 6. there is no security account added.

To add a security, the investment account must be selected in the account list and ‘New investment’ selected in the right-click menu.

Alternatively, you can select ‘New investment’ in the right-click menu via the open investment account in the general ledger.
Comment 9 Ralf Habacker 2024-12-24 13:29:50 UTC
Created attachment 176867 [details]
test file (updated)
Comment 10 Ralf Habacker 2024-12-24 13:30:43 UTC
Created attachment 176868 [details]
Screenshot showing Capital Gains report (only owned)
Comment 11 Ralf Habacker 2025-01-23 17:48:07 UTC
Git commit ff72e2d8ab942436fdc4e0758a4030672ed33a11 by Ralf Habacker.
Committed on 23/01/2025 at 07:15.
Pushed by habacker into branch 'master'.

Add test report for investment transactions

The still incorrect display of values for added/removed shares
is caused by an incorrect mixing of the implementation of price
and currency conversion and will be fixed elsewhere.
Related: bug 498033

A  +27   -0    kmymoney/plugins/views/reports/core/tests/data/test-investment-report-querytable-Investment-Transactions-_Customized_.csv
M  +7    -4    kmymoney/plugins/views/reports/core/tests/data/test-investment.xml

https://invent.kde.org/office/kmymoney/-/commit/ff72e2d8ab942436fdc4e0758a4030672ed33a11
Comment 12 Ralf Habacker 2025-01-24 20:47:00 UTC
Created attachment 177652 [details]
Screenshot from version 5.1.90 - Investment Capital Gains by Account (Customized)

Values are looking correct
Comment 13 Ralf Habacker 2025-01-24 20:48:17 UTC
Created attachment 177653 [details]
Screenshot from version 5.1.90 - Copy of Investment Capital Gains by Account (Customized - no conversion)

Values are looking correct, but there is a duplicated line displayed (see red rectangle in the screenshot)
Comment 14 Ralf Habacker 2025-01-25 01:08:43 UTC
(In reply to Ralf Habacker from comment #13)
>  but there is a duplicated line displayed (see red rectangle in the screenshot)

The wrong output is generated here https://invent.kde.org/office/kmymoney/-/blob/master/kmymoney/plugins/views/reports/core/listtable.cpp#L313 with rank == 5.
Comment 15 Ralf Habacker 2025-01-25 01:22:30 UTC
(In reply to Ralf Habacker from comment #14)
> (In reply to Ralf Habacker from comment #13)
> >  but there is a duplicated line displayed (see red rectangle in the screenshot)
> 
> The wrong output is generated here
> https://invent.kde.org/office/kmymoney/-/blob/master/kmymoney/plugins/views/
> reports/core/listtable.cpp#L313 with rank == 5.

Moved to bug 499116