diff options
author | John Wiegley <johnw@newartisans.com> | 2009-10-31 03:22:31 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-10-31 03:22:31 -0400 |
commit | d5b1ee56e188c49f1f1b2c8bfc5e0cedcf320f17 (patch) | |
tree | 3381286ec79c41f16f2485bac55289d19aab89c6 /src/iterators.cc | |
parent | e182f01de169d3d3daa76fd6d80220198b9d014f (diff) | |
download | fork-ledger-d5b1ee56e188c49f1f1b2c8bfc5e0cedcf320f17.tar.gz fork-ledger-d5b1ee56e188c49f1f1b2c8bfc5e0cedcf320f17.tar.bz2 fork-ledger-d5b1ee56e188c49f1f1b2c8bfc5e0cedcf320f17.zip |
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.
Diffstat (limited to 'src/iterators.cc')
-rw-r--r-- | src/iterators.cc | 71 |
1 files 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<string, xact_t *> xacts_by_commodity; foreach (commodity_t * comm, commodities) { - optional<commodity_t::varied_history_t&> 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<string, xact_t *>::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<string, xact_t *>(symbol, xact)); + if (optional<commodity_t::varied_history_t&> 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<string, xact_t *>::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<string, xact_t *>(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; } } } |