Commit 182c2267 authored by Thomas Baumgart's avatar Thomas Baumgart
Browse files

Convert GnuCash account type to valid top-level account type

The GnuCash template may use any account type for top-level account
groups. KMyMoney only supports certain types. The current conversion did
not take that into account and some templates failed during loading into
KMyMoney.

This change adjusts the account type of the top-level accounts to those
supported by KMyMoney and makes the templates loadable.

CCBUG: 452863
parent 0b51881e
......@@ -238,7 +238,7 @@ bool MyMoneyAccount::operator == (const MyMoneyAccount& right) const
// clang-format on
}
Account::Type MyMoneyAccount::accountGroup(Account::Type type) const
Account::Type MyMoneyAccount::accountGroup(Account::Type type)
{
switch (type) {
case Account::Type::Checkings:
......
......@@ -155,7 +155,7 @@ public:
/**
* Return the account group for a given account @a type.
*/
eMyMoney::Account::Type accountGroup(eMyMoney::Account::Type type) const;
static eMyMoney::Account::Type accountGroup(eMyMoney::Account::Type type);
/**
* This method returns the id of the MyMoneyInstitution object this account
......
......@@ -64,8 +64,20 @@ DirNameMapType &getDirNameMap()
return dirNameMap;
}
int toKMyMoneyAccountType(const QString &type)
int toKMyMoneyAccountType(const QString& type, int index)
{
// in case index is 1 we process the level that represents the
// KMyMoney top-level accounts. They can only have distinct values
// and we have to make sure to return one of them by converting
// the Account::Type into the respective accountGroup value.
if (index == 1) {
const auto accountType = toKMyMoneyAccountType(type, 0);
if (accountType != (int)Account::Type::Unknown) {
return (int)MyMoneyAccount::accountGroup(static_cast<eMyMoney::Account::Type>(accountType));
}
return 99; // unknown
}
if(type == "ROOT") return (int)Account::Type::Unknown;
else if (type == "BANK") return (int)Account::Type::Checkings;
else if (type == "CASH") return (int)Account::Type::Cash;
......@@ -105,11 +117,11 @@ public:
void clear()
{
id = "";
m_type = "";
m_name = "";
code = "";
parent = "";
id.clear();
m_type.clear();
m_name.clear();
code.clear();
parent.clear();
slotList.clear();
}
......@@ -272,7 +284,7 @@ public:
if (account->m_type != "ROOT")
{
xml.writeStartElement("","account");
xml.writeAttribute("type", QString::number(toKMyMoneyAccountType(account->m_type)));
xml.writeAttribute("type", QString::number(toKMyMoneyAccountType(account->m_type, index)));
xml.writeAttribute("name", noLevel1Names && index < 2 ? "" : account->m_name);
if (withID)
xml.writeAttribute("id", account->id);
......@@ -363,7 +375,7 @@ public:
{
QString a;
a.fill(' ', index);
qDebug() << a << account->m_name << toKMyMoneyAccountType(account->m_type);
qDebug() << a << account->m_name << toKMyMoneyAccountType(account->m_type, index);
index++;
dumpTemplates(account->id, index);
index--;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment