From 0018c884dbf228c54e30f0bc8b7586cc35c56b0f Mon Sep 17 00:00:00 2001 From: Daraul Date: Tue, 10 Mar 2020 13:38:43 -0400 Subject: 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. --- src/textual.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/textual.cc') diff --git a/src/textual.cc b/src/textual.cc index 4e24fd44..16054445 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -1633,7 +1633,7 @@ post_t * instance_t::parse_post(char * line, const amount_t& amt(*post->assigned_amount); value_t account_total - (post->account->amount().strip_annotations(keep_details_t())); + (post->account->amount(!post->has_flags(POST_VIRTUAL)).strip_annotations(keep_details_t())); DEBUG("post.assign", "line " << context.linenum << ": " << "account balance = " << account_total); @@ -1666,7 +1666,7 @@ post_t * instance_t::parse_post(char * line, // Subtract amounts from previous posts to this account in the xact. for (post_t* p : xact->posts) { - if (p->account == post->account) { + if (p->account == post->account && p->has_flags(POST_VIRTUAL) == post->has_flags(POST_VIRTUAL)) { diff -= p->amount; DEBUG("textual.parse", "line " << context.linenum << ": " << "Subtracting " << p->amount << ", diff = " << diff); -- cgit v1.2.3