diff options
-rw-r--r-- | src/account.cc | 15 | ||||
-rw-r--r-- | src/account.h | 6 | ||||
-rw-r--r-- | src/filters.cc | 2 | ||||
-rw-r--r-- | src/post.cc | 6 | ||||
-rw-r--r-- | src/post.h | 2 | ||||
-rw-r--r-- | test/regress/D060256A.test | 16 |
6 files changed, 44 insertions, 3 deletions
diff --git a/src/account.cc b/src/account.cc index b14520d3..23761049 100644 --- a/src/account.cc +++ b/src/account.cc @@ -397,6 +397,21 @@ value_t account_t::amount(const optional<expr_t&>& expr) const xdata_->self_details.last_post = i; } + if (xdata_->self_details.last_reported_post) + i = *xdata_->self_details.last_reported_post; + else + i = xdata_->reported_posts.begin(); + + for (; i != xdata_->reported_posts.end(); i++) { + if ((*i)->xdata().has_flags(POST_EXT_VISITED)) { + if (! (*i)->xdata().has_flags(POST_EXT_CONSIDERED)) { + (*i)->add_to_value(xdata_->self_details.total, expr); + (*i)->xdata().add_flags(POST_EXT_CONSIDERED); + } + } + xdata_->self_details.last_reported_post = i; + } + return xdata_->self_details.total; } else { return NULL_VALUE; diff --git a/src/account.h b/src/account.h index ce0a7a66..c8f6bdbd 100644 --- a/src/account.h +++ b/src/account.h @@ -159,6 +159,7 @@ public: std::set<string> payees_referenced; optional<posts_list::const_iterator> last_post; + optional<posts_list::const_iterator> last_reported_post; details_t() : calculated(false), @@ -176,8 +177,9 @@ public: void update(post_t& post, bool gather_all = false); }; - details_t self_details; - details_t family_details; + details_t self_details; + details_t family_details; + posts_list reported_posts; std::list<sort_value_t> sort_values; diff --git a/src/filters.cc b/src/filters.cc index 201fddf1..00e495dd 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -815,7 +815,7 @@ void budget_posts::operator()(post_t& post) post_in_budget = true; // Report the post as if it had occurred in the parent account. if (post.reported_account() != acct) - post.xdata().account = acct; + post.set_reported_account(acct); goto handle; } } diff --git a/src/post.cc b/src/post.cc index 0d6ab8a0..2a1663cb 100644 --- a/src/post.cc +++ b/src/post.cc @@ -436,4 +436,10 @@ void post_t::add_to_value(value_t& value, const optional<expr_t&>& expr) const } } +void post_t::set_reported_account(account_t * account) +{ + xdata().account = account; + account->xdata().reported_posts.push_back(this); +} + } // namespace ledger @@ -193,6 +193,8 @@ public: void add_to_value(value_t& value, const optional<expr_t&>& expr = none) const; + void set_reported_account(account_t * account); + account_t * reported_account() { if (xdata_) if (account_t * acct = xdata_->account) diff --git a/test/regress/D060256A.test b/test/regress/D060256A.test new file mode 100644 index 00000000..26c30351 --- /dev/null +++ b/test/regress/D060256A.test @@ -0,0 +1,16 @@ +budget --now=2009/11/01 --end=2009/11/30 +<<< +~ Monthly + Expenses:Food $500.00 + Assets + +2009/11/01 Sample + Expenses:Food:Dining $20.00 + Assets +>>>1 + $-20.00 $-500.00 $480.00 4% Assets + $20.00 $500.00 $-480.00 4% Expenses:Food +------------ ------------ ------------ ----- + 0 0 0 0 +>>>2 +=== 0 |