diff options
author | Daraul <thurst306@gmail.com> | 2020-03-10 13:38:43 -0400 |
---|---|---|
committer | Martin Michlmayr <tbm@cyrius.com> | 2020-04-05 11:33:09 +0800 |
commit | 0018c884dbf228c54e30f0bc8b7586cc35c56b0f (patch) | |
tree | 66f637fb69dd59e5e902cdb2ecd1aa041e26f933 /src/account.cc | |
parent | a413a072a5a8199d0acee6d6b7a9586a4ddd86ac (diff) | |
download | fork-ledger-0018c884dbf228c54e30f0bc8b7586cc35c56b0f.tar.gz fork-ledger-0018c884dbf228c54e30f0bc8b7586cc35c56b0f.tar.bz2 fork-ledger-0018c884dbf228c54e30f0bc8b7586cc35c56b0f.zip |
fix: Fix #543 by tracking an account's real balance
Without these changes, whether an account's balance is virtual
or real is not considered when asserting it's balance. This lead
to situations where the user must consider their virtual postings
when attemping to assert the real balance of the account. See
test/regress/543_a.test for that testcase, taken from the original
issue. This commit also includes other, fringe, situations that I
noticed while working on the fix. It essentially just adds a separate
attribute to the account class(?) that hold's the account's "real"
balance, which is only updated when the user attempts an assertion on a
real account. The virtual account's balance is updated the way it always
was.
Diffstat (limited to 'src/account.cc')
-rw-r--r-- | src/account.cc | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/account.cc b/src/account.cc index 29c28866..5f9f7f51 100644 --- a/src/account.cc +++ b/src/account.cc @@ -610,8 +610,10 @@ void account_t::clear_xdata() pair.second->clear_xdata(); } -value_t account_t::amount(const optional<expr_t&>& expr) const +value_t account_t::amount(const optional<bool> real_only, const optional<expr_t&>& expr) const { + DEBUG("account.amount", "real only: " << real_only); + if (xdata_ && xdata_->has_flags(ACCOUNT_EXT_VISITED)) { posts_list::const_iterator i; if (xdata_->self_details.last_post) @@ -622,6 +624,10 @@ value_t account_t::amount(const optional<expr_t&>& expr) const for (; i != posts.end(); i++) { if ((*i)->xdata().has_flags(POST_EXT_VISITED)) { if (! (*i)->xdata().has_flags(POST_EXT_CONSIDERED)) { + if (! (*i)->has_flags(POST_VIRTUAL)) { + (*i)->add_to_value(xdata_->self_details.real_total, expr); + } + (*i)->add_to_value(xdata_->self_details.total, expr); (*i)->xdata().add_flags(POST_EXT_CONSIDERED); } @@ -637,6 +643,10 @@ value_t account_t::amount(const optional<expr_t&>& expr) const for (; i != xdata_->reported_posts.end(); i++) { if ((*i)->xdata().has_flags(POST_EXT_VISITED)) { if (! (*i)->xdata().has_flags(POST_EXT_CONSIDERED)) { + if (! (*i)->has_flags(POST_VIRTUAL)) { + (*i)->add_to_value(xdata_->self_details.real_total, expr); + } + (*i)->add_to_value(xdata_->self_details.total, expr); (*i)->xdata().add_flags(POST_EXT_CONSIDERED); } @@ -644,7 +654,11 @@ value_t account_t::amount(const optional<expr_t&>& expr) const xdata_->self_details.last_reported_post = i; } - return xdata_->self_details.total; + if (real_only == true) { + return xdata_->self_details.real_total; + } else { + return xdata_->self_details.total; + } } else { return NULL_VALUE; } @@ -662,7 +676,7 @@ value_t account_t::total(const optional<expr_t&>& expr) const add_or_set_value(xdata_->family_details.total, temp); } - temp = amount(expr); + temp = amount(false, expr); if (! temp.is_null()) add_or_set_value(xdata_->family_details.total, temp); } |