diff options
author | Rahix <rahix@rahix.de> | 2020-05-12 23:00:24 +0200 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2020-07-21 14:50:01 -0700 |
commit | 3c7b8442c20f9a86e7077dc8049d97d1f2b33885 (patch) | |
tree | 907c06866baca6fcf56659ad792767d809f81058 | |
parent | 81e107645ebfcb31c285ce8b2a4ea0cd922174f8 (diff) | |
download | fork-ledger-3c7b8442c20f9a86e7077dc8049d97d1f2b33885.tar.gz fork-ledger-3c7b8442c20f9a86e7077dc8049d97d1f2b33885.tar.bz2 fork-ledger-3c7b8442c20f9a86e7077dc8049d97d1f2b33885.zip |
collapse_posts: Use the existing accounts instead of temps
The temps will not have correct depth information attached which means
a display predicate involving `depth` will most likely lead to wrong
results.
-rw-r--r-- | src/filters.cc | 6 | ||||
-rw-r--r-- | src/filters.h | 10 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/filters.cc b/src/filters.cc index 67b6d35a..6db8af80 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -451,7 +451,7 @@ void collapse_posts::report_subtotal() foreach (totals_map::value_type& pat, totals) { handle_value(/* value= */ pat.second, - /* account= */ &temps.create_account(pat.first), + /* account= */ pat.first, /* xact= */ &xact, /* temps= */ temps, /* handler= */ handler, @@ -473,10 +473,10 @@ void collapse_posts::report_subtotal() value_t& collapse_posts::find_totals(account_t* account) { if (collapse_depth == 0) - return totals[_("<Total>")]; + return totals[global_totals_account]; if (account->depth <= collapse_depth) - return totals[account->fullname()]; + return totals[account]; //else recurse return find_totals(account->parent); diff --git a/src/filters.h b/src/filters.h index be2e0e84..5409a97d 100644 --- a/src/filters.h +++ b/src/filters.h @@ -427,7 +427,7 @@ public: class collapse_posts : public item_handler<post_t> { - typedef std::map<string,value_t> totals_map; + typedef std::map<account_t *,value_t> totals_map; expr_t& amount_expr; predicate_t display_predicate; @@ -437,6 +437,7 @@ class collapse_posts : public item_handler<post_t> xact_t * last_xact; post_t * last_post; temporaries_t temps; + account_t * global_totals_account; totals_map totals; bool only_collapse_if_zero; unsigned short collapse_depth; @@ -459,12 +460,18 @@ public: last_xact(NULL), last_post(NULL), only_collapse_if_zero(_only_collapse_if_zero), collapse_depth(_collapse_depth), report(_report) { + create_accounts(); TRACE_CTOR(collapse_posts, "post_handler_ptr, ..."); } virtual ~collapse_posts() { TRACE_DTOR(collapse_posts); handler.reset(); } + + void create_accounts() { + global_totals_account = &temps.create_account(_("<Total>")); + } + value_t& find_totals(account_t* account); virtual void flush() { @@ -487,6 +494,7 @@ public: last_post = NULL; temps.clear(); + create_accounts(); totals.clear(); component_posts.clear(); |