summaryrefslogtreecommitdiff
path: root/src/xact.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-12 21:43:03 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-13 01:03:48 -0400
commit6ef755c1330c6e11476ea2e63b8388ad29efb4ef (patch)
treead006748fff38a2748087514908ef370495ec791 /src/xact.cc
parent6f56a7443fea165c73d00029437530d567556994 (diff)
downloadfork-ledger-6ef755c1330c6e11476ea2e63b8388ad29efb4ef.tar.gz
fork-ledger-6ef755c1330c6e11476ea2e63b8388ad29efb4ef.tar.bz2
fork-ledger-6ef755c1330c6e11476ea2e63b8388ad29efb4ef.zip
Added support for assert, check and expr directives
These can occur in many places: ; Within an automated transaction, the assert is evaluated every time ; a posting is matched, with the expression context set to the ; matching posting. = /Food/ assert account("Expenses:Food").total >= $100 2010-06-12 Sample Expenses:Food $100 Assets:Checking ; At file scope, the expression is evaluated with "global" scope. assert account("Expenses:Food").total == $100 ; At the top of a transction, the assertion's scope is the ; transaction. After a posting, the scope is that posting. Note ; however that account totals are only adjusted after successful ; parsing of a transaction, which means that all the assertions below ; are true, even though it appears as though the middle posting should ; affect the total immediately (which is not the case). 2010-06-12 Sample 2 assert account("Expenses:Food").total == $100 Expenses:Food $50 assert account("Expenses:Food").total == $100 Assets:Checking assert account("Expenses:Food").total == $100
Diffstat (limited to 'src/xact.cc')
-rw-r--r--src/xact.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/xact.cc b/src/xact.cc
index eeb487d9..0bf1fc2c 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -691,6 +691,21 @@ void auto_xact_t::extend_xact(xact_base_t& xact,
current_year);
}
}
+ if (check_exprs) {
+ foreach (check_expr_pair& pair, *check_exprs) {
+ if (pair.second == auto_xact_t::EXPR_GENERAL) {
+ pair.first.calc(bound_scope);
+ }
+ else if (! pair.first.calc(bound_scope).to_boolean()) {
+ if (pair.second == auto_xact_t::EXPR_ASSERTION) {
+ throw_(parse_error,
+ _("Transaction assertion failed: %1" << pair.first));
+ } else {
+ warning_(_("Transaction check failed: %1" << pair.first));
+ }
+ }
+ }
+ }
foreach (post_t * post, posts) {
amount_t post_amount;