void MyMoneySplitTest::testReadXML() { MyMoneySplit s; QString ref_ok = QString( "<!DOCTYPE TEST>\n" "<SPLIT-CONTAINER>\n" " <SPLIT payee=\"P000001\" reconciledate=\"\" shares=\"96379/100\" action=\"Deposit\" bankid=\"SPID\" number=\"124\" reconcileflag=\"2\" memo=\"MyMemo\" value=\"96379/1000\" account=\"A000076\">\n" " <TAG id=\"G000001\"/>\n" " </SPLIT>\n" "</SPLIT-CONTAINER>\n"); QString ref_false = QString( "<!DOCTYPE TEST>\n" "<SPLIT-CONTAINER>\n" " <SPLITS payee=\"P000001\" reconciledate=\"\" shares=\"96379/100\" action=\"Deposit\" bankid=\"SPID\" number=\"124\" reconcileflag=\"2\" memo=\"\" value=\"96379/1000\" account=\"A000076\" />\n" " <TAG id=\"G000001\"/>\n" "</SPLIT-CONTAINER>\n"); QDomDocument doc; QDomElement node; doc.setContent(ref_false); node = doc.documentElement().firstChild().toElement(); try { s = MyMoneySplit(node); QFAIL("Missing expected exception"); } catch (const MyMoneyException &) { } doc.setContent(ref_ok); node = doc.documentElement().firstChild().toElement(); try { s = MyMoneySplit(node); QVERIFY(s.id().isEmpty()); QVERIFY(s.payeeId() == "P000001"); QList<QString> tagIdList; tagIdList << "G000001"; QVERIFY(s.tagIdList() == tagIdList); QVERIFY(s.reconcileDate() == QDate()); QVERIFY(s.shares() == MyMoneyMoney(96379, 100)); QVERIFY(s.value() == MyMoneyMoney(96379, 1000)); QVERIFY(s.number() == "124"); QVERIFY(s.bankID() == "SPID"); QVERIFY(s.reconcileFlag() == MyMoneySplit::Reconciled); QVERIFY(s.action() == MyMoneySplit::ActionDeposit); QVERIFY(s.accountId() == "A000076"); QVERIFY(s.memo() == "MyMemo"); } catch (const MyMoneyException &) { } }
void CsvUtil::dissectTransaction(const MyMoneyTransaction& transaction, const MyMoneySplit& split, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency, MyMoneySplit::investTransactionTypeE& transactionType) { // collect the splits. split references the stock account and should already // be set up. assetAccountSplit references the corresponding asset account (maybe // empty), feeSplits is the list of all expenses and interestSplits // the list of all incomes MyMoneyFile* file = MyMoneyFile::instance(); QList<MyMoneySplit>::ConstIterator it_s; for (it_s = transaction.splits().constBegin(); it_s != transaction.splits().constEnd(); ++it_s) { MyMoneyAccount acc = file->account((*it_s).accountId()); if ((*it_s).id() == split.id()) { security = file->security(acc.currencyId()); } else if (acc.accountGroup() == MyMoneyAccount::Expense) { feeSplits.append(*it_s); } else if (acc.accountGroup() == MyMoneyAccount::Income) { interestSplits.append(*it_s); } else { assetAccountSplit = *it_s; } } // determine transaction type if (split.action() == MyMoneySplit::ActionAddShares) { transactionType = (!split.shares().isNegative()) ? MyMoneySplit::AddShares : MyMoneySplit::RemoveShares; } else if (split.action() == MyMoneySplit::ActionBuyShares) { transactionType = (!split.value().isNegative()) ? MyMoneySplit::BuyShares : MyMoneySplit::SellShares; } else if (split.action() == MyMoneySplit::ActionDividend) { transactionType = MyMoneySplit::Dividend; } else if (split.action() == MyMoneySplit::ActionReinvestDividend) { transactionType = MyMoneySplit::ReinvestDividend; } else if (split.action() == MyMoneySplit::ActionYield) { transactionType = MyMoneySplit::Yield; } else if (split.action() == MyMoneySplit::ActionSplitShares) { transactionType = MyMoneySplit::SplitShares; } else if (split.action() == MyMoneySplit::ActionInterestIncome) { transactionType = MyMoneySplit::InterestIncome; } else transactionType = MyMoneySplit::BuyShares; currency.setTradingSymbol("???"); try { currency = file->security(transaction.commodity()); } catch (const MyMoneyException &) { } }
void MyMoneySplitTest::testAssignmentConstructor() { testSetFunctions(); MyMoneySplit n; n = *m; QVERIFY(n.accountId() == "Account"); QVERIFY(n.memo() == "Memo"); QVERIFY(n.reconcileDate() == QDate(1, 2, 3)); QVERIFY(n.reconcileFlag() == MyMoneySplit::Cleared); QVERIFY(n.shares() == MyMoneyMoney(1234, 100)); QVERIFY(n.value() == MyMoneyMoney(3456, 100)); QVERIFY(n.id() == "MyID"); QVERIFY(n.payeeId() == "Payee"); QList<QString> tagIdList; tagIdList << "Tag"; QVERIFY(m->tagIdList() == tagIdList); QVERIFY(n.action() == "Action"); QVERIFY(n.transactionId() == "TestTransaction"); QVERIFY(n.value("Key") == "Value"); }