summaryrefslogtreecommitdiff
path: root/src/filters.cc
diff options
context:
space:
mode:
authorsmr894 <smr894@lametissebleue.com>2018-04-04 23:30:38 -0400
committersmr894 <smr894@lametissebleue.com>2018-04-04 23:30:38 -0400
commit48edf1eb5c33e75e9db4ed50d16abe1e57d61ed0 (patch)
treef46a4eec4c393b7104a8a9848bb0aa03ef522ea2 /src/filters.cc
parenta9859bc6d131afe564adaf0b1628cee75c4bead3 (diff)
downloadfork-ledger-48edf1eb5c33e75e9db4ed50d16abe1e57d61ed0.tar.gz
fork-ledger-48edf1eb5c33e75e9db4ed50d16abe1e57d61ed0.tar.bz2
fork-ledger-48edf1eb5c33e75e9db4ed50d16abe1e57d61ed0.zip
budget_posts: Keep pending items until the last day they apply
Diffstat (limited to 'src/filters.cc')
-rw-r--r--src/filters.cc25
1 files changed, 17 insertions, 8 deletions
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<pending_posts_list::iterator> 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<pending_posts_list::iterator> 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<date_t> begin = pair.first.start;
if (! begin) {
optional<date_t> 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);
}