diff options
author | John Wiegley <johnw@newartisans.com> | 2006-03-04 14:17:26 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 05:48:44 -0400 |
commit | 6375730fc9af02c27ec774aa2b9929095f5ffbde (patch) | |
tree | 9f27f3ba154fd462d237f7eba670c9f87d703704 /derive.cc | |
parent | 2034d6640c5ba7465cadda5da0060b55c7277d22 (diff) | |
download | fork-ledger-6375730fc9af02c27ec774aa2b9929095f5ffbde.tar.gz fork-ledger-6375730fc9af02c27ec774aa2b9929095f5ffbde.tar.bz2 fork-ledger-6375730fc9af02c27ec774aa2b9929095f5ffbde.zip |
*** no comment ***
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; |