Added "reported posts" into account xdata

This is necessary because sometimes, a post from one account will get
reported as though it were in another account (this happens with
--budget, to show child account postings within their parent account).
In that case, the account needs to remember which postings have been
reported as being within it, so that it can add these amounts to its own
total in the balance report.
This commit is contained in:
John Wiegley 2009-11-02 01:39:18 -05:00
parent 4db60bb464
commit 3a0879aff0
6 changed files with 44 additions and 3 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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

View file

@ -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)

View file

@ -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