summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-05-30 21:58:05 -0600
committerJohn Wiegley <johnw@newartisans.com>2010-05-30 21:58:05 -0600
commit654c842348c570a086f31cb79b7b3b4810463707 (patch)
tree846fb1a0f16f19af08c3c9a4ce035733b573e3e4
parent5a2644c1b7220dc96e4de9cfb82f6d829cf34321 (diff)
downloadfork-ledger-654c842348c570a086f31cb79b7b3b4810463707.tar.gz
fork-ledger-654c842348c570a086f31cb79b7b3b4810463707.tar.bz2
fork-ledger-654c842348c570a086f31cb79b7b3b4810463707.zip
-G option now takes price history into account
-rw-r--r--src/filters.cc56
-rw-r--r--test/baseline/opt-gain.test3
-rw-r--r--test/baseline/opt-price.test3
3 files changed, 56 insertions, 6 deletions
diff --git a/src/filters.cc b/src/filters.cc
index bca8516e..41e8c16b 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -582,20 +582,68 @@ void changed_value_posts::output_intermediate_prices(post_t& post,
// date. If so, generate an output_revaluation for that price change.
// Mostly this is only going to occur if the user has a series of pricing
// entries, since a posting-based revaluation would be seen here as a post.
- assert(! last_total.is_null());
- switch (last_total.type()) {
+ value_t display_total(last_total);
+
+ if (display_total.type() == value_t::SEQUENCE) {
+ xact_t& xact(temps.create_xact());
+
+ xact.payee = _("Commodities revalued");
+ xact._date = is_valid(current) ? current : post.date();
+
+ post_t& temp(temps.copy_post(post, xact));
+ temp.add_flags(ITEM_GENERATED);
+
+ post_t::xdata_t& xdata(temp.xdata());
+ if (is_valid(current))
+ xdata.date = current;
+
+ DEBUG("filters.revalued", "intermediate last_total = " << last_total);
+
+ switch (last_total.type()) {
+ case value_t::BOOLEAN:
+ case value_t::INTEGER:
+ last_total.in_place_cast(value_t::AMOUNT);
+ // fall through...
+
+ case value_t::AMOUNT:
+ temp.amount = last_total.as_amount();
+ break;
+
+ case value_t::BALANCE:
+ case value_t::SEQUENCE:
+ xdata.compound_value = last_total;
+ xdata.add_flags(POST_EXT_COMPOUND);
+ break;
+
+ case value_t::DATETIME:
+ case value_t::DATE:
+ default:
+ assert(false);
+ break;
+ }
+
+ bind_scope_t inner_scope(report, temp);
+ display_total = display_total_expr.calc(inner_scope);
+
+ DEBUG("filters.revalued", "intermediate display_total = " << display_total);
+ }
+
+ switch (display_total.type()) {
+ case value_t::VOID:
case value_t::INTEGER:
case value_t::SEQUENCE:
break;
+
case value_t::AMOUNT:
- last_total.in_place_cast(value_t::BALANCE);
+ display_total.in_place_cast(value_t::BALANCE);
// fall through...
+
case value_t::BALANCE: {
commodity_t::history_map all_prices;
foreach (const balance_t::amounts_map::value_type& amt_comm,
- last_total.as_balance().amounts) {
+ display_total.as_balance().amounts) {
if (optional<commodity_t::varied_history_t&> hist =
amt_comm.first->varied_history()) {
foreach
diff --git a/test/baseline/opt-gain.test b/test/baseline/opt-gain.test
index 8aeb8bab..63055d5f 100644
--- a/test/baseline/opt-gain.test
+++ b/test/baseline/opt-gain.test
@@ -50,7 +50,8 @@ P 2010/03/01 00:00:00 S 8 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-Jan-15 Commodities revalued <Revalued> 100 P 100 P
+09-Feb-01 Commodities revalued <Revalued> 200 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
diff --git a/test/baseline/opt-price.test b/test/baseline/opt-price.test
index bf302264..133b2155 100644
--- a/test/baseline/opt-price.test
+++ b/test/baseline/opt-price.test
@@ -37,7 +37,8 @@ reg --end 2009/06/26 -G equities
08-Jan-01 Purchase Apple shares Equities 0 0
08-Jun-30 Commodities revalued <Revalued> $500 $500
08-Jun-30 Sell some Apple sha.. Equities 0 $500
-09-Jun-26 Commodities revalued <Revalued> $750 $1250
+09-Jan-31 Commodities revalued <Revalued> $250 $750
+09-Jun-26 Commodities revalued <Revalued> $500 $1250
>>>2
=== 0
reg -I equities