Commit 7a4901c6 authored by Thomas Baumgart's avatar Thomas Baumgart
Browse files

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:
parent 3117b22d
......@@ -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());
......
......@@ -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.
......
......@@ -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>
......@@ -833,11 +838,6 @@
<header>ktabwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KTextEdit</class>
<extends>QTextEdit</extends>
<header>ktextedit.h</header>
</customwidget>
<customwidget>
<class>kMyMoneyDateInput</class>
<extends>QFrame</extends>
......@@ -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>
......
......@@ -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()) {
......
......@@ -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()) {
......
......@@ -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();
......
......@@ -46,6 +46,7 @@ private slots:
void testInstitutionModify();
void testSetFunctions();
void testAddAccounts();
void testAddCategories();
void testModifyAccount();
void testModifyStdAccount();
void testReparentAccount();
......
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