From 48edf1eb5c33e75e9db4ed50d16abe1e57d61ed0 Mon Sep 17 00:00:00 2001 From: smr894 Date: Wed, 4 Apr 2018 23:30:38 -0400 Subject: budget_posts: Keep pending items until the last day they apply --- src/filters.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/filters.cc') diff --git a/src/filters.cc b/src/filters.cc index 4e9e633a..3dfd2327 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -1245,19 +1245,34 @@ void generate_posts::add_post(const date_interval_t& period, post_t& post) void budget_posts::report_budget_items(const date_t& date) { + { // Cleanup pending items that finished before date + // We have to keep them until the last day they apply because operator() needs them to see if a + // posting is budgeted or not + std::list posts_to_erase; + for (pending_posts_list::iterator i = pending_posts.begin(); i != pending_posts.end(); i++) { + pending_posts_list::value_type& pair(*i); + if (pair.first.finish && ! pair.first.start && pair.first.finish < date) { + posts_to_erase.push_back(i); + } + } + foreach (pending_posts_list::iterator& i, posts_to_erase) + pending_posts.erase(i); + } + if (pending_posts.size() == 0) return; bool reported; do { - std::list posts_to_erase; - reported = false; for (pending_posts_list::iterator i = pending_posts.begin(); i != pending_posts.end(); i++) { pending_posts_list::value_type& pair(*i); + if (pair.first.finish && ! pair.first.start) + continue; // skip expired posts + optional begin = pair.first.start; if (! begin) { optional range_begin; @@ -1285,9 +1300,6 @@ void budget_posts::report_budget_items(const date_t& date) post_t& post = *pair.second; ++pair.first; - if (! pair.first.start) - posts_to_erase.push_back(i); - DEBUG("budget.generate", "Reporting budget for " << post.reported_account()->fullname()); @@ -1312,9 +1324,6 @@ void budget_posts::report_budget_items(const date_t& date) reported = true; } } - - foreach (pending_posts_list::iterator& i, posts_to_erase) - pending_posts.erase(i); } while (reported); } -- cgit v1.2.3