Bug 511553

Summary: Closed account showing incorrect balance in net worth by month report
Product: [Applications] kmymoney Reporter: kieran
Component: reportsAssignee: KMyMoney Devel Mailing List <kmymoney-devel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: 5.2.1   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Other   
Latest Commit: Version Fixed/Implemented In: 5.2.2
Sentry Crash Report:
Attachments: Net worth by month with wrong balance
Account with correct balance when open
Transactions showing 0 balance on account

Description kieran 2025-11-03 00:36:19 UTC
Created attachment 186443 [details]
Net worth by month with wrong balance

SUMMARY
I have a 0 balance reconcilled account. 
In the net worth by month report it shows correctly as currently balance 0 if I have the account open but if I close the account, it then shows an incorrect negative balance on the monthly report.

STEPS TO REPRODUCE
1. Have an account with 0 balance where it went to zero a few months ago.
2. View net worth by month report, account shows up with currently 0 balance.
3. Close account
4. View net worth by month report, account shows up with new incorrect negative balance.

OBSERVED RESULT
Incorrect balance in net worth by month report for closed account with 0 balance.

EXPECTED RESULT
Correct 0 balance in net worth by month report for closed account with 0 balance.

SOFTWARE/OS VERSIONS
Windows: 10 22H2
KDE Frameworks Version: 6.18.0

ADDITIONAL INFORMATION
Balances show correctly if account is open or closed in the net worth by year report and all other reports that I can find. It is only the monthly report that is wrong. This happens even if I create a new monthly report from scratch so it isn't my customisations.
Comment 1 kieran 2025-11-03 00:36:39 UTC
Created attachment 186444 [details]
Account with correct balance when open
Comment 2 kieran 2025-11-03 00:36:55 UTC
Created attachment 186445 [details]
Transactions showing 0 balance on account
Comment 3 Thomas Baumgart 2025-11-03 07:36:49 UTC
Problem seems to be, that when the account is closed, the starting balance for the report is not calculated/used.
Comment 4 kieran 2025-11-03 21:52:37 UTC
I've just seen that changing the range on the monthly report from 12 months to 6 months produces a different wrong negative balance. It was -300 for 12 months, but changes to -1211.10 for the 6 month view.
Comment 5 Thomas Baumgart 2025-11-08 16:48:49 UTC
Git commit 2eedc2ec2bb7c46209c411702e63da81dae77d61 by Thomas Baumgart.
Committed on 08/11/2025 at 16:48.
Pushed by tbaumgart into branch 'master'.

Fix pivot reports with transactions in closed accounts

The calculation of the balance of closed accounts when they need to be
included in a pivot report did not work properly. This change fixes the
problem and provides a test case for the scenario.
FIXED-IN: 5.2.2

M  +10   -10   kmymoney/mymoney/mymoneyfile.h
M  +1    -1    kmymoney/mymoney/storage/journalmodel.cpp
M  +16   -9    kmymoney/plugins/views/reports/core/pivottable.cpp
M  +1    -0    kmymoney/plugins/views/reports/core/tests/data/CMakeLists.txt
A  +8    -0    kmymoney/plugins/views/reports/core/tests/data/csv/test-closed-account-report-pivottable-Net-Worth-By-Month-_Customized_.csv
A  +95   -0    kmymoney/plugins/views/reports/core/tests/data/test-closed-account.xml

https://invent.kde.org/office/kmymoney/-/commit/2eedc2ec2bb7c46209c411702e63da81dae77d61
Comment 6 Thomas Baumgart 2025-11-09 16:26:34 UTC
Git commit 4887bebb128cdce0278cf721645bbf50eca4d319 by Thomas Baumgart.
Committed on 08/11/2025 at 16:55.
Pushed by tbaumgart into branch '5.2'.

Fix pivot reports with transactions in closed accounts

The calculation of the balance of closed accounts when they need to be
included in a pivot report did not work properly. This change fixes the
problem and provides a test case for the scenario.
FIXED-IN: 5.2.2
(cherry picked from commit 2eedc2ec2bb7c46209c411702e63da81dae77d61)

M  +10   -10   kmymoney/mymoney/mymoneyfile.h
M  +1    -1    kmymoney/mymoney/storage/journalmodel.cpp
M  +16   -9    kmymoney/plugins/views/reports/core/pivottable.cpp
M  +1    -0    kmymoney/plugins/views/reports/core/tests/data/CMakeLists.txt
A  +8    -0    kmymoney/plugins/views/reports/core/tests/data/test-closed-account-report-pivottable-Net-Worth-By-Month-_Customized_.csv
A  +95   -0    kmymoney/plugins/views/reports/core/tests/data/test-closed-account.xml

https://invent.kde.org/office/kmymoney/-/commit/4887bebb128cdce0278cf721645bbf50eca4d319
Comment 7 kieran 2025-11-12 10:11:44 UTC
I've downloaded the latest build and tried it out and it does indeed work for my use case. Thank you very much!