From e78af146e810eaaf0a44fd5c5d745efa2bbf9561 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 13 Jun 2010 23:41:50 -0400 Subject: Corrected bug with forecasting date bounded xacts --- src/filters.cc | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/filters.cc') diff --git a/src/filters.cc b/src/filters.cc index 86386f58..2992f512 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -1228,18 +1228,16 @@ void budget_posts::operator()(post_t& post) void forecast_posts::add_post(const date_interval_t& period, post_t& post) { - generate_posts::add_post(period, post); + date_interval_t i(period); + if (! i.start && ! i.find_period(CURRENT_DATE())) + return; + + generate_posts::add_post(i, post); - // Advance the period's interval until it is at or beyond the current date. - date_interval_t& i = pending_posts.back().first; - if (! i.start) { - if (! i.find_period(CURRENT_DATE())) - throw_(std::runtime_error, _("Something odd has happened")); + // Advance the period's interval until it is at or beyond the current + // date. + while (*i.start < CURRENT_DATE()) ++i; - } else { - while (*i.start < CURRENT_DATE()) - ++i; - } } void forecast_posts::flush() @@ -1281,6 +1279,8 @@ void forecast_posts::flush() for (pending_posts_list::iterator i = ++pending_posts.begin(); i != pending_posts.end(); i++) { + assert((*i).first.start); + assert((*least).first.start); if (*(*i).first.start < *(*least).first.start) least = i; } @@ -1307,7 +1307,6 @@ void forecast_posts::flush() } begin = next; - ++(*least).first; // `post' refers to the posting defined in the period transaction. We // make a copy of it within a temporary transaction with the payee @@ -1337,6 +1336,14 @@ void forecast_posts::flush() continue; } } + + // Increment the 'least', but remove it from pending_posts if it + // exceeds its own boundaries. + ++(*least).first; + if (! (*least).first.start) { + pending_posts.erase(least); + continue; + } } item_handler::flush(); -- cgit v1.2.3 From 847a5fae3d6ec2c011da95f282abc3947e4da1ef Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 14 Jun 2010 00:38:56 -0400 Subject: Removed some unneeded code --- src/filters.cc | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'src/filters.cc') diff --git a/src/filters.cc b/src/filters.cc index 2992f512..69183991 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -501,26 +501,15 @@ void related_posts::flush() { if (posts.size() > 0) { foreach (post_t * post, posts) { - if (post->xact) { - foreach (post_t * r_post, post->xact->posts) { - post_t::xdata_t& xdata(r_post->xdata()); - if (! xdata.has_flags(POST_EXT_HANDLED) && - (! xdata.has_flags(POST_EXT_RECEIVED) ? - ! r_post->has_flags(ITEM_GENERATED | POST_VIRTUAL) : - also_matching)) { - xdata.add_flags(POST_EXT_HANDLED); - item_handler::operator()(*r_post); - } - } - } else { - // This code should only be reachable from the "output" - // command, since that is the only command which attempts to - // output auto or period xacts. - post_t::xdata_t& xdata(post->xdata()); + assert(post->xact); + foreach (post_t * r_post, post->xact->posts) { + post_t::xdata_t& xdata(r_post->xdata()); if (! xdata.has_flags(POST_EXT_HANDLED) && - ! post->has_flags(ITEM_GENERATED)) { + (! xdata.has_flags(POST_EXT_RECEIVED) ? + ! r_post->has_flags(ITEM_GENERATED | POST_VIRTUAL) : + also_matching)) { xdata.add_flags(POST_EXT_HANDLED); - item_handler::operator()(*post); + item_handler::operator()(*r_post); } } } -- cgit v1.2.3