diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-23 15:47:09 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-23 15:47:09 -0400 |
commit | 4a43c221729abcc35bfc3b09925e4ba9d0246218 (patch) | |
tree | fd967496f7df24d7b52f34f9994a5e6ae6023245 | |
parent | f440fcd8b0420325af917448684e5029f9ab4380 (diff) | |
download | fork-ledger-4a43c221729abcc35bfc3b09925e4ba9d0246218.tar.gz fork-ledger-4a43c221729abcc35bfc3b09925e4ba9d0246218.tar.bz2 fork-ledger-4a43c221729abcc35bfc3b09925e4ba9d0246218.zip |
Restore the --gain option, for showing gain/loss
-rw-r--r-- | src/report.h | 20 | ||||
-rw-r--r-- | test/baseline/opt-gain.test | 66 |
2 files changed, 85 insertions, 1 deletions
diff --git a/src/report.h b/src/report.h index 57cef3c5..4f53e8ec 100644 --- a/src/report.h +++ b/src/report.h @@ -386,7 +386,25 @@ public: OPTION(report_t, flat); OPTION(report_t, forecast_while_); OPTION(report_t, format_); // -F - OPTION(report_t, gain); // -G + + OPTION_(report_t, gain, DO() { // -G + parent->HANDLER(revalued).on_only(); + parent->HANDLER(amount_).set_expr("(amount, cost)"); + // Since we are displaying the amounts of revalued transactions, they + // will end up being composite totals, and hence a pair of pairs. + parent->HANDLER(display_amount_) + .set_expr("is_seq(get_at(amount_expr, 0)) ?" + " get_at(get_at(amount_expr, 0), 0) :" + " market(get_at(amount_expr, 0), date, exchange) -" + " get_at(amount_expr, 1)"); + parent->HANDLER(revalued_total_) + .set_expr("(market(get_at(total_expr, 0), date, exchange), " + "get_at(total_expr, 1))"); + parent->HANDLER(display_total_) + .set_expr("market(get_at(total_expr, 0), date, exchange)" + " - get_at(total_expr, 1)"); + }); + OPTION(report_t, head_); OPTION_(report_t, invert, DO() { diff --git a/test/baseline/opt-gain.test b/test/baseline/opt-gain.test new file mode 100644 index 00000000..8aeb8bab --- /dev/null +++ b/test/baseline/opt-gain.test @@ -0,0 +1,66 @@ +reg --gain stocks +<<< +2009/01/01 Sample 1a + Assets:Brokerage:Stocks 100 S + Assets:Brokerage:Cash -100 P + +P 2009/01/15 00:00:00 S 2 P + +2009/02/01 Sample 2a + Assets:Brokerage:Stocks 100 S @ 1 P + Assets:Brokerage:Cash + +P 2009/02/01 00:00:00 S 4 P + +2009/03/01 Sample 3a + Assets:Brokerage:Stocks 100 S @@ 100 P + Assets:Brokerage:Cash + +P 2009/03/01 00:00:00 S 8 P + +2009/04/01 Sample 4a + Assets:Brokerage:Cash 100 P + Assets:Brokerage:Stocks -100 S {1 P} + +P 2009/04/01 00:00:00 S 16 P + +; In this usage case, the top amount is always secondary +; 2010/01/01 Sample 1b +; Assets:Brokerage:Cash -100 P +; Assets:Brokerage:Stocks 100 S +; +; P 2010/01/01 00:00:00 S 2 P + +2010/02/01 Sample 2b + Assets:Brokerage:Cash + Assets:Brokerage:Stocks 100 S @ 1 P + +P 2010/02/01 00:00:00 S 4 P + +2010/03/01 Sample 3b + Assets:Brokerage:Cash + Assets:Brokerage:Stocks 100 S @@ 100 P + +P 2010/03/01 00:00:00 S 8 P + +2010/04/01 Sample 4b + Assets:Brokerage:Stocks -100 S {1 P} + Assets:Brokerage:Cash 100 P + +P 2010/04/01 00:00:00 S 16 P +>>>1 +09-Jan-01 Sample 1a As:Brokerage:Stocks 0 0 +09-Feb-01 Commodities revalued <Revalued> 300 P 300 P +09-Feb-01 Sample 2a As:Brokerage:Stocks 300 P 600 P +09-Mar-01 Commodities revalued <Revalued> 800 P 1400 P +09-Mar-01 Sample 3a As:Brokerage:Stocks 700 P 2100 P +09-Apr-01 Commodities revalued <Revalued> 2400 P 4500 P +09-Apr-01 Sample 4a As:Brokerage:Stocks -1500 P 3000 P +10-Feb-01 Commodities revalued <Revalued> -2400 P 600 P +10-Feb-01 Sample 2b As:Brokerage:Stocks 300 P 900 P +10-Mar-01 Commodities revalued <Revalued> 1200 P 2100 P +10-Mar-01 Sample 3b As:Brokerage:Stocks 700 P 2800 P +10-Apr-01 Commodities revalued <Revalued> 3200 P 6000 P +10-Apr-01 Sample 4b As:Brokerage:Stocks -1500 P 4500 P +>>>2 +=== 0 |