diff options
-rw-r--r-- | src/report.cc | 24 | ||||
-rw-r--r-- | src/report.h | 17 | ||||
-rw-r--r-- | test/baseline/opt-basis.test | 10 |
3 files changed, 44 insertions, 7 deletions
diff --git a/src/report.cc b/src/report.cc index 76f1df39..0a64abcc 100644 --- a/src/report.cc +++ b/src/report.cc @@ -56,16 +56,17 @@ void report_t::entry_report(xact_handler_ptr handler, entry_t& entry) void report_t::sum_all_accounts() { - expr_t& expr(HANDLER(amount_).expr); - expr.set_context(this); + expr_t& amount_expr(HANDLER(amount_).expr); + amount_expr.set_context(this); journal_xacts_iterator walker(*session.journal.get()); pass_down_xacts(chain_xact_handlers - (*this, xact_handler_ptr(new set_account_value(expr)), true), - walker); + (*this, xact_handler_ptr(new set_account_value(amount_expr)), + true), walker); - expr.mark_uncompiled(); // recompile, throw away xact_t bindings - session.master->calculate_sums(expr); + expr_t& account_amount_expr(HANDLER(account_amount_).expr); + account_amount_expr.set_context(this); + session.master->calculate_sums(account_amount_expr); } void report_t::accounts_report(acct_handler_ptr handler) @@ -143,6 +144,11 @@ value_t report_t::fn_strip(call_scope_t& args) return args[0].strip_annotations(what_to_keep()); } +value_t report_t::fn_rounded(call_scope_t& args) +{ + return args[0].rounded(); +} + value_t report_t::fn_quantity(call_scope_t& args) { return args[0].to_amount().number(); @@ -310,6 +316,7 @@ option_t<report_t> * report_t::lookup_option(const char * p) case 'a': OPT(abbrev_len_); else OPT(account_); + else OPT(account_amount_); else OPT(actual); else OPT(add_budget); else OPT(amount_); @@ -613,6 +620,11 @@ expr_t::ptr_op_t report_t::lookup(const string& name) return MAKE_FUNCTOR(report_t::fn_quantity); break; + case 'r': + if (is_eq(p, "rounded")) + return MAKE_FUNCTOR(report_t::fn_rounded); + break; + case 's': if (is_eq(p, "strip")) return MAKE_FUNCTOR(report_t::fn_strip); diff --git a/src/report.h b/src/report.h index 0e6f7dc6..7aa4bc42 100644 --- a/src/report.h +++ b/src/report.h @@ -135,6 +135,7 @@ public: value_t fn_market_value(call_scope_t& scope); value_t fn_strip(call_scope_t& scope); value_t fn_quantity(call_scope_t& scope); + value_t fn_rounded(call_scope_t& scope); value_t fn_truncate(call_scope_t& scope); value_t fn_print(call_scope_t& scope); value_t fn_quoted(call_scope_t& scope); @@ -183,6 +184,20 @@ public: CTOR(report_t, abbrev_len_) { on_with(2L); }); OPTION(report_t, account_); + OPTION__ + (report_t, account_amount_, + expr_t expr; + CTOR(report_t, account_amount_) { + set_expr("amount"); + } + void set_expr(const string& str) { + expr = str; + on(str); + } + DO_(args) { + set_expr(args[0].to_string()); + }); + OPTION_(report_t, actual, DO() { // -L parent->HANDLER(limit_).on("actual"); }); @@ -228,7 +243,7 @@ public: OPTION_(report_t, basis, DO() { // -B parent->HANDLER(revalued).off(); - parent->HANDLER(amount_).set_expr("cost"); + parent->HANDLER(amount_).set_expr("rounded(cost)"); }); OPTION_(report_t, begin_, DO_(args) { // -b diff --git a/test/baseline/opt-basis.test b/test/baseline/opt-basis.test new file mode 100644 index 00000000..2e1c13c0 --- /dev/null +++ b/test/baseline/opt-basis.test @@ -0,0 +1,10 @@ +bal --args-only --basis +<<< +2007/02/02 RD VMMXX + Assets:Investments:Vanguard:VMMXX 0.350 VMMXX @ $1.00 + Income:Dividends:Vanguard:VMMXX $-0.35 +>>>1 + $0.35 Assets:Investments:Vanguard:VMMXX + $-0.35 Income:Dividends:Vanguard:VMMXX +>>>2 +=== 0 |