summaryrefslogtreecommitdiff
path: root/derive.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2006-03-04 17:13:45 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 02:41:29 -0400
commit7acc1306d985fb532ee429121fac0e1692285503 (patch)
tree6ff877c57daf4fdeb048147dad6f17811cdeca41 /derive.cc
parent11498f48070a9e96826afb316c684fed8c59397b (diff)
downloadfork-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.cc28
1 files changed, 25 insertions, 3 deletions
diff --git a/derive.cc b/derive.cc
index 5e103dc9..20083796 100644
--- a/derive.cc
+++ b/derive.cc
@@ -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;