Commit f6659597 authored by Cristian Oneț's avatar Cristian Oneț
Browse files

Fix the investment accounts handling in the institutions view.

Make the investment accounts the only accounts that are added
to their parent in the institutions view. The rest of the
accounts are added at the first level because they don't inherit
the institution from their parent. Thanks to Allen for working on
this.

BUG: 309105
(cherry picked from commit a5371f1e)
parent 62999c11
......@@ -759,7 +759,10 @@ public:
}
QStandardItem *institutionItem = institutionItemFromId(model, institutionId);
QStandardItem *item = itemFromAccountId(institutionItem, account.id());
QStandardItem *parentAccounItem = itemFromAccountId(institutionItem, account.parentAccountId());
// only investment accounts are added to their parent in the institutions view
// this makes hierarchy maintenance a lot easier since the investment accounts
// are the only ones that always have the same institution as their parent
QStandardItem *parentAccounItem = account.isInvest() ? itemFromAccountId(institutionItem, account.parentAccountId()) : 0;
if (!item) {
item = new QStandardItem(account.name());
if (parentAccounItem) {
......@@ -876,7 +879,18 @@ void InstitutionsModel::slotObjectAdded(MyMoneyFile::notificationObjectT objType
if (!account || account->parentAccountId().isEmpty() || account->isIncomeExpense())
return;
// load the account into the institution
static_cast<InstitutionsPrivate *>(d)->loadInstitution(this, *account);
// load the investment sub-accounts if there are any - there could be sub-accounts if this is an add operation
// that was triggered in slotObjectModified on an already existing account which went trough a hierarchy change
QList<MyMoneyAccount> subAccounts;
d->m_file->accountList(subAccounts, account->accountList(), true);
for (QList<MyMoneyAccount>::ConstIterator it_a = subAccounts.constBegin(); it_a != subAccounts.constEnd(); ++it_a) {
if ((*it_a).isInvest()) {
static_cast<InstitutionsPrivate *>(d)->loadInstitution(this, *it_a);
}
}
}
/**
......
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