diff options
author | John Wiegley <johnw@newartisans.com> | 2006-03-04 17:13:45 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 02:41:29 -0400 |
commit | 7acc1306d985fb532ee429121fac0e1692285503 (patch) | |
tree | 6ff877c57daf4fdeb048147dad6f17811cdeca41 /derive.cc | |
parent | 11498f48070a9e96826afb316c684fed8c59397b (diff) | |
download | fork-ledger-7acc1306d985fb532ee429121fac0e1692285503.tar.gz fork-ledger-7acc1306d985fb532ee429121fac0e1692285503.tar.bz2 fork-ledger-7acc1306d985fb532ee429121fac0e1692285503.zip |
*** empty log message ***
Diffstat (limited to 'derive.cc')
-rw-r--r-- | derive.cc | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -2,6 +2,7 @@ #include "datetime.h" #include "error.h" #include "mask.h" +#include "walk.h" #include <memory> @@ -47,10 +48,31 @@ entry_t * derive_new_entry(journal_t& journal, i++; } - if (i == end) + if (i == end) { added->add_transaction(new transaction_t(acct)); - else - added->add_transaction(new transaction_t(acct, amount_t(*i++))); + } else { + transaction_t * xact = new transaction_t(acct, amount_t(*i++)); + added->add_transaction(xact); + + if (! xact->amount.commodity()) { + // If the amount has no commodity, we can determine it given + // the account by creating a final for the account and then + // checking if it contains only a single commodity. An + // account to which only dollars are applied would imply that + // dollars are wanted now too. + + std::auto_ptr<item_handler<transaction_t> > formatter; + formatter.reset(new set_account_value); + walk_entries(journal.entries, *formatter.get()); + formatter->flush(); + + sum_accounts(*journal.master); + + value_t total = account_xdata(*acct).total; + if (total.type == value_t::AMOUNT) + xact->amount.set_commodity(((amount_t *) total.data)->commodity()); + } + } if (journal.basket) acct = journal.basket; |