bool NewSplitEditor::Private::categoryChanged(const QString& accountId) { bool rc = true; if(!accountId.isEmpty()) { try { MyMoneyAccount category = MyMoneyFile::instance()->account(accountId); const bool isIncomeExpense = category.isIncomeExpense(); ui->costCenterCombo->setEnabled(isIncomeExpense); ui->costCenterLabel->setEnabled(isIncomeExpense); costCenterRequired = category.isCostCenterRequired(); rc &= costCenterChanged(ui->costCenterCombo->currentIndex()); } catch (MyMoneyException &e) { qDebug() << "Ooops: invalid account id" << accountId << "in" << Q_FUNC_INFO; } } return rc; }
QValueList<MyMoneyAccount> MyMoneyForecast::budgetAccountList(void) { MyMoneyFile* file = MyMoneyFile::instance(); QValueList<MyMoneyAccount> accList; QStringList emptyStringList; //Get all accounts from the file and check if they are of the right type to calculate forecast file->accountList(accList, emptyStringList, false); QValueList<MyMoneyAccount>::iterator accList_t = accList.begin(); for(; accList_t != accList.end(); ) { MyMoneyAccount acc = *accList_t; if(acc.isClosed() //check the account is not closed || (!acc.isIncomeExpense()) ) { accList.remove(accList_t); //remove the account if it is not of the correct type accList_t = accList.begin(); } else { ++accList_t; } } return accList; }
void MyMoneyAccountTest::testIsIncomeExpense() { MyMoneyAccount a; a.setAccountType(MyMoneyAccount::UnknownAccountType); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Checkings); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Savings); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Cash); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::CreditCard); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Loan); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::CertificateDep); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Investment); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::MoneyMarket); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Asset); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Liability); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Currency); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Income); QVERIFY(a.isIncomeExpense() == true); a.setAccountType(MyMoneyAccount::Expense); QVERIFY(a.isIncomeExpense() == true); a.setAccountType(MyMoneyAccount::AssetLoan); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Stock); QVERIFY(a.isIncomeExpense() == false); a.setAccountType(MyMoneyAccount::Equity); QVERIFY(a.isIncomeExpense() == false); }