diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-22 04:43:34 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-22 04:51:11 -0400 |
commit | e124811d8a31292c06430815683b2e0fe87f7ceb (patch) | |
tree | e165b781aa87402980c3a47a5617794387e81494 /src/amount.cc | |
parent | 04fd1ae24c3be6f9d3400c55bce90c3fd743e96b (diff) | |
download | fork-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/amount.cc')
-rw-r--r-- | src/amount.cc | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/amount.cc b/src/amount.cc index 6fc049b9..84e77f41 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -509,13 +509,19 @@ void amount_t::in_place_unreduce() } } -optional<amount_t> amount_t::value(const optional<datetime_t>& moment, - const optional<commodity_t&>& in_terms_of) const +optional<amount_t> +amount_t::value(const bool primary_only, + const optional<datetime_t>& moment, + const optional<commodity_t&>& in_terms_of) const { if (quantity) { - optional<price_point_t> point(commodity().find_price(in_terms_of, moment)); - if (point) - return (point->price * number()).rounded(); + if (has_commodity() && + (! primary_only || commodity().has_flags(COMMODITY_PRIMARY)) && + (! in_terms_of || commodity() != *in_terms_of)) { + optional<price_point_t> point(commodity().find_price(in_terms_of, moment)); + if (point) + return (point->price * number()).rounded(); + } } else { throw_(amount_error, "Cannot determine value of an uninitialized amount"); } |