Add ImportPanel
Throw exception when category/account are not found in User Fix a bug in GrisbiImportEngine with QDate::fromString Try to search an account also with its name Remove categories number limit (only used for pie color)
This commit is contained in:
@@ -80,7 +80,7 @@ QString User::GetCategoryName(int catId)
|
||||
return _("Unknown") ;
|
||||
}
|
||||
|
||||
int User::GetCategoryId(const QString& catName)
|
||||
int User::GetCategoryId(const QString& catName) throw (CategoryNotFound)
|
||||
{
|
||||
std::vector<Category>::iterator it;
|
||||
Category cat;
|
||||
@@ -92,7 +92,7 @@ int User::GetCategoryId(const QString& catName)
|
||||
if ( _db->LoadCategory(0, catName, cat))
|
||||
return cat.id;
|
||||
|
||||
return 0 ;
|
||||
throw CategoryNotFound();
|
||||
}
|
||||
|
||||
const QFont User::GetCategoryFont(int catId)
|
||||
@@ -158,24 +158,24 @@ QString User::GetAccountName(int accountId)
|
||||
return _("Unknown") ;
|
||||
}
|
||||
|
||||
int User::GetAccountId(const QString& accountName)
|
||||
int User::GetAccountId(const QString& accountName) throw (AccountNotFound)
|
||||
{
|
||||
std::vector<Account>::iterator it;
|
||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||
if (it->name == accountName)
|
||||
return it->id;
|
||||
|
||||
return 0 ;
|
||||
throw AccountNotFound();
|
||||
}
|
||||
|
||||
int User::GetAccountIdFromAccountNumber(const QString& accountNumber)
|
||||
int User::GetAccountIdFromAccountNumber(const QString& accountNumber) throw (AccountNotFound)
|
||||
{
|
||||
std::vector<Account>::iterator it;
|
||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||
if (it->number == accountNumber)
|
||||
return it->id;
|
||||
|
||||
return 0 ;
|
||||
throw AccountNotFound();
|
||||
}
|
||||
|
||||
void User::AddAccount(Account& ac)
|
||||
|
||||
@@ -52,10 +52,11 @@ public:
|
||||
std::map<QString, ImportPattern> _importPatterns;
|
||||
|
||||
class AccountNotFound {};
|
||||
class CategoryNotFound {};
|
||||
|
||||
Category GetCategory(int catId);
|
||||
QString GetCategoryName(int catId);
|
||||
int GetCategoryId(const QString& catName);
|
||||
int GetCategoryId(const QString& catName) throw (CategoryNotFound);
|
||||
const QFont GetCategoryFont(int catId);
|
||||
void AddCategory(const Category& cat);
|
||||
void UpdateCategory(const Category& cat);
|
||||
@@ -64,8 +65,8 @@ public:
|
||||
|
||||
Account GetAccount(int accountId) throw (AccountNotFound);
|
||||
QString GetAccountName(int accountId);
|
||||
int GetAccountId(const QString& accountName);
|
||||
int GetAccountIdFromAccountNumber(const QString& accountNumber);
|
||||
int GetAccountId(const QString& accountName) throw (AccountNotFound);
|
||||
int GetAccountIdFromAccountNumber(const QString& accountNumber) throw (AccountNotFound);
|
||||
void AddAccount(Account& ac);
|
||||
void UpdateAccount(Account& ac);
|
||||
void DeleteAccount(Account& ac);
|
||||
|
||||
@@ -110,10 +110,10 @@ void GrisbiImportEngine::LoadOperation(const QXmlAttributes& attrs)
|
||||
|
||||
op.account = _accounts[attrs.value("Ac").toInt()];
|
||||
|
||||
date.fromString(attrs.value("Dt"), "MM/%dd/%yyyy");
|
||||
date = QDate::fromString(attrs.value("Dt"), "MM/dd/yyyy");
|
||||
op.day = date.day();
|
||||
op.month = date.month();
|
||||
op.year = date.year();
|
||||
op.year = date.year();
|
||||
op.amount = attrs.value("Am").toDouble();
|
||||
op.category = _categories[attrs.value("Ca").toInt()];
|
||||
op.description = attrs.value("No");
|
||||
|
||||
@@ -93,7 +93,6 @@ bool XMLImportEngine::startElement (const QString& namespaceURI, const QString&
|
||||
void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs)
|
||||
{
|
||||
int id;
|
||||
QString account_number, name;
|
||||
Account ac;
|
||||
static int unknownAccount = 0;
|
||||
|
||||
@@ -101,7 +100,7 @@ void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs)
|
||||
|
||||
ac.name = attrs.value("name");
|
||||
ac.id = id = attrs.value("id").toInt();
|
||||
ac.number = account_number = attrs.value("number");
|
||||
ac.number = attrs.value("number");
|
||||
ac.blocked = (attrs.value("blocked") == "1");
|
||||
ac._virtual = (attrs.value("virtual") == "1");
|
||||
ac.hidden = (attrs.value("hidden") == "1");
|
||||
@@ -113,10 +112,21 @@ void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs)
|
||||
ac.shared = false;
|
||||
ac.is_owner = true;
|
||||
|
||||
if (account_number.size())
|
||||
if (ac.number.size())
|
||||
{
|
||||
try {
|
||||
_accounts[ac.id] = _user->GetAccountIdFromAccountNumber(account_number);
|
||||
_accounts[ac.id] = _user->GetAccountIdFromAccountNumber(ac.number);
|
||||
return;
|
||||
}
|
||||
catch (User::AccountNotFound)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (ac.name.size())
|
||||
{
|
||||
try {
|
||||
_accounts[ac.id] = _user->GetAccountId(ac.name);
|
||||
return;
|
||||
}
|
||||
catch (User::AccountNotFound)
|
||||
|
||||
Reference in New Issue
Block a user