Git commit 7a4901c668871882bba75068bf1256f2bf00dba0 by Thomas Baumgart. Committed on 16/05/2015 at 06:20. Pushed by tbaumgart into branch 'master'.
Eliminate usage of opening date for categories Set the opening date for newly created categories to 1900-01-01 and fix existing ones to have that date during the consistency check. Since the opening date of an income/expense account (aka category) is not used throughout the application, it should not interfer with the check that the opening dates of all accounts referenced in a transaction are prior to the transaction's post date. Setting the opening date of a category to the above mentioned value makes sure that a category is always 'opened' before the transaction took place. The UI elements for the opening date have been removed from the account/category edit dialog as they are not used anymore. BUG: 313793 GUI: M +8 -2 kmymoney/dialogs/knewaccountdlg.cpp M +1 -0 kmymoney/dialogs/knewaccountdlg.h M +16 -16 kmymoney/dialogs/knewaccountdlgdecl.ui M +2 -0 kmymoney/kmymoney.cpp M +13 -0 kmymoney/mymoney/mymoneyfile.cpp M +71 -0 kmymoney/mymoney/mymoneyfiletest.cpp M +1 -0 kmymoney/mymoney/mymoneyfiletest.h http://commits.kde.org/kmymoney/7a4901c668871882bba75068bf1256f2bf00dba0 diff --git a/kmymoney/dialogs/knewaccountdlg.cpp b/kmymoney/dialogs/knewaccountdlg.cpp index e294624..fe36a18 100644 --- a/kmymoney/dialogs/knewaccountdlg.cpp +++ b/kmymoney/dialogs/knewaccountdlg.cpp @@ -217,7 +217,7 @@ KNewAccountDlg::KNewAccountDlg(const MyMoneyAccount& account, bool isEditing, bo if (!m_account.openingDate().isValid()) { m_account.setOpeningDate(KMyMoneyGlobalSettings::firstFiscalDate()); } - startDateEdit->setDate(m_account.openingDate()); + m_openingDateEdit->setDate(m_account.openingDate()); if (categoryEditor) { // get rid of the tabs that are not used for categories @@ -494,6 +494,12 @@ void KNewAccountDlg::setOpeningBalanceShown(bool shown) m_openingBalanceEdit->setVisible(shown); } +void KNewAccountDlg::setOpeningDateShown(bool shown) +{ + m_openingDateLabel->setVisible(shown); + m_openingDateEdit->setVisible(shown); +} + void KNewAccountDlg::okClicked() { MyMoneyFile* file = MyMoneyFile::instance(); @@ -578,7 +584,7 @@ void KNewAccountDlg::okClicked() m_account.setDescription(descriptionEdit->toPlainText()); - m_account.setOpeningDate(startDateEdit->date()); + m_account.setOpeningDate(m_openingDateEdit->date()); if (!m_categoryEditor) { m_account.setCurrencyId(m_currency->security().id()); diff --git a/kmymoney/dialogs/knewaccountdlg.h b/kmymoney/dialogs/knewaccountdlg.h index be62c4b..962dee4 100644 --- a/kmymoney/dialogs/knewaccountdlg.h +++ b/kmymoney/dialogs/knewaccountdlg.h @@ -129,6 +129,7 @@ public: }; void setOpeningBalanceShown(bool shown); + void setOpeningDateShown(bool shown); /** * This method adds an additional tab pointed to with @a w to the tab widget. diff --git a/kmymoney/dialogs/knewaccountdlgdecl.ui b/kmymoney/dialogs/knewaccountdlgdecl.ui index ef76e8b..bee638d 100644 --- a/kmymoney/dialogs/knewaccountdlgdecl.ui +++ b/kmymoney/dialogs/knewaccountdlgdecl.ui @@ -105,7 +105,7 @@ </widget> </item> <item row="0" column="2"> - <widget class="QLabel" name="TextLabel1_2"> + <widget class="QLabel" name="m_openingDateLabel"> <property name="minimumSize"> <size> <width>0</width> @@ -121,7 +121,7 @@ </widget> </item> <item row="0" column="3"> - <widget class="kMyMoneyDateInput" name="startDateEdit"/> + <widget class="kMyMoneyDateInput" name="m_openingDateEdit"/> </item> <item row="1" column="2"> <widget class="QLabel" name="m_openingBalanceLabel"> @@ -691,7 +691,7 @@ <bool>true</bool> </property> <attribute name="buttonGroup"> - <string>m_amountGroup</string> + <string notr="true">m_amountGroup</string> </attribute> </widget> </item> @@ -701,7 +701,7 @@ <string>Net amount</string> </property> <attribute name="buttonGroup"> - <string>m_amountGroup</string> + <string notr="true">m_amountGroup</string> </attribute> </widget> </item> @@ -813,9 +813,9 @@ <layoutdefault spacing="6" margin="11"/> <customwidgets> <customwidget> - <class>KPushButton</class> - <extends>QPushButton</extends> - <header>kpushbutton.h</header> + <class>KComboBox</class> + <extends>QComboBox</extends> + <header>kcombobox.h</header> </customwidget> <customwidget> <class>KLineEdit</class> @@ -823,9 +823,14 @@ <header>klineedit.h</header> </customwidget> <customwidget> - <class>KComboBox</class> - <extends>QComboBox</extends> - <header>kcombobox.h</header> + <class>KPushButton</class> + <extends>QPushButton</extends> + <header>kpushbutton.h</header> + </customwidget> + <customwidget> + <class>KTextEdit</class> + <extends>QTextEdit</extends> + <header>ktextedit.h</header> </customwidget> <customwidget> <class>KTabWidget</class> @@ -834,11 +839,6 @@ <container>1</container> </customwidget> <customwidget> - <class>KTextEdit</class> - <extends>QTextEdit</extends> - <header>ktextedit.h</header> - </customwidget> - <customwidget> <class>kMyMoneyDateInput</class> <extends>QFrame</extends> <header>kmymoneydateinput.h</header> @@ -877,8 +877,8 @@ <tabstop>m_tab</tabstop> <tabstop>accountNameEdit</tabstop> <tabstop>typeCombo</tabstop> - <tabstop>startDateEdit</tabstop> <tabstop>m_currency</tabstop> + <tabstop>m_openingDateEdit</tabstop> <tabstop>m_openingBalanceEdit</tabstop> <tabstop>m_lastCheckNumberUsed</tabstop> <tabstop>descriptionEdit</tabstop> diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp index d095992..522fe1a 100644 --- a/kmymoney/kmymoney.cpp +++ b/kmymoney/kmymoney.cpp @@ -3137,6 +3137,7 @@ void KMyMoneyApp::createCategory(MyMoneyAccount& account, const MyMoneyAccount& new KNewAccountDlg(account, false, true, 0, i18n("Create a new Category")); dialog->setOpeningBalanceShown(false); + dialog->setOpeningDateShown(false); if (dialog->exec() == QDialog::Accepted && dialog != 0) { MyMoneyAccount parentAccount, brokerageAccount; @@ -3618,6 +3619,7 @@ void KMyMoneyApp::slotAccountEdit(void) if (category || d->m_selectedAccount.accountType() == MyMoneyAccount::Investment) { dlg->setOpeningBalanceShown(false); + dlg->setOpeningDateShown(false); tid.clear(); } else { if (!tid.isEmpty()) { diff --git a/kmymoney/mymoney/mymoneyfile.cpp b/kmymoney/mymoney/mymoneyfile.cpp index aca8d4a..9df0059 100644 --- a/kmymoney/mymoney/mymoneyfile.cpp +++ b/kmymoney/mymoney/mymoneyfile.cpp @@ -947,6 +947,12 @@ void MyMoneyFile::addAccount(MyMoneyAccount& account, MyMoneyAccount& parent) account.setOpeningDate(QDate::currentDate()); } + // make sure to set the opening date for categories to a + // fixed date (1900-1-1). See #313793 on b.k.o for details + if(account.isIncomeExpense()) { + account.setOpeningDate(QDate(1900,1,1)); + } + // if we don't have a currency assigned use the base currency if (account.currencyId().isEmpty()) { account.setCurrencyId(baseCurrency().id()); @@ -1964,6 +1970,13 @@ const QStringList MyMoneyFile::consistencyCheck(void) } } + // check if it is a category and set the date to 1900-01-01 if different + if ((*it_a).isIncomeExpense()) { + if(((*it_a).openingDate().isValid() == false) || ((*it_a).openingDate() != QDate(1900,1,1))) { + (*it_a).setOpeningDate(QDate(1900,1,1)); + } + } + // check for clear text online password in the online settings if (!(*it_a).onlineBankingSettings().value("password").isEmpty()) { if (problemAccount != (*it_a).name()) { diff --git a/kmymoney/mymoney/mymoneyfiletest.cpp b/kmymoney/mymoney/mymoneyfiletest.cpp index b69f600..fc90e3d 100644 --- a/kmymoney/mymoney/mymoneyfiletest.cpp +++ b/kmymoney/mymoney/mymoneyfiletest.cpp @@ -579,6 +579,77 @@ void MyMoneyFileTest::testAddAccounts() QCOMPARE(p.currencyId(), QLatin1String("EUR")); } +void MyMoneyFileTest::testAddCategories() +{ + MyMoneyAccount a, b, c; + a.setAccountType(MyMoneyAccount::Income); + a.setOpeningDate(QDate::currentDate()); + b.setAccountType(MyMoneyAccount::Expense); + + storage->m_dirty = false; + + QCOMPARE(m->accountCount(), static_cast<unsigned>(5)); + QCOMPARE(a.openingDate(), QDate::currentDate()); + QVERIFY(!b.openingDate().isValid()); + + a.setName("Account1"); + a.setCurrencyId("EUR"); + + clearObjectLists(); + MyMoneyFileTransaction ft; + try { + MyMoneyAccount parent = m->income(); + m->addAccount(a, parent); + ft.commit(); + QCOMPARE(m->accountCount(), static_cast<unsigned>(6)); + QCOMPARE(a.parentAccountId(), QLatin1String("AStd::Income")); + QCOMPARE(a.id(), QLatin1String("A000001")); + QCOMPARE(a.institutionId(), QString()); + QCOMPARE(a.currencyId(), QLatin1String("EUR")); + QCOMPARE(a.openingDate(), QDate(1900,1,1)); + QCOMPARE(m->dirty(), true); + QCOMPARE(m->income().accountList().count(), 1); + QCOMPARE(m->income().accountList()[0], QLatin1String("A000001")); + + } catch (const MyMoneyException &) { + QFAIL("Unexpected exception!"); + } + + // add a second category, expense this time + b.setName("Account2"); + b.setCurrencyId("EUR"); + clearObjectLists(); + ft.restart(); + try { + MyMoneyAccount parent = m->expense(); + m->addAccount(b, parent); + ft.commit(); + QCOMPARE(m->dirty(), true); + QCOMPARE(b.id(), QLatin1String("A000002")); + QCOMPARE(a.institutionId(), QString()); + QCOMPARE(b.currencyId(), QLatin1String("EUR")); + QCOMPARE(b.openingDate(), QDate(1900,1,1)); + QCOMPARE(b.parentAccountId(), QLatin1String("AStd::Expense")); + QCOMPARE(m->accountCount(), static_cast<unsigned>(7)); + + QCOMPARE(m->income().accountList().count(), 1); + QCOMPARE(m->expense().accountList().count(), 1); + QCOMPARE(m->income().accountList()[0], QLatin1String("A000001")); + QCOMPARE(m->expense().accountList()[0], QLatin1String("A000002")); + + QCOMPARE(m_objectsRemoved.count(), 0); + QCOMPARE(m_objectsAdded.count(), 1); + QCOMPARE(m_objectsModified.count(), 1); + QCOMPARE(m_balanceChanged.count(), 0); + QCOMPARE(m_valueChanged.count(), 0); + QVERIFY(m_objectsAdded.contains(QLatin1String("A000002"))); + QVERIFY(m_objectsModified.contains(QLatin1String("AStd::Expense"))); + + } catch (const MyMoneyException &) { + QFAIL("Unexpected exception!"); + } +} + void MyMoneyFileTest::testModifyAccount() { testAddAccounts(); diff --git a/kmymoney/mymoney/mymoneyfiletest.h b/kmymoney/mymoney/mymoneyfiletest.h index 4a91731..d98625a 100644 --- a/kmymoney/mymoney/mymoneyfiletest.h +++ b/kmymoney/mymoney/mymoneyfiletest.h @@ -46,6 +46,7 @@ private slots: void testInstitutionModify(); void testSetFunctions(); void testAddAccounts(); + void testAddCategories(); void testModifyAccount(); void testModifyStdAccount(); void testReparentAccount();
