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/s= kg_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 =3D KWallet::Wallet::walletList= ().value(SKGServices::stringToInt(skgfile_settings::selectedWallet())); if (walletName.isEmpty()) { diff --git a/plugins/import/skrooge_import_backend/skgimportpluginbackend.c= pp 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 f =3D QtConcurrent::mapped(backendAcc= ounts, download(nbToDownload, properties["getoperations"], pwd)); f.waitForFinished(); listDownloadedId =3D f.results(); diff --git a/plugins/import/skrooge_import_kmy/skgimportpluginkmy.cpp b/plu= gins/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 =3D docElem.firstChildElement("SECURITI= ES"); if (!err && !securities.isNull()) { - SKGTRACEINFUNCRC(10, err); + SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-SECURITIE= S", err); QDomNodeList securityList =3D securities.elementsByTagName= ("SECURITY"); int nb =3D securityList.count(); err =3D m_importer->getDocument()->beginTransaction("#INTE= RNAL#" % i18nc("Import step", "Import units"), nb); @@ -154,7 +154,7 @@ SKGError SKGImportPluginKmy::importFile() // Step 2-Get units prices QDomElement prices =3D docElem.firstChildElement("PRICES"); if (!err && !prices.isNull()) { - SKGTRACEINFUNCRC(10, err); + SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-PRICES", = err); QDomNodeList pricepairList =3D prices.elementsByTagName("P= RICEPAIR"); int nb =3D pricepairList.count(); err =3D m_importer->getDocument()->beginTransaction("#INTE= RNAL#" % i18nc("Import step", "Import units"), nb); @@ -188,7 +188,7 @@ SKGError SKGImportPluginKmy::importFile() QMap mapIdBank; QDomElement institutions =3D docElem.firstChildElement("INSTIT= UTIONS"); if (!err && !institutions.isNull()) { - SKGTRACEINFUNCRC(10, err); + SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-INSTITUTI= ONS", err); QDomNodeList institutionList =3D institutions.elementsByTa= gName("INSTITUTION"); int nb =3D institutionList.count(); for (int i =3D 0; !err && i < nb; ++i) { @@ -215,18 +215,20 @@ SKGError SKGImportPluginKmy::importFile() = QDomElement accounts =3D docElem.firstChildElement("ACCOUNTS"); if (!err && !accounts.isNull()) { - SKGTRACEINFUNCRC(10, err); + SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-ACCOUNTS"= , err); QDomNodeList accountList =3D accounts.elementsByTagName("A= CCOUNT"); int nb =3D accountList.count(); err =3D m_importer->getDocument()->beginTransaction("#INTE= RNAL#" % i18nc("Import step", "Import accounts"), nb); + QMap type15Account; + QMap type15Unit; for (int i =3D 0; !err && i < nb; ++i) { // Get account object QDomElement account =3D accountList.at(i).toElement(); QString type =3D account.attribute("type"); if (type =3D=3D "15") { // Actions: the real account is the parent - m_mapIdAccount[account.attribute("id")] =3D m_mapI= dAccount[account.attribute("parentaccount")]; - m_mapIdUnit[account.attribute("id")] =3D m_mapIdUn= it[account.attribute("currency")]; + type15Account[account.attribute("id")] =3D account= .attribute("parentaccount"); + type15Unit[account.attribute("id")] =3D account.at= tribute("currency"); } else if (type !=3D "12" && type !=3D "13" && type != =3D "16") { // Get the bank QString bankId =3D account.attribute("institution"= ); @@ -302,6 +304,15 @@ SKGError SKGImportPluginKmy::importFile() } } = + foreach(const QString & i, type15Account.keys()) { + m_mapIdAccount[i] =3D m_mapIdAccount[type15Account= [i]]; + m_mapIdUnit[account.attribute("id")] =3D m_mapIdUn= it[account.attribute("currency")]; + } + + foreach(const QString & i, type15Unit.keys()) { + m_mapIdUnit[i] =3D m_mapIdUnit[type15Unit[i]]; + } + IFOKDO(err, m_importer->getDocument()->stepForward(i += 1)) } = @@ -313,7 +324,7 @@ SKGError SKGImportPluginKmy::importFile() QMap mapIdPayee; QDomElement payees =3D docElem.firstChildElement("PAYEES"); if (!err && !payees.isNull()) { - SKGTRACEINFUNCRC(10, err); + SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-PAYEES", = err); QDomNodeList payeeList =3D payees.elementsByTagName("PAYEE= "); int nb =3D payeeList.count(); for (int i =3D 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-TRANSACTI= ON", err); QDomNodeList transactionList =3D docElem.elementsByTagName= ("TRANSACTION"); int nb =3D transactionList.count(); err =3D m_importer->getDocument()->beginTransaction("#INTE= RNAL#" % i18nc("Import step", "Import operations"), nb); @@ -482,6 +493,10 @@ SKGError SKGImportPluginKmy::importFile() IFOKDO(err, operationObj.setStatus(SKG= OperationObject::CHECKED)) IFOKDO(err, operationObj.save(true, fa= lse)) = + if (!err && !suboperationObj.getID()) { + err =3D operationObj.addSubOperati= on(suboperationObj); + } + IFOKDO(err, suboperationObj.setAttribu= te("d_date", "0000-00-00")) IFOKDO(err, suboperationObj.save(true,= false)) } else { @@ -506,10 +521,10 @@ SKGError SKGImportPluginKmy::importFile() IFOKDO(err, operationObj2.setImpor= ted(true)) IFOKDO(err, operationObj2.setImpor= tID(operationObj.getImportID())) = - if (m_mapIdUnit.contains(suboperat= ion.attribute("account"))) { - IFOKDO(err, operationObj2.setU= nit(m_mapIdUnit[suboperation.attribute("account")])) + SKGUnitObject unit =3D m_mapIdUnit= [suboperation.attribute("account")]; + if (unit.getID()) { + IFOKDO(err, operationObj2.setU= nit(unit)) } else { - SKGUnitObject unit; IFOKDO(err, operationObj.getUn= it(unit)) IFOKDO(err, operationObj2.setU= nit(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 =3D SKGError(ERR_FAIL, i18= nc("Error message", "Account with identifier %1 not found", suboperation.at= tribute("account"))); + } IFOKDO(err, operationObj.setParent= Account(act, true)) IFOKDO(err, operationObj.save()) = @@ -565,7 +583,7 @@ SKGError SKGImportPluginKmy::importFile() // Step 7-Get budgets QDomElement budgets =3D docElem.firstChildElement("BUDGETS"); if (!err && !budgets.isNull()) { - SKGTRACEINFUNCRC(10, err); + SKGTRACEINRC(10, "SKGImportPluginKmy::importFile-BUDGETS",= err); // Build cache of categories QMap catExpense; { diff --git a/plugins/import/skrooge_import_mny/skgimportpluginmny.cpp b/plu= gins/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 =3D readJsonFile(temporaryPath % "/categories.json", var); QVariantList list =3D var.toList(); IFOK(err) { - SKGTRACEINFUNCRC(10, err); + SKGTRACEINRC(10, "SKGImportPluginMny::importFile-categorie= s", err); int nb =3D list.count(); err =3D m_importer->getDocument()->beginTransaction("#INTE= RNAL#" % i18nc("Import step", "Import categories"), nb); // Create categories @@ -226,7 +226,7 @@ SKGError SKGImportPluginMny::importFile() err =3D readJsonFile(temporaryPath % "/payees.json", var); QVariantList list =3D var.toList(); IFOK(err) { - SKGTRACEINFUNCRC(10, err); + SKGTRACEINRC(10, "SKGImportPluginMny::importFile-payees", = err); int nb =3D list.count(); err =3D m_importer->getDocument()->beginTransaction("#INTE= RNAL#" % i18nc("Import step", "Import payees"), nb); // Create categories @@ -257,7 +257,7 @@ SKGError SKGImportPluginMny::importFile() err =3D readJsonFile(temporaryPath % "/securities.json", var); QVariantList list =3D var.toList(); IFOK(err) { - SKGTRACEINFUNCRC(10, err); + SKGTRACEINRC(10, "SKGImportPluginMny::importFile-securitie= s", err); int nb =3D list.count(); err =3D m_importer->getDocument()->beginTransaction("#INTE= RNAL#" % i18nc("Import step", "Import units"), nb); // Create categories diff --git a/tests/input/skgtestimportkmy4/randy1.kmy b/tests/input/skgtest= importkmy4/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/skgbank= modelertest/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(), tru= e); + SKGError err; + { + // Scope of the transaction + SKGBEGINTRANSACTION(document1, "IMPORT_KMY", err); + SKGImportExportManager imp1(&document1, KUrl::fromLocalFile(SK= GTest::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/skgbasemodeler= test/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 % ")", accou= nt.setName(ACCOUNT), true); \ + SKGTESTERROR(QString(ACCOUNT) % ".load(" % ACCOUNT % ")", account.= load(), true); \ + SKGTEST(QString(ACCOUNT) % ".getCurrentAmount(" % ACCOUNT % ")", S= KGServices::doubleToString(account.getCurrentAmount()), SKGServices::double= ToString(AMOUNT));\ + } = +#endif