Move MyMoneySplit reading and writing to XML storage
ClosedPublic

Authored by wojnilowicz on Jul 15 2018, 9:10 AM.

Details

Summary

It has been inadvertently omitted from the last patch. Old read methods are still around but only for an easy comparison with new methods.

Diff Detail

Repository
R261 KMyMoney
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
wojnilowicz requested review of this revision.Jul 15 2018, 9:10 AM
wojnilowicz created this revision.
tbaumgart requested changes to this revision.Jul 15 2018, 2:21 PM

I needed to apply the following patch to get correct results. Reason: you must not set the entry date of a scheduled transaction to a valid value, due to the fact that

// some old versions did not remove the entry date and post date fields
// in the schedule. So if this is the case, we deal with a very old transaction
// and can't use the post date field as next due date. Hence, we wipe it out here

Since you set the entry date prior to this check, such an old entry is assumed and things go wrong. The patch takes care of this.

diff --git a/kmymoney/plugins/xml/mymoneystoragexml.cpp b/kmymoney/plugins/xml/mymoneystoragexml.cpp
index 0e5ec0b4..e938e814 100644
--- a/kmymoney/plugins/xml/mymoneystoragexml.cpp
+++ b/kmymoney/plugins/xml/mymoneystoragexml.cpp
@@ -152,7 +152,7 @@ private:
   static void writeBaseXML(const QString &id, QDomDocument &document, QDomElement &el);
   static void addToKeyValueContainer(MyMoneyKeyValueContainer &container, const QDomElement &node);
   static void writeKeyValueContainer(const MyMoneyKeyValueContainer &container, QDomDocument &document, QDomElement &parent);
-  static MyMoneyTransaction readTransaction(const QDomElement &node);
+  static MyMoneyTransaction readTransaction(const QDomElement &node, bool assignEntryDateIfEmpty = true);
   static void writeTransaction(const MyMoneyTransaction &transaction, QDomDocument &document, QDomElement &parent);
   static MyMoneySplit readSplit(const QDomElement &node);
   static void writeSplit(const MyMoneySplit &_split, QDomDocument &document, QDomElement &parent);
@@ -514,7 +514,7 @@ void MyMoneyXmlContentHandler::writeKeyValueContainer(const MyMoneyKeyValueConta
   }
 }
 
-MyMoneyTransaction MyMoneyXmlContentHandler::readTransaction(const QDomElement &node)
+MyMoneyTransaction MyMoneyXmlContentHandler::readTransaction(const QDomElement &node, bool assignEntryDateIfEmpty)
 {
   if (nodeName(Node::Transaction) != node.tagName())
     throw MYMONEYEXCEPTION_CSTRING("Node was not TRANSACTION");
@@ -525,7 +525,7 @@ MyMoneyTransaction MyMoneyXmlContentHandler::readTransaction(const QDomElement &
 
   transaction.setPostDate(QDate::fromString(node.attribute(attributeName(Attribute::Transaction::PostDate)), Qt::ISODate));
   auto entryDate = QDate::fromString(node.attribute(attributeName(Attribute::Transaction::EntryDate)),Qt::ISODate);
-  if (entryDate == QDate())
+  if (!entryDate.isValid() && assignEntryDateIfEmpty)
     entryDate = QDate::currentDate();
   transaction.setEntryDate(entryDate);
   transaction.setBankID(node.attribute(attributeName(Attribute::Transaction::BankID)));
@@ -557,7 +557,7 @@ MyMoneyTransaction MyMoneyXmlContentHandler::readTransaction(const QDomElement &
       }
 
     } else if (c.tagName() == nodeName(Node::KeyValuePairs)) {
-      addToKeyValueContainer(transaction, c.toElement());         
+      addToKeyValueContainer(transaction, c.toElement());
     }
 
     child = child.nextSibling();
@@ -1197,7 +1197,7 @@ MyMoneySchedule MyMoneyXmlContentHandler::readSchedule(const QDomElement &node)
   if (nodeList.count() == 0)
     throw MYMONEYEXCEPTION_CSTRING("SCHEDULED_TX has no TRANSACTION node");
 
-  auto transaction = readTransaction(nodeList.item(0).toElement());
+  auto transaction = readTransaction(nodeList.item(0).toElement(), false);
 
   // some old versions did not remove the entry date and post date fields
   // in the schedule. So if this is the case, we deal with a very old transaction
kmymoney/mymoney/mymoneysplit.cpp
51

Is this needed? It should be initialized in the MyMoneySplitPrivate ctor which is the case. So in my POV this is superfluous. I might be mistaken, in that case a short comment why it is needed would help.

kmymoney/plugins/xml/mymoneystoragexml.cpp
545

Can you add a /// @todo remove after final test or similar doxygen comment here and in other locations where you check the new code against the old?

This revision now requires changes to proceed.Jul 15 2018, 2:21 PM
wojnilowicz marked 2 inline comments as done.
wojnilowicz added inline comments.
kmymoney/plugins/xml/mymoneystoragexml.cpp
545

Only in one place.

tbaumgart accepted this revision.Jul 15 2018, 4:18 PM

Looks OK to me. Made some tests in comparing the output of the master version and this version which do not show differences.

This revision is now accepted and ready to land.Jul 15 2018, 4:18 PM
This revision was automatically updated to reflect the committed changes.