From d5b1ee56e188c49f1f1b2c8bfc5e0cedcf320f17 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Oct 2009 03:22:31 -0400 Subject: Don't output extra commodity "posts" If a posting has already been registered for a given date with a given price, don't register it again. --- src/iterators.cc | 71 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/src/iterators.cc b/src/iterators.cc index e9560cc0..50c67ade 100644 --- a/src/iterators.cc +++ b/src/iterators.cc @@ -90,37 +90,48 @@ void posts_commodities_iterator::reset(journal_t& journal) std::map xacts_by_commodity; foreach (commodity_t * comm, commodities) { - optional history = comm->varied_history(); - if (! history) - continue; - - account_t * account = journal.master->find_account(comm->symbol()); - - foreach (commodity_t::base_t::history_by_commodity_map::value_type pair, - history->histories) { - foreach (commodity_t::base_t::history_map::value_type hpair, - pair.second.prices) { - xact_t * xact; - string symbol = hpair.second.commodity().symbol(); - - std::map::iterator i = - xacts_by_commodity.find(symbol); - if (i != xacts_by_commodity.end()) { - xact = (*i).second; - } else { - xact = &temps.create_xact(); - xact_temps.push_back(xact); - xact->payee = symbol; - xact->_date = hpair.first.date(); - xacts_by_commodity.insert - (std::pair(symbol, xact)); + if (optional history = + comm->varied_history()) { + account_t * account = journal.master->find_account(comm->symbol()); + + foreach (commodity_t::base_t::history_by_commodity_map::value_type pair, + history->histories) { + foreach (commodity_t::base_t::history_map::value_type hpair, + pair.second.prices) { + xact_t * xact; + string symbol = hpair.second.commodity().symbol(); + + std::map::iterator i = + xacts_by_commodity.find(symbol); + if (i != xacts_by_commodity.end()) { + xact = (*i).second; + } else { + xact = &temps.create_xact(); + xact_temps.push_back(xact); + xact->payee = symbol; + xact->_date = hpair.first.date(); + xacts_by_commodity.insert + (std::pair(symbol, xact)); + } + + bool post_already_exists = false; + + foreach (post_t * post, xact->posts) { + if (post->_date == hpair.first.date() && + post->amount == hpair.second) { + post_already_exists = true; + break; + } + } + + if (! post_already_exists) { + post_t& temp = temps.create_post(*xact, account); + temp._date = hpair.first.date(); + temp.amount = hpair.second; + + temp.xdata().datetime = hpair.first; + } } - - post_t& temp = temps.create_post(*xact, account); - temp._date = hpair.first.date(); - temp.amount = hpair.second; - - temp.xdata().datetime = hpair.first; } } } -- cgit v1.2.3