summaryrefslogtreecommitdiff
path: root/src/draft.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-03-07 22:53:57 -0500
committerJohn Wiegley <johnw@newartisans.com>2010-03-08 01:11:55 -0500
commit1bf0220f246c5e984d9a43e5d8b3979b9091bc5a (patch)
tree710291f43415b9aed741a948ee8687316df13bda /src/draft.cc
parente070cdfc8ddcf9d6a25b593502f1c5ade56c849c (diff)
downloadfork-ledger-1bf0220f246c5e984d9a43e5d8b3979b9091bc5a.tar.gz
fork-ledger-1bf0220f246c5e984d9a43e5d8b3979b9091bc5a.tar.bz2
fork-ledger-1bf0220f246c5e984d9a43e5d8b3979b9091bc5a.zip
Added experimental account lookup logic
This is used by the "xact" command, and the CSV importer. It is very slow O(xacts*records).
Diffstat (limited to 'src/draft.cc')
-rw-r--r--src/draft.cc26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/draft.cc b/src/draft.cc
index 74e17dba..89c68541 100644
--- a/src/draft.cc
+++ b/src/draft.cc
@@ -38,6 +38,7 @@
#include "journal.h"
#include "session.h"
#include "report.h"
+#include "lookup.h"
#include "print.h"
namespace ledger {
@@ -242,18 +243,25 @@ xact_t * draft_t::insert(journal_t& journal)
if (tmpl->payee_mask.empty())
throw std::runtime_error(_("xact' command requires at least a payee"));
- xact_t * matching = NULL;
+ xact_t * matching = NULL;
std::auto_ptr<xact_t> added(new xact_t);
- for (xacts_list::reverse_iterator j = journal.xacts.rbegin();
- j != journal.xacts.rend();
- j++) {
- if (tmpl->payee_mask.match((*j)->payee)) {
- matching = *j;
- DEBUG("derive.xact",
- "Found payee match: transaction on line " << (*j)->pos->beg_line);
- break;
+ xacts_iterator xi(journal);
+ if (xact_t * xact = lookup_probable_account(tmpl->payee_mask.str(), xi).first) {
+ DEBUG("derive.xact", "Found payee by lookup: transaction on line "
+ << xact->pos->beg_line);
+ matching = xact;
+ } else {
+ for (xacts_list::reverse_iterator j = journal.xacts.rbegin();
+ j != journal.xacts.rend();
+ j++) {
+ if (tmpl->payee_mask.match((*j)->payee)) {
+ matching = *j;
+ DEBUG("derive.xact",
+ "Found payee match: transaction on line " << (*j)->pos->beg_line);
+ break;
+ }
}
}