summaryrefslogtreecommitdiff
path: root/src/entry.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-09-14 19:38:44 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-09-14 19:38:44 -0400
commit7d1809cb15b1ebea4d96341ae0e5fc655487788a (patch)
treefa56bc87e3798b5529640075885271b8fa02f359 /src/entry.cc
parent0135c28049839c2db25351b8d8114f9f31649afc (diff)
downloadfork-ledger-7d1809cb15b1ebea4d96341ae0e5fc655487788a.tar.gz
fork-ledger-7d1809cb15b1ebea4d96341ae0e5fc655487788a.tar.bz2
fork-ledger-7d1809cb15b1ebea4d96341ae0e5fc655487788a.zip
Transactional assignments (i.e., confirmed balances) are working now.
Diffstat (limited to 'src/entry.cc')
-rw-r--r--src/entry.cc39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/entry.cc b/src/entry.cc
index 7cb4b926..a1cfa702 100644
--- a/src/entry.cc
+++ b/src/entry.cc
@@ -130,7 +130,7 @@ bool entry_base_t::finalize()
// :generatedp t))
// (add-xact entry null-xact)))
- if (journal && journal->basket && xacts.size() == 1) {
+ if (journal && journal->basket && xacts.size() == 1 && ! balance.is_null()) {
// jww (2008-07-24): Need to make the rest of the code aware of what to do
// when it sees a generated xact.
null_xact = new xact_t(journal->basket, XACT_GENERATED);
@@ -173,10 +173,14 @@ bool entry_base_t::finalize()
XACT_GENERATED));
}
}
- } else {
+ }
+ else if (balance.is_amount()) {
null_xact->amount = balance.as_amount().negate();
null_xact->add_flags(XACT_CALCULATED);
}
+ else if (! balance.is_null() && ! balance.is_realzero()) {
+ throw_(balance_error, "Entry does not balance");
+ }
balance = NULL_VALUE;
}
@@ -300,28 +304,37 @@ bool entry_base_t::finalize()
// (format-value balance :width 20)))
if (! balance.is_null()) {
- balance.round();
+ balance.in_place_round();
if (! balance.is_zero()) {
#if 0
- error * err =
- new balance_error("Entry does not balance",
- new entry_context(*this, "While balancing entry:"));
- err->context.push_front
- (new value_context(balance, "Unbalanced remainder is:"));
- throw err;
+ new entry_context(*this, "While balancing entry:");
#endif
+ add_error_context("Unbalanced remainder is: ");
+ add_error_context(value_context(balance));
+ throw_(balance_error, "Entry does not balance");
}
}
// Add the final calculated totals each to their related account
if (dynamic_cast<entry_t *>(this)) {
+ bool all_null = true;
foreach (xact_t * xact, xacts) {
- // jww (2008-08-09): For now, this feature only works for
- // non-specific commodities.
- add_or_set_value(xact->account->xdata().value,
- xact->amount.strip_annotations());
+ if (! xact->amount.is_null()) {
+ all_null = false;
+
+ // jww (2008-08-09): For now, this feature only works for
+ // non-specific commodities.
+ add_or_set_value(xact->account->xdata().value, xact->amount);
+
+ DEBUG("entry.finalize.totals",
+ "Total for " << xact->account->fullname() << " + "
+ << xact->amount.strip_annotations() << ": "
+ << xact->account->xdata().value.strip_annotations());
+ }
}
+ if (all_null)
+ return false; // ignore this entry completely
}
return true;