summaryrefslogtreecommitdiff
path: root/src/commodity.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-22 04:43:34 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-22 04:51:11 -0400
commite124811d8a31292c06430815683b2e0fe87f7ceb (patch)
treee165b781aa87402980c3a47a5617794387e81494 /src/commodity.cc
parent04fd1ae24c3be6f9d3400c55bce90c3fd743e96b (diff)
downloadfork-ledger-e124811d8a31292c06430815683b2e0fe87f7ceb.tar.gz
fork-ledger-e124811d8a31292c06430815683b2e0fe87f7ceb.tar.bz2
fork-ledger-e124811d8a31292c06430815683b2e0fe87f7ceb.zip
Added --exchange (-x) option
This is like -V, except it lets you specify the goal commodity to report in terms of, for example: reg -x CAD
Diffstat (limited to 'src/commodity.cc')
-rw-r--r--src/commodity.cc27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/commodity.cc b/src/commodity.cc
index 2ab7612e..57e20891 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -33,10 +33,10 @@
namespace ledger {
-void commodity_t::base_t::history_t::add_price(const commodity_t& source,
- const datetime_t& date,
- const amount_t& price,
- const bool reflexive)
+void commodity_t::base_t::history_t::add_price(commodity_t& source,
+ const datetime_t& date,
+ const amount_t& price,
+ const bool reflexive)
{
DEBUG("commodity.prices",
"add_price to " << source << " : " << date << ", " << price);
@@ -50,10 +50,13 @@ void commodity_t::base_t::history_t::add_price(const commodity_t& source,
assert(result.second);
}
- if (reflexive && ! price.commodity().has_flags(COMMODITY_NOMARKET)) {
- amount_t inverse = price.inverted();
- inverse.set_commodity(const_cast<commodity_t&>(source));
- price.commodity().add_price(date, inverse, false);
+ if (reflexive) {
+ if (! price.commodity().has_flags(COMMODITY_NOMARKET)) {
+ amount_t inverse = price.inverted();
+ inverse.set_commodity(const_cast<commodity_t&>(source));
+ price.commodity().add_price(date, inverse, false);
+ }
+ source.add_flags(COMMODITY_PRIMARY);
}
}
@@ -68,10 +71,10 @@ bool commodity_t::base_t::history_t::remove_price(const datetime_t& date)
}
void commodity_t::base_t::varied_history_t::
- add_price(const commodity_t& source,
- const datetime_t& date,
- const amount_t& price,
- const bool reflexive)
+ add_price(commodity_t& source,
+ const datetime_t& date,
+ const amount_t& price,
+ const bool reflexive)
{
optional<history_t&> hist = history(price.commodity());
if (! hist) {