From a87ed245d71d3737c6d56e7a829f361510fd53a6 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 13 Feb 2009 19:30:53 -0400 Subject: Changed the semantics of the "prices" report The prices report now uses the following scheme: PAYEE -> name of commodity of price ACCOUNT -> name of commodity of item AMOUNT -> price DATE -> date of pricing However, the report does not show the payee. The only reason the payee is set is to enable clever querying. For example: ledger prices gold # show all known prices for GOLD ledger prices @gold # show all known prices *in* GOLD --- src/iterators.cc | 30 ++++++++++++++++++++++-------- src/report.cc | 3 +-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/iterators.cc b/src/iterators.cc index ac5b2fc8..df3fd646 100644 --- a/src/iterators.cc +++ b/src/iterators.cc @@ -85,32 +85,46 @@ void xacts_commodities_iterator::reset(journal_t& journal) commodities.insert(&comm); } + std::map entries_by_commodity; + foreach (commodity_t * comm, commodities) { optional history = comm->varied_history(); if (! history) continue; - entry_temps.push_back(new entry_t); - entry_temps.back()->payee = comm->symbol(); - entry_temps.back()->_date = CURRENT_DATE(); + account_t * account = journal.master->find_account(comm->symbol()); foreach (commodity_t::base_t::history_by_commodity_map::value_type pair, history->histories) { commodity_t& price_comm(*pair.first); commodity_t::history_t& price_hist(pair.second); - acct_temps.push_back(account_t(NULL, price_comm.symbol())); - foreach (commodity_t::base_t::history_map::value_type hpair, price_hist.prices) { - xact_temps.push_back(xact_t(&acct_temps.back())); + entry_t * entry; + string symbol = hpair.second.commodity().symbol(); + + std::map::iterator i = + entries_by_commodity.find(symbol); + if (i != entries_by_commodity.end()) { + entry = (*i).second; + } else { + entry_temps.push_back(new entry_t); + entry = entry_temps.back(); + entry->payee = symbol; + entry->_date = hpair.first.date(); + entries_by_commodity.insert + (std::pair(symbol, entry)); + } + + xact_temps.push_back(xact_t(account)); xact_t& temp = xact_temps.back(); temp._date = hpair.first.date(); - temp.entry = entry_temps.back(); + temp.entry = entry; temp.amount = hpair.second; temp.set_flags(ITEM_GENERATED | ITEM_TEMP); - entry_temps.back()->add_xact(&temp); + entry->add_xact(&temp); } } } diff --git a/src/report.cc b/src/report.cc index 9227ee2c..e195a8c2 100644 --- a/src/report.cc +++ b/src/report.cc @@ -80,8 +80,7 @@ report_t::report_t(session_t& _session) HANDLER(plot_total_format_).on("%D %(S(T))\n"); HANDLER(prices_format_).on( - "%-.9(date) %-.10(payee) %-10(account) %12(strip(display_amount))\n%/" - "%21|%-.9(date) %-.10(payee) %-10(account) %12(strip(display_amount))\n"); + "%-.9(date) %-8(account) %12(strip(display_amount))\n"); HANDLER(pricesdb_format_).on("P %[%Y/%m/%d %H:%M:%S] %A %t\n"); HANDLER(csv_format_).on( -- cgit v1.2.3