Bug 501815 - In credit account the "Online Balance" bar is red even when account and online balances are equal
Summary: In credit account the "Online Balance" bar is red even when account and onlin...
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: general (show other bugs)
Version: 5.1.92
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-21 01:24 UTC by yzg
Modified: 2025-03-31 09:50 UTC (History)
0 users

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yzg 2025-03-21 01:24:24 UTC
SUMMARY
After kmymoney update to 5.1.92, the credit account "Online Balance" bar became red color (error indication) even the account balance and online balances are equal.

NOTE: 
This problem affects only the credit account. Other accounts types are behaving as expected.

Looking at the source code:
file: kmymoney/views/onlinebalancedelegate.cpp
function:  OnlineBalanceDelegate::paint()
I printed the values used in the condition
KColorScheme::BackgroundRole role = (accountBalance == onlineBalanceValue) ? KColorScheme::PositiveBackground : KColorScheme::NegativeBackground;

qDebug() << "accountBalance    = " << accountBalance << "\n";
qDebug() << "onlineBalanceValue= " << onlineBalanceValue << "\n";
    
When I opened the credit account, I got the output:
accountBalance    =  -1423.76 "-35594/25" 
onlineBalanceValue=  1423.76 "35594/25" 

The problem is the negative sign of the account balance.


STEPS TO REPRODUCE
1. Update to version 5.1.92
2. Import bank transactions for a credit account using OFX

OBSERVED RESULT
The "Online Balance" bar is red even if the account and online balances are the same


EXPECTED RESULT
The "Online Balance" bar should be green if the account and online balances are the same

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 
KDE Plasma Version: 6.3.3
KDE Frameworks Version: 5.116.0
Qt Version: 5.15.16

ADDITIONAL INFORMATION
This function used to work as expected in version 5.1.3 before the update to 5.1.92
Comment 1 yzg 2025-03-21 08:59:22 UTC
Suggested fix:

--- onlinebalancedelegate.cpp   2025-03-21 19:55:20.508887229 +1100
+++ onlinebalancedelegate.cpp.new       2025-03-21 19:53:28.868843506 +1100
@@ -148,9 +148,10 @@
     }
     const auto onlineBalanceValue = index.data(eMyMoney::Model::AccountOnlineBalanceValueRole).value<MyMoneyMoney>();
     const auto accountId(index.data(eMyMoney::Model::IdRole).toString());
+    const MyMoneyMoney showValuesInverted = index.data(eMyMoney::Model::ShowValueInvertedRole).toBool() ? MyMoneyMoney::MINUS_ONE : MyMoneyMoney::ONE;
     auto accountBalance(onlineBalanceValue);
     if (!accountId.isEmpty()) {
-        accountBalance = MyMoneyFile::instance()->balance(accountId, onlineBalanceDate);
+        accountBalance = MyMoneyFile::instance()->balance(accountId, onlineBalanceDate) * showValuesInverted;
         onlineBalanceValueTxt = onlineBalanceValue.formatMoney(index.data(eMyMoney::Model::AccountFractionRole).toInt());
     }
Comment 2 Thomas Baumgart 2025-03-21 10:52:16 UTC
Well, the solution might work in your case but there are others where it might fail. The problem here is that we don't know how the institution reports the credit card account balance. My idea currently is - and I present that here for discussion - to compare the absolute values of those two balances. I think it is very unlikely that this will produce false positives (meaning the status will show as green when it is actually red). Thoughts?
Comment 3 yzg 2025-03-21 12:39:15 UTC
I think it will work.
Comment 4 Jack 2025-03-21 12:41:12 UTC
I'm not certain, but I think I may have actually seen this problem on occasion.  I'll have to check my OFX for negative balance, but I do like the absolute value concept.
Comment 5 Bug Janitor Service 2025-03-21 13:53:29 UTC
A possibly relevant merge request was started @ https://invent.kde.org/office/kmymoney/-/merge_requests/267
Comment 6 Thomas Baumgart 2025-03-31 09:50:44 UTC
Git commit 1051093bb69629561c3bfc0ab167571ccc36020f by Thomas Baumgart, on behalf of Thomas Baumgart.
Committed on 31/03/2025 at 09:19.
Pushed by tbaumgart into branch 'master'.

If only sign of balance differs treat as OK

If only the sign of the balance differs between the online received
value and the one calculated by KMyMoney mark it as OK anyway.
FIXED-IN: 5.2

M  +2    -1    kmymoney/views/onlinebalancedelegate.cpp

https://invent.kde.org/office/kmymoney/-/commit/1051093bb69629561c3bfc0ab167571ccc36020f