void MyMoneyQifWriter::writeTransactionEntry(QTextStream &s, const MyMoneyTransaction& t, const QString& accountId) { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneySplit split = t.splitByAccount(accountId); s << "D" << m_qifProfile.date(t.postDate()) << endl; switch(split.reconcileFlag()) { case MyMoneySplit::Cleared: s << "C*" << endl; break; case MyMoneySplit::Reconciled: case MyMoneySplit::Frozen: s << "CX" << endl; break; default: break; } if(split.memo().length() > 0) { QString m = split.memo(); m.replace('\n', "\\n"); s << "M" << m << endl; } s << "T" << m_qifProfile.value('T', split.value()) << endl; if(split.number().length() > 0) s << "N" << split.number() << endl; if(!split.payeeId().isEmpty()) { MyMoneyPayee payee = file->payee(split.payeeId()); s << "P" << payee.name() << endl; } QValueList<MyMoneySplit> list = t.splits(); if(list.count() > 1) { MyMoneySplit sp = t.splitByAccount(accountId, false); MyMoneyAccount acc = file->account(sp.accountId()); if(acc.accountGroup() != MyMoneyAccount::Income && acc.accountGroup() != MyMoneyAccount::Expense) { s << "L" << m_qifProfile.accountDelimiter()[0] << MyMoneyFile::instance()->accountToCategory(sp.accountId()) << m_qifProfile.accountDelimiter()[1] << endl; } else { s << "L" << file->accountToCategory(sp.accountId()) << endl; } if(list.count() > 2) { QValueList<MyMoneySplit>::ConstIterator it; for(it = list.begin(); it != list.end(); ++it) { if(!((*it) == split)) { writeSplitEntry(s, *it); } } } } s << "^" << endl; }
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 &) { } }