Skip to content

Commit d7bc4ba

Browse files
authored
Merge pull request ledger#557 from smr894/fix-missing-trans-in-last-budget-period
budget_posts: Keep pending items until the last day they apply
2 parents a9859bc + 48edf1e commit d7bc4ba

File tree

2 files changed

+96
-8
lines changed

2 files changed

+96
-8
lines changed

src/filters.cc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,19 +1245,34 @@ void generate_posts::add_post(const date_interval_t& period, post_t& post)
12451245

12461246
void budget_posts::report_budget_items(const date_t& date)
12471247
{
1248+
{ // Cleanup pending items that finished before date
1249+
// We have to keep them until the last day they apply because operator() needs them to see if a
1250+
// posting is budgeted or not
1251+
std::list<pending_posts_list::iterator> posts_to_erase;
1252+
for (pending_posts_list::iterator i = pending_posts.begin(); i != pending_posts.end(); i++) {
1253+
pending_posts_list::value_type& pair(*i);
1254+
if (pair.first.finish && ! pair.first.start && pair.first.finish < date) {
1255+
posts_to_erase.push_back(i);
1256+
}
1257+
}
1258+
foreach (pending_posts_list::iterator& i, posts_to_erase)
1259+
pending_posts.erase(i);
1260+
}
1261+
12481262
if (pending_posts.size() == 0)
12491263
return;
12501264

12511265
bool reported;
12521266
do {
1253-
std::list<pending_posts_list::iterator> posts_to_erase;
1254-
12551267
reported = false;
12561268
for (pending_posts_list::iterator i = pending_posts.begin();
12571269
i != pending_posts.end();
12581270
i++) {
12591271
pending_posts_list::value_type& pair(*i);
12601272

1273+
if (pair.first.finish && ! pair.first.start)
1274+
continue; // skip expired posts
1275+
12611276
optional<date_t> begin = pair.first.start;
12621277
if (! begin) {
12631278
optional<date_t> range_begin;
@@ -1285,9 +1300,6 @@ void budget_posts::report_budget_items(const date_t& date)
12851300
post_t& post = *pair.second;
12861301

12871302
++pair.first;
1288-
if (! pair.first.start)
1289-
posts_to_erase.push_back(i);
1290-
12911303
DEBUG("budget.generate", "Reporting budget for "
12921304
<< post.reported_account()->fullname());
12931305

@@ -1312,9 +1324,6 @@ void budget_posts::report_budget_items(const date_t& date)
13121324
reported = true;
13131325
}
13141326
}
1315-
1316-
foreach (pending_posts_list::iterator& i, posts_to_erase)
1317-
pending_posts.erase(i);
13181327
} while (reported);
13191328
}
13201329

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
= ~ ^A
2+
[Balance] 1
3+
[Budget:$account] -1
4+
5+
~ Monthly from 2014/01 to 2014/12/31
6+
[Budget:A] 100.00 USD
7+
[Balance]
8+
9+
~ Monthly from 2014/01 to 2014/12/31
10+
[Budget:Z] 100.00 USD
11+
[Balance]
12+
13+
2014/10/01 toto0
14+
[Budget:A:B] 0.01 USD
15+
[Balance]
16+
17+
2014/11/01 toto1
18+
A:B 51.00 USD
19+
Cash
20+
21+
2014/11/02 toto2
22+
A:B 52.00 USD
23+
Cash
24+
25+
2014/11/03 toto3
26+
A:B 53.00 USD
27+
Cash
28+
29+
2014/11/04 toto4
30+
A:B 54.00 USD
31+
Cash
32+
33+
2014/12/08 toto5
34+
A:B 55.00 USD
35+
Cash
36+
37+
2014/12/09 toto6
38+
A:B 56.00 USD
39+
Cash
40+
41+
2014/12/10 toto7
42+
A:B 57.00 USD
43+
Cash
44+
45+
2014/12/11 toto8
46+
A:B 58.00 USD
47+
Cash
48+
49+
2014/12/12 toto9
50+
A:B 59.00 USD
51+
Cash
52+
53+
2014/12/12 toto9
54+
C 59.00 USD
55+
Cash
56+
57+
2015/01/12 toto10
58+
A:B 59.00 USD
59+
Cash
60+
61+
test reg --budget -b 2014/10 -e 2015/02 --columns 80 --date-format "%F" reg ^Bu
62+
2014-10-01 Budget transaction [Budget:A] -100.00 USD -100.00 USD
63+
2014-10-01 Budget transaction [Budget:Z] -100.00 USD -200.00 USD
64+
2014-10-01 toto0 [Budget:A] 0.01 USD -199.99 USD
65+
2014-11-01 Budget transaction [Budget:A] -100.00 USD -299.99 USD
66+
2014-11-01 Budget transaction [Budget:Z] -100.00 USD -399.99 USD
67+
2014-11-01 toto1 [Budget:A] -51.00 USD -450.99 USD
68+
2014-11-02 toto2 [Budget:A] -52.00 USD -502.99 USD
69+
2014-11-03 toto3 [Budget:A] -53.00 USD -555.99 USD
70+
2014-11-04 toto4 [Budget:A] -54.00 USD -609.99 USD
71+
2014-12-01 Budget transaction [Budget:A] -100.00 USD -709.99 USD
72+
2014-12-01 Budget transaction [Budget:Z] -100.00 USD -809.99 USD
73+
2014-12-08 toto5 [Budget:A] -55.00 USD -864.99 USD
74+
2014-12-09 toto6 [Budget:A] -56.00 USD -920.99 USD
75+
2014-12-10 toto7 [Budget:A] -57.00 USD -977.99 USD
76+
2014-12-11 toto8 [Budget:A] -58.00 USD -1035.99 USD
77+
2014-12-12 toto9 [Budget:A] -59.00 USD -1094.99 USD
78+
2015-01-12 toto10 [Budget:A] -59.00 USD -1153.99 USD
79+
end test

0 commit comments

Comments
 (0)