diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-19 13:34:15 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-19 13:34:15 -0400 |
commit | 627162acc0393aa8e9f4aaf45b52adab518aac4a (patch) | |
tree | 11ead53dedda228b1ae953735b7fad84f3f01c70 | |
parent | 6fd512cc117ebb61ced94f2d67f69ae5ed81b60b (diff) | |
download | fork-ledger-627162acc0393aa8e9f4aaf45b52adab518aac4a.tar.gz fork-ledger-627162acc0393aa8e9f4aaf45b52adab518aac4a.tar.bz2 fork-ledger-627162acc0393aa8e9f4aaf45b52adab518aac4a.zip |
Made amount_t::value a bit safer
-rw-r--r-- | src/amount.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/amount.cc b/src/amount.cc index 9817f464..a5c54ce6 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -743,21 +743,22 @@ amount_t::value(const optional<datetime_t>& moment, optional<price_point_t> point; optional<commodity_t&> comm(in_terms_of); - if (comm && commodity().referent() == comm->referent()) { - return *this; - } - else if (has_annotation() && annotation().price) { + if (has_annotation() && annotation().price) { if (annotation().has_flags(ANNOTATION_PRICE_FIXATED)) { point = price_point_t(); point->price = *annotation().price; } - else if (! in_terms_of) { + else if (! comm) { comm = annotation().price->commodity(); } } if (! point) { + if (comm && commodity().referent() == comm->referent()) + return *this; + point = commodity().find_price(comm, moment); + // Whether a price was found or not, check whether we should attempt // to download a price from the Internet. This is done if (a) no // price was found, or (b) the price is "stale" according to the |