[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [skrooge] /: Better KMyMoney import
From: Stephane Mankowski <stephane () mankowski ! fr>
Date: 2013-12-31 22:06:12
Message-ID: E1Vy7S0-00032n-Ic () scm ! kde ! org
[Download RAW message or body]
Git commit fc00e44f6cc4b0fc4388430b871b96027aa266cf by Stephane Mankowski.
Committed on 31/12/2013 at 22:05.
Pushed by smankowski into branch 'master'.
Better KMyMoney import
M +1 -0 CHANGELOG
M +0 -1 plugins/generic/skg_file/skgfileplugin.cpp
M +0 -1 plugins/import/skrooge_import_backend/skgimportpluginbackend.cpp
M +30 -12 plugins/import/skrooge_import_kmy/skgimportpluginkmy.cpp
M +3 -3 plugins/import/skrooge_import_mny/skgimportpluginmny.cpp
A +- -- tests/input/skgtestimportkmy4/randy1.kmy
M +52 -0 tests/skgbankmodelertest/skgtestimportkmy4.cpp
M +16 -1 tests/skgbasemodelertest/skgtestmacro.h
http://commits.kde.org/skrooge/fc00e44f6cc4b0fc4388430b871b96027aa266cf
diff --git a/CHANGELOG b/CHANGELOG
index 7026ca4..d34eb87 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,6 +8,7 @@ skrooge (1.9.0)
*Correction: Refresh delta during reconciliation
*Correction: Better PDF export from Monthly report
*Correction: Import CSV unit file with "," as separator
+ *Correction: Better KMyMoney import
*New feature: New shortcuts for "Expand all" and "Collapse all"
*New feature: Operations can be split by date
*New feature: Imports (csv, qif) support date format like this: 31Dec2012
diff --git a/plugins/generic/skg_file/skgfileplugin.cpp \
b/plugins/generic/skg_file/skgfileplugin.cpp index 29509e6..7b15d1b 100644
--- a/plugins/generic/skg_file/skgfileplugin.cpp
+++ b/plugins/generic/skg_file/skgfileplugin.cpp
@@ -427,7 +427,6 @@ void SKGFilePlugin::onOpen(const KUrl& iUrl)
// Get password
if (useKWallet) {
- SKGTRACEINFUNCRC(10, err);
// Use KWallet
QString walletName = \
KWallet::Wallet::walletList().value(SKGServices::stringToInt(skgfile_settings::selectedWallet()));
if (walletName.isEmpty()) {
diff --git a/plugins/import/skrooge_import_backend/skgimportpluginbackend.cpp \
b/plugins/import/skrooge_import_backend/skgimportpluginbackend.cpp index \
3bb3fd3..841fdf3 100644
--- a/plugins/import/skrooge_import_backend/skgimportpluginbackend.cpp
+++ b/plugins/import/skrooge_import_backend/skgimportpluginbackend.cpp
@@ -187,7 +187,6 @@ SKGError SKGImportPluginBackend::importFile()
}
QStringList listDownloadedId;
{
- SKGTRACEINFUNCRC(10, err);
QFuture<QString> f = QtConcurrent::mapped(backendAccounts, \
download(nbToDownload, properties["getoperations"], pwd)); f.waitForFinished();
listDownloadedId = f.results();
diff --git a/plugins/import/skrooge_import_kmy/skgimportpluginkmy.cpp \
b/plugins/import/skrooge_import_kmy/skgimportpluginkmy.cpp index af638c5..fe2ad5d \
100644
--- a/plugins/import/skrooge_import_kmy/skgimportpluginkmy.cpp
+++ b/plugins/import/skrooge_import_kmy/skgimportpluginkmy.cpp
@@ -106,7 +106,7 @@ SKGError SKGImportPluginKmy::importFile()
// Step 1-Get units
QDomElement securities = docElem.firstChildElement("SECURITIES");
if (!err && !securities.isNull()) {
- SKGTRACEINFUNCRC(10, err);
+ SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-SECURITIES", err);
QDomNodeList securityList = \
securities.elementsByTagName("SECURITY"); int nb = securityList.count();
err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % \
i18nc("Import step", "Import units"), nb); @@ -154,7 +154,7 @@ SKGError \
SKGImportPluginKmy::importFile() // Step 2-Get units prices
QDomElement prices = docElem.firstChildElement("PRICES");
if (!err && !prices.isNull()) {
- SKGTRACEINFUNCRC(10, err);
+ SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-PRICES", err);
QDomNodeList pricepairList = prices.elementsByTagName("PRICEPAIR");
int nb = pricepairList.count();
err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % \
i18nc("Import step", "Import units"), nb); @@ -188,7 +188,7 @@ SKGError \
SKGImportPluginKmy::importFile() QMap<QString, SKGBankObject> mapIdBank;
QDomElement institutions = docElem.firstChildElement("INSTITUTIONS");
if (!err && !institutions.isNull()) {
- SKGTRACEINFUNCRC(10, err);
+ SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-INSTITUTIONS", \
err);
QDomNodeList institutionList = \
institutions.elementsByTagName("INSTITUTION"); int nb = institutionList.count();
for (int i = 0; !err && i < nb; ++i) {
@@ -215,18 +215,20 @@ SKGError SKGImportPluginKmy::importFile()
QDomElement accounts = docElem.firstChildElement("ACCOUNTS");
if (!err && !accounts.isNull()) {
- SKGTRACEINFUNCRC(10, err);
+ SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-ACCOUNTS", err);
QDomNodeList accountList = accounts.elementsByTagName("ACCOUNT");
int nb = accountList.count();
err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % \
i18nc("Import step", "Import accounts"), nb); + QMap<QString, QString> \
type15Account; + QMap<QString, QString> type15Unit;
for (int i = 0; !err && i < nb; ++i) {
// Get account object
QDomElement account = accountList.at(i).toElement();
QString type = account.attribute("type");
if (type == "15") {
// Actions: the real account is the parent
- m_mapIdAccount[account.attribute("id")] = \
m_mapIdAccount[account.attribute("parentaccount")];
- m_mapIdUnit[account.attribute("id")] = \
m_mapIdUnit[account.attribute("currency")]; + \
type15Account[account.attribute("id")] = account.attribute("parentaccount"); + \
type15Unit[account.attribute("id")] = account.attribute("currency");
} else if (type != "12" && type != "13" && type != "16") {
// Get the bank
QString bankId = account.attribute("institution");
@@ -302,6 +304,15 @@ SKGError SKGImportPluginKmy::importFile()
}
}
+ foreach(const QString & i, type15Account.keys()) {
+ m_mapIdAccount[i] = m_mapIdAccount[type15Account[i]];
+ m_mapIdUnit[account.attribute("id")] = \
m_mapIdUnit[account.attribute("currency")]; + }
+
+ foreach(const QString & i, type15Unit.keys()) {
+ m_mapIdUnit[i] = m_mapIdUnit[type15Unit[i]];
+ }
+
IFOKDO(err, m_importer->getDocument()->stepForward(i + 1))
}
@@ -313,7 +324,7 @@ SKGError SKGImportPluginKmy::importFile()
QMap<QString, SKGPayeeObject> mapIdPayee;
QDomElement payees = docElem.firstChildElement("PAYEES");
if (!err && !payees.isNull()) {
- SKGTRACEINFUNCRC(10, err);
+ SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-PAYEES", err);
QDomNodeList payeeList = payees.elementsByTagName("PAYEE");
int nb = payeeList.count();
for (int i = 0; !err && i < nb; ++i) {
@@ -335,7 +346,7 @@ SKGError SKGImportPluginKmy::importFile()
// Step 6-Create operations
IFOK(err) {
- SKGTRACEINFUNCRC(10, err);
+ SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-TRANSACTION", err);
QDomNodeList transactionList = \
docElem.elementsByTagName("TRANSACTION"); int nb = transactionList.count();
err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % \
i18nc("Import step", "Import operations"), nb); @@ -482,6 +493,10 @@ SKGError \
SKGImportPluginKmy::importFile()
IFOKDO(err, \
operationObj.setStatus(SKGOperationObject::CHECKED))
IFOKDO(err, operationObj.save(true, false))
+ if (!err && !suboperationObj.getID()) {
+ err = \
operationObj.addSubOperation(suboperationObj); + }
+
IFOKDO(err, \
suboperationObj.setAttribute("d_date", "0000-00-00"))
IFOKDO(err, suboperationObj.save(true, false))
} else {
@@ -506,10 +521,10 @@ SKGError SKGImportPluginKmy::importFile()
IFOKDO(err, operationObj2.setImported(true))
IFOKDO(err, \
operationObj2.setImportID(operationObj.getImportID()))
- if \
(m_mapIdUnit.contains(suboperation.attribute("account"))) {
- IFOKDO(err, \
operationObj2.setUnit(m_mapIdUnit[suboperation.attribute("account")])) + \
SKGUnitObject unit = m_mapIdUnit[suboperation.attribute("account")]; + \
if (unit.getID()) { + IFOKDO(err, \
operationObj2.setUnit(unit)) } else {
- SKGUnitObject unit;
IFOKDO(err, operationObj.getUnit(unit))
IFOKDO(err, operationObj2.setUnit(unit))
}
@@ -529,6 +544,9 @@ SKGError SKGImportPluginKmy::importFile()
IFOKDO(err, suboperationObj2.save(true, \
false)) } else {
// We set the parent
+ if (Q_LIKELY(!err) && !act.getID()) {
+ err = SKGError(ERR_FAIL, i18nc("Error \
message", "Account with identifier %1 not found", \
suboperation.attribute("account"))); + }
IFOKDO(err, \
operationObj.setParentAccount(act, true)) IFOKDO(err, operationObj.save())
@@ -565,7 +583,7 @@ SKGError SKGImportPluginKmy::importFile()
// Step 7-Get budgets
QDomElement budgets = docElem.firstChildElement("BUDGETS");
if (!err && !budgets.isNull()) {
- SKGTRACEINFUNCRC(10, err);
+ SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-BUDGETS", err);
// Build cache of categories
QMap<int, bool> catExpense;
{
diff --git a/plugins/import/skrooge_import_mny/skgimportpluginmny.cpp \
b/plugins/import/skrooge_import_mny/skgimportpluginmny.cpp index 8bc4f1d..11ce873 \
100644
--- a/plugins/import/skrooge_import_mny/skgimportpluginmny.cpp
+++ b/plugins/import/skrooge_import_mny/skgimportpluginmny.cpp
@@ -185,7 +185,7 @@ SKGError SKGImportPluginMny::importFile()
err = readJsonFile(temporaryPath % "/categories.json", var);
QVariantList list = var.toList();
IFOK(err) {
- SKGTRACEINFUNCRC(10, err);
+ SKGTRACEINRC(10, "SKGImportPluginMny::importFile-categories", err);
int nb = list.count();
err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % \
i18nc("Import step", "Import categories"), nb); // Create categories
@@ -226,7 +226,7 @@ SKGError SKGImportPluginMny::importFile()
err = readJsonFile(temporaryPath % "/payees.json", var);
QVariantList list = var.toList();
IFOK(err) {
- SKGTRACEINFUNCRC(10, err);
+ SKGTRACEINRC(10, "SKGImportPluginMny::importFile-payees", err);
int nb = list.count();
err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % \
i18nc("Import step", "Import payees"), nb); // Create categories
@@ -257,7 +257,7 @@ SKGError SKGImportPluginMny::importFile()
err = readJsonFile(temporaryPath % "/securities.json", var);
QVariantList list = var.toList();
IFOK(err) {
- SKGTRACEINFUNCRC(10, err);
+ SKGTRACEINRC(10, "SKGImportPluginMny::importFile-securities", err);
int nb = list.count();
err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % \
i18nc("Import step", "Import units"), nb); // Create categories
diff --git a/tests/input/skgtestimportkmy4/randy1.kmy \
b/tests/input/skgtestimportkmy4/randy1.kmy new file mode 100644
index 0000000..600e70f
Binary files /dev/null and b/tests/input/skgtestimportkmy4/randy1.kmy differ
diff --git a/tests/skgbankmodelertest/skgtestimportkmy4.cpp \
b/tests/skgbankmodelertest/skgtestimportkmy4.cpp index a84e4f5..f669245 100644
--- a/tests/skgbankmodelertest/skgtestimportkmy4.cpp
+++ b/tests/skgbankmodelertest/skgtestimportkmy4.cpp
@@ -68,6 +68,58 @@ int main(int argc, char** argv)
SKGTEST("document1:nb operations", nboperation2, nboperation);
}
}
+
+ {
+ // Test import randy1
+ SKGDocumentBank document1;
+ SKGTESTERROR("document1.initialize()", document1.initialize(), true);
+ SKGError err;
+ {
+ // Scope of the transaction
+ SKGBEGINTRANSACTION(document1, "IMPORT_KMY", err);
+ SKGImportExportManager imp1(&document1, \
KUrl::fromLocalFile(SKGTest::getTestPath("IN") % "/skgtestimportkmy4/randy1.kmy")); + \
SKGTESTERROR("KMY.importFile", imp1.importFile(), true); + }
+
+ // Actif
+ SKGTESTACCOUNT(document1, "A000290", 23182500.00);
+ // Action
+ /*SKGTESTACCOUNT(document1, "A000014", 2432032.27);
+ SKGTESTACCOUNT(document1, "A000016", 236769.78);
+ SKGTESTACCOUNT(document1, "A000018", 0.00);
+ SKGTESTACCOUNT(document1, "A000020", 0.00);
+ SKGTESTACCOUNT(document1, "A000022", 326254.23);
+ SKGTESTACCOUNT(document1, "A000023", 459915.34);
+ SKGTESTACCOUNT(document1, "A000025", 618975.84);
+ SKGTESTACCOUNT(document1, "A000027", 301501.09);
+ SKGTESTACCOUNT(document1, "A000032", 12358550.29);
+ SKGTESTACCOUNT(document1, "A000294", 1193772.30);
+ SKGTESTACCOUNT(document1, "A000300", 12304427.59);
+ SKGTESTACCOUNT(document1, "A000312", 2822127.36);
+ SKGTESTACCOUNT(document1, "A000366", 14150464.39);
+ SKGTESTACCOUNT(document1, "A000371", 2160798.86);*/
+ // Carte de credit
+ SKGTESTACCOUNT(document1, "A000120", -316721.001);
+ SKGTESTACCOUNT(document1, "A000407", -1438.158);
+ SKGTESTACCOUNT(document1, "A000409", 0.00);
+ // Cheques
+ SKGTESTACCOUNT(document1, "A000030", -6371673.033);
+ SKGTESTACCOUNT(document1, "A000040", 429856.659);
+ SKGTESTACCOUNT(document1, "A000273", 2479805.892);
+ SKGTESTACCOUNT(document1, "A000378", 845357.871);
+ // Especes
+ SKGTESTACCOUNT(document1, "A000314", 0.00);
+ SKGTESTACCOUNT(document1, "A000354", 863.232);
+ // Epargne
+ SKGTESTACCOUNT(document1, "A000041", 402257.682);
+ SKGTESTACCOUNT(document1, "A000301", 951074.286);
+ SKGTESTACCOUNT(document1, "A000330", 0.00);
+ SKGTESTACCOUNT(document1, "A000353", 1753.44);
+ SKGTESTACCOUNT(document1, "A000379", 4955771.076);
+ SKGTESTACCOUNT(document1, "A000387", 849701.007);
+ SKGTESTACCOUNT(document1, "A000388", 4681634.22);
+ SKGTESTACCOUNT(document1, "A000400", 255912.039);
+ }
// End test
SKGENDTEST();
}
diff --git a/tests/skgbasemodelertest/skgtestmacro.h \
b/tests/skgbasemodelertest/skgtestmacro.h index 82be0bd..9f4c804 100644
--- a/tests/skgbasemodelertest/skgtestmacro.h
+++ b/tests/skgbasemodelertest/skgtestmacro.h
@@ -171,5 +171,20 @@ public:
++nbcheck;\
}
-#endif
+/**
+ * @def SKGTESTACCOUNT(DOC, ACCOUNT, AMOUNT)
+ * To check the account amount
+ * Example of usage:
+ * @code
+ * SKGTESTACCOUNT(document1, "act1", 12345);
+ * @endcode
+ */
+#define SKGTESTACCOUNT(DOC, ACCOUNT, AMOUNT) \
+ { \
+ SKGAccountObject account(&DOC); \
+ SKGTESTERROR(QString(ACCOUNT) % ".setName(" % ACCOUNT % ")", \
account.setName(ACCOUNT), true); \ + SKGTESTERROR(QString(ACCOUNT) % ".load(" \
% ACCOUNT % ")", account.load(), true); \ + SKGTEST(QString(ACCOUNT) % \
".getCurrentAmount(" % ACCOUNT % ")", \
SKGServices::doubleToString(account.getCurrentAmount()), \
SKGServices::doubleToString(AMOUNT));\ + }
+#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic