Commit 1d9158e1 authored by Thomas Baumgart's avatar Thomas Baumgart
Browse files

Changing the security of a transaction does not update balance

When the security of an investment transaction (e.g. buy) is changed
from security A to security B, the balance of security A does not get
updated. This causes to display false values.

This change fixes the problem by first removing the split referencing
security A from the list of transactions and then updating the balance.

BUG: 411015
FIXED-IN: 5.0.8
parent cc79f506
......@@ -669,21 +669,17 @@ void MyMoneyStorageMgr::modifyTransaction(const MyMoneyTransaction& transaction)
if (it_t == d->m_transactionList.end())
throw MYMONEYEXCEPTION_CSTRING("invalid transaction key");
// remove old transaction from lists
d->m_transactionList.remove(oldKey);
// and adjust the balances of the accounts
foreach (const auto split, (*it_t).splits()) {
auto acc = d->m_accountList[split.accountId()];
// we only need to adjust non-investment accounts here
// as for investment accounts the balance will be recalculated
// after the transaction has been added.
if (!acc.isInvest()) {
d->adjustBalance(acc, split, true);
acc.touch();
d->m_accountList.modify(acc.id(), acc);
}
d->adjustBalance(acc, split, true);
acc.touch();
d->m_accountList.modify(acc.id(), acc);
}
// remove old transaction from lists
d->m_transactionList.remove(oldKey);
// add new transaction to lists
QString newKey = transaction.uniqueSortKey();
d->m_transactionList.insert(newKey, transaction);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment