From 6375730fc9af02c27ec774aa2b9929095f5ffbde Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 4 Mar 2006 14:17:26 +0000 Subject: *** no comment *** --- derive.cc | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'derive.cc') 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 @@ -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 > 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; -- cgit v1.2.3