diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-05 14:27:58 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-05 14:27:58 -0500 |
commit | 67ce33430c1f37f0fa7da62e5bd055c5a00b614d (patch) | |
tree | 3357a0a2fd100f8dbf65e01ae1272770852c3e23 /src | |
parent | 15555d497f56e4b4d39e9a14f74b2c82cce52b90 (diff) | |
parent | 09ace752d604d5afce698f7cc240e1a83cee934d (diff) | |
download | fork-ledger-67ce33430c1f37f0fa7da62e5bd055c5a00b614d.tar.gz fork-ledger-67ce33430c1f37f0fa7da62e5bd055c5a00b614d.tar.bz2 fork-ledger-67ce33430c1f37f0fa7da62e5bd055c5a00b614d.zip |
Merge branch 'next'
Diffstat (limited to 'src')
-rw-r--r-- | src/item.cc | 10 | ||||
-rw-r--r-- | src/post.cc | 6 | ||||
-rw-r--r-- | src/report.cc | 27 | ||||
-rw-r--r-- | src/report.h | 1 | ||||
-rw-r--r-- | src/value.cc | 2 |
5 files changed, 41 insertions, 5 deletions
diff --git a/src/item.cc b/src/item.cc index acef2e44..f60db226 100644 --- a/src/item.cc +++ b/src/item.cc @@ -212,23 +212,23 @@ namespace { else if (args[0].is_mask()) return item.has_tag(args[0].as_mask()); else - throw_(std::logic_error, - _("Expected string for argument 1, but received %1") + throw_(std::runtime_error, + _("Expected string or mask for argument 1, but received %1") << args[0].label()); } else if (args.size() == 2) { if (args[0].is_mask() && args[1].is_mask()) return item.has_tag(args[0].to_mask(), args[1].to_mask()); else - throw_(std::logic_error, + throw_(std::runtime_error, _("Expected masks for arguments 1 and 2, but received %1 and %2") << args[0].label() << args[1].label()); } else if (args.size() == 0) { - throw_(std::logic_error, _("Too few arguments to function")); + throw_(std::runtime_error, _("Too few arguments to function")); } else { - throw_(std::logic_error, _("Too many arguments to function")); + throw_(std::runtime_error, _("Too many arguments to function")); } return false; } diff --git a/src/post.cc b/src/post.cc index d7923866..4f45592f 100644 --- a/src/post.cc +++ b/src/post.cc @@ -160,6 +160,8 @@ namespace { value_t get_amount(post_t& post) { if (post.has_xdata() && post.xdata().has_flags(POST_EXT_COMPOUND)) return post.xdata().compound_value; + else if (post.amount.is_null()) + return 0L; else return post.amount; } @@ -186,6 +188,8 @@ namespace { else if (post.has_xdata() && post.xdata().has_flags(POST_EXT_COMPOUND)) return post.xdata().compound_value; + else if (post.amount.is_null()) + return 0L; else return post.amount; } @@ -193,6 +197,8 @@ namespace { value_t get_total(post_t& post) { if (post.xdata_ && ! post.xdata_->total.is_null()) return post.xdata_->total; + else if (post.amount.is_null()) + return 0L; else return post.amount; } diff --git a/src/report.cc b/src/report.cc index e6f3ccb4..3b570682 100644 --- a/src/report.cc +++ b/src/report.cc @@ -313,6 +313,31 @@ value_t report_t::fn_price(call_scope_t& scope) return args.value_at(0).price(); } +value_t report_t::fn_account_total(call_scope_t& args) +{ + account_t * acct = NULL; + string name; + if (args[0].is_string()) { + name = args[0].as_string(); + acct = session.journal->find_account(name, false); + } + else if (args[0].is_mask()) { + name = args[0].as_mask().expr.str(); + acct = session.journal->find_account_re(name); + } + else { + throw_(std::runtime_error, + _("Expected string or mask for argument 1, but received %1") + << args[0].label()); + } + + if (! acct) + throw_(std::runtime_error, + _("Could not find an account matching ") << name); + + return acct->amount(); +} + value_t report_t::fn_lot_date(call_scope_t& scope) { interactive_t args(scope, "v"); @@ -730,6 +755,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, return MAKE_FUNCTOR(report_t::fn_ansify_if); else if (is_eq(p, "abs")) return MAKE_FUNCTOR(report_t::fn_abs); + else if (is_eq(p, "account_total")) + return MAKE_FUNCTOR(report_t::fn_account_total); break; case 'b': diff --git a/src/report.h b/src/report.h index 32648648..431eac3c 100644 --- a/src/report.h +++ b/src/report.h @@ -160,6 +160,7 @@ public: value_t fn_ansify_if(call_scope_t& scope); value_t fn_percent(call_scope_t& scope); value_t fn_price(call_scope_t& scope); + value_t fn_account_total(call_scope_t& scope); value_t fn_lot_date(call_scope_t& scope); value_t fn_lot_price(call_scope_t& scope); value_t fn_lot_tag(call_scope_t& scope); diff --git a/src/value.cc b/src/value.cc index a3a05b6c..4529300a 100644 --- a/src/value.cc +++ b/src/value.cc @@ -983,6 +983,8 @@ void value_t::in_place_cast(type_t cast_type) if (type() == cast_type) return; + _dup(); + if (cast_type == BOOLEAN) { set_boolean(bool(*this)); return; |