summaryrefslogtreecommitdiff
path: root/src/amount.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-22 22:22:07 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-22 22:23:02 -0400
commitde6de07bac1337b0dd87b41c853369dc8432c2af (patch)
tree7a03ec320c4c359d3ca16c163badb797f96b92ee /src/amount.cc
parentea418c7fbcd54d7222583914477d087fe7d6c5e8 (diff)
downloadfork-ledger-de6de07bac1337b0dd87b41c853369dc8432c2af.tar.gz
fork-ledger-de6de07bac1337b0dd87b41c853369dc8432c2af.tar.bz2
fork-ledger-de6de07bac1337b0dd87b41c853369dc8432c2af.zip
Many fixes to --market and --exchange
Also, --exchange now accepted multiple, comma-separated commodities.
Diffstat (limited to 'src/amount.cc')
-rw-r--r--src/amount.cc23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/amount.cc b/src/amount.cc
index 84e77f41..dde1f96c 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -515,12 +515,25 @@ amount_t::value(const bool primary_only,
const optional<commodity_t&>& in_terms_of) const
{
if (quantity) {
+#if defined(DEBUG_ON)
+ DEBUG("commodity.prices.find",
+ "amount_t::value of " << commodity().symbol());
+ if (moment)
+ DEBUG("commodity.prices.find",
+ "amount_t::value: moment = " << *moment);
+ if (in_terms_of)
+ DEBUG("commodity.prices.find",
+ "amount_t::value: in_terms_of = " << in_terms_of->symbol());
+#endif
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)
+ (! primary_only || ! commodity().has_flags(COMMODITY_PRIMARY))) {
+ if (in_terms_of && commodity() == *in_terms_of) {
+ return *this;
+ }
+ else if (optional<price_point_t> point =
+ commodity().find_price(in_terms_of, moment)) {
return (point->price * number()).rounded();
+ }
}
} else {
throw_(amount_error, "Cannot determine value of an uninitialized amount");
@@ -996,7 +1009,7 @@ void amount_t::print(std::ostream& _out) const
if (comm.annotated) {
annotated_commodity_t& ann(static_cast<annotated_commodity_t&>(comm));
- assert(&*ann.details.price != this);
+ assert(! ann.details.price || &*ann.details.price != this);
ann.write_annotations(out);
}