Commit db9dae70 authored by Thomas Baumgart's avatar Thomas Baumgart
Browse files

Assign correct parent category to new categories

In case a category is selected use it as the parent for new categories.
Change the parent category when the category type changes between income
and expense.

BUG: 428164
FIXED-IN: 5.1.1
(cherry picked from commit f204a28d)
parent d3d72a02
Pipeline #41384 failed with stage
in 3 minutes and 16 seconds
......@@ -88,32 +88,43 @@ public:
auto file = MyMoneyFile::instance();
// initialize the m_parentAccount member
if (!m_account.parentAccountId().isEmpty()) {
try {
m_parentAccount = file->account(m_account.parentAccountId());
} catch (MyMoneyException&) {
m_account.setParentAccountId(QString());
}
}
// assign a standard account if the selected parent is not set/found
QVector<Account::Type> filterAccountGroup {m_account.accountGroup()};
switch (m_account.accountGroup()) {
case Account::Type::Asset:
m_parentAccount = file->asset();
break;
case Account::Type::Liability:
m_parentAccount = file->liability();
break;
case Account::Type::Income:
m_parentAccount = file->income();
break;
case Account::Type::Expense:
m_parentAccount = file->expense();
break;
case Account::Type::Equity:
m_parentAccount = file->equity();
break;
default:
qDebug("Seems we have an account that hasn't been mapped to the top five");
if (m_categoryEditor) {
m_parentAccount = file->income();
filterAccountGroup[0] = Account::Type::Income;
} else {
if (m_account.parentAccountId().isEmpty()) {
switch (m_account.accountGroup()) {
case Account::Type::Asset:
m_parentAccount = file->asset();
filterAccountGroup[0] = Account::Type::Asset;
}
break;
case Account::Type::Liability:
m_parentAccount = file->liability();
break;
case Account::Type::Income:
m_parentAccount = file->income();
break;
case Account::Type::Expense:
m_parentAccount = file->expense();
break;
case Account::Type::Equity:
m_parentAccount = file->equity();
break;
default:
qDebug("Seems we have an account that hasn't been mapped to the top five");
if (m_categoryEditor) {
m_parentAccount = file->income();
filterAccountGroup[0] = Account::Type::Income;
} else {
m_parentAccount = file->asset();
filterAccountGroup[0] = Account::Type::Asset;
}
}
}
ui->m_amountGroup->setId(ui->m_grossAmount, 0);
......@@ -391,6 +402,13 @@ public:
q->connect(ui->m_qcomboboxInstitutions, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated), q, &KNewAccountDlg::slotLoadInstitutions);
QModelIndex parentIndex;
if (!m_parentAccount.id().isEmpty()) {
const auto baseIdx = model->indexById(m_parentAccount.id());
parentIndex = m_filterProxyModel->mapFromSource(baseIdx);
}
selectParentAccount(parentIndex);
ui->m_vatCategory->setChecked(false);
ui->m_vatAssignment->setChecked(false);
......@@ -566,6 +584,14 @@ public:
}
}
void selectParentAccount(const QModelIndex& parentIndex)
{
ui->m_parentAccounts->expand(parentIndex);
ui->m_parentAccounts->selectionModel()->select(parentIndex, QItemSelectionModel::SelectCurrent);
ui->m_parentAccounts->setCurrentIndex(parentIndex);
ui->m_parentAccounts->scrollTo(parentIndex, QAbstractItemView::PositionAtCenter);
}
KNewAccountDlg* q_ptr;
Ui::KNewAccountDlg* ui;
MyMoneyAccount m_account;
......@@ -852,6 +878,8 @@ void KNewAccountDlg::slotAccountTypeChanged(int index)
// update the account group displayed in the accounts hierarchy
d->m_filterProxyModel->clear();
d->m_filterProxyModel->addAccountGroup(QVector<Account::Type> {d->m_account.accountGroup()});
d->selectParentAccount(d->m_filterProxyModel->index(0, 0));
}
} catch (const MyMoneyException &) {
qWarning("Unexpected exception in KNewAccountDlg::slotAccountTypeChanged()");
......
Markdown is supported
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