Lookup probable accounts in reverse historical order

Fixes #510
This commit is contained in:
John Wiegley 2011-07-19 23:29:31 -05:00
parent d0dfff62a6
commit 966b6fc359
4 changed files with 16 additions and 17 deletions

View file

@ -121,14 +121,10 @@ value_t convert_command(call_scope_t& args)
} }
else { else {
if (xact->posts.front()->account == NULL) { if (xact->posts.front()->account == NULL) {
xacts_iterator xi;
xi.xacts_i = current_xacts.begin();
xi.xacts_end = current_xacts.end();
xi.xacts_uninitialized = false;
// jww (2010-03-07): Bind this logic to an option: --auto-match // jww (2010-03-07): Bind this logic to an option: --auto-match
if (account_t * acct = if (account_t * acct =
lookup_probable_account(xact->payee, xi, bucket).second) lookup_probable_account(xact->payee, current_xacts.rbegin(),
current_xacts.rend(), bucket).second)
xact->posts.front()->account = acct; xact->posts.front()->account = acct;
else else
xact->posts.front()->account = unknown; xact->posts.front()->account = unknown;

View file

@ -246,11 +246,11 @@ xact_t * draft_t::insert(journal_t& journal)
throw std::runtime_error(_("'xact' command requires at least a payee")); 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); std::auto_ptr<xact_t> added(new xact_t);
xacts_iterator xi(journal); if (xact_t * xact =
if (xact_t * xact = lookup_probable_account(tmpl->payee_mask.str(), xi).first) { lookup_probable_account(tmpl->payee_mask.str(), journal.xacts.rbegin(),
journal.xacts.rend()).first) {
DEBUG("draft.xact", "Found payee by lookup: transaction on line " DEBUG("draft.xact", "Found payee by lookup: transaction on line "
<< xact->pos->beg_line); << xact->pos->beg_line);
matching = xact; matching = xact;

View file

@ -61,7 +61,8 @@ namespace {
std::pair<xact_t *, account_t *> std::pair<xact_t *, account_t *>
lookup_probable_account(const string& ident, lookup_probable_account(const string& ident,
xacts_iterator& iter_func, xacts_list::reverse_iterator iter,
xacts_list::reverse_iterator end,
account_t * ref_account) account_t * ref_account)
{ {
scorecard_t scores; scorecard_t scores;
@ -83,7 +84,8 @@ lookup_probable_account(const string& ident,
" with reference account: " << ref_account->fullname()); " with reference account: " << ref_account->fullname());
#endif #endif
while (xact_t * xact = iter_func()) { xact_t * xact;
while (iter != end && (xact = *iter++) != NULL) {
#if 0 #if 0
// Only consider transactions from the last two years (jww (2010-03-07): // Only consider transactions from the last two years (jww (2010-03-07):
// make this an option) // make this an option)

View file

@ -48,7 +48,8 @@ namespace ledger {
std::pair<xact_t *, account_t *> std::pair<xact_t *, account_t *>
lookup_probable_account(const string& ident, lookup_probable_account(const string& ident,
xacts_iterator& iter_func, xacts_list::reverse_iterator iter,
xacts_list::reverse_iterator end,
account_t * ref_account = NULL); account_t * ref_account = NULL);
} // namespace ledger } // namespace ledger