summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-03-22 23:42:18 -0500
committerJohn Wiegley <johnw@newartisans.com>2012-03-22 23:42:18 -0500
commit5addacfbf21250204b8db25f0a4890c1299cb891 (patch)
tree9a4f9d35dd479cc8591a52d30c760f7f55758229
parent4e07084b0351f2ff75bbb960ff9b02b2f99e4b23 (diff)
downloadfork-ledger-5addacfbf21250204b8db25f0a4890c1299cb891.tar.gz
fork-ledger-5addacfbf21250204b8db25f0a4890c1299cb891.tar.bz2
fork-ledger-5addacfbf21250204b8db25f0a4890c1299cb891.zip
Fixed an interaction with equity and virtual accounts
Fixes #686
-rw-r--r--src/filters.cc20
-rw-r--r--src/filters.h17
-rw-r--r--test/regress/012ADB60.test24
3 files changed, 54 insertions, 7 deletions
diff --git a/src/filters.cc b/src/filters.cc
index 58e5fcaf..32b3ec3a 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -900,11 +900,19 @@ void subtotal_posts::operator()(post_t& post)
#if defined(DEBUG_ON)
std::pair<values_map::iterator, bool> result =
#endif
- values.insert(values_pair(acct->fullname(), acct_value_t(acct, temp)));
+ values.insert(values_pair
+ (acct->fullname(),
+ acct_value_t(acct, temp, post.has_flags(POST_VIRTUAL),
+ post.has_flags(POST_MUST_BALANCE))));
#if defined(DEBUG_ON)
assert(result.second);
#endif
} else {
+ if (post.has_flags(POST_VIRTUAL) != (*i).second.is_virtual)
+ throw_(std::logic_error,
+ _("'equity' cannot accept virtual and "
+ "non-virtual postings to the same account"));
+
post.add_to_value((*i).second.value, amount_expr);
}
@@ -1062,10 +1070,17 @@ void posts_as_equity::report_subtotal()
/* act_date_p= */ false);
}
}
- total += value;
+
+ if (! pair.second.is_virtual || pair.second.must_balance)
+ total += value;
}
values.clear();
+#if 1
+ // This last part isn't really needed, since an Equity:Opening
+ // Balances posting with a null amount will automatically balance with
+ // all the other postings generated. But it does make the full
+ // balancing amount clearer to the user.
if (! total.is_zero()) {
if (total.is_balance()) {
foreach (const balance_t::amounts_map::value_type& pair,
@@ -1082,6 +1097,7 @@ void posts_as_equity::report_subtotal()
(*handler)(balance_post);
}
}
+#endif
}
void by_payee_posts::flush()
diff --git a/src/filters.h b/src/filters.h
index ab226429..1dad8852 100644
--- a/src/filters.h
+++ b/src/filters.h
@@ -640,15 +640,22 @@ protected:
public:
account_t * account;
value_t value;
+ bool is_virtual;
+ bool must_balance;
- acct_value_t(account_t * a) : account(a) {
- TRACE_CTOR(acct_value_t, "account_t *");
+ acct_value_t(account_t * a, bool _is_virtual = false,
+ bool _must_balance = false)
+ : account(a), is_virtual(_is_virtual), must_balance(_must_balance) {
+ TRACE_CTOR(acct_value_t, "account_t *, bool, bool");
}
- acct_value_t(account_t * a, value_t& v) : account(a), value(v) {
- TRACE_CTOR(acct_value_t, "account_t *, value_t&");
+ acct_value_t(account_t * a, value_t& v, bool _is_virtual = false,
+ bool _must_balance = false)
+ : account(a), value(v), is_virtual(_is_virtual),
+ must_balance(_must_balance) {
+ TRACE_CTOR(acct_value_t, "account_t *, value_t&, bool, bool");
}
acct_value_t(const acct_value_t& av)
- : account(av.account), value(av.value) {
+ : account(av.account), value(av.value), is_virtual(av.is_virtual) {
TRACE_CTOR(acct_value_t, "copy");
}
~acct_value_t() throw() {
diff --git a/test/regress/012ADB60.test b/test/regress/012ADB60.test
new file mode 100644
index 00000000..443b9e5b
--- /dev/null
+++ b/test/regress/012ADB60.test
@@ -0,0 +1,24 @@
+2005/01/03 * Pay Credit card
+ Liabilities:CredCard $1,000.00 ; Electronic/ACH Debit
+ Assets:Current:Checking ; Electronic/ACH Debit
+ (Virtualaccount) $1,000.00
+
+2006/01/03 Gift shop
+ Expenses:Gifts $46.50
+ * Liabilities:CredCard
+
+2006/01/03 Bike shop
+ Expenses:Misc $199.00
+ * Liabilities:CredCard
+ (testvirtual) $184.72
+
+2006/01/04 Store
+ Expenses:Misc $49.95
+ * Liabilities:CredCard
+
+test equity -e 2006
+2005/01/03 Opening Balances
+ Assets:Current:Checking $-1,000.00
+ Liabilities:CredCard $1,000.00
+ (Virtualaccount) $1,000.00
+end test