Made amount_t::value a bit safer

This commit is contained in:
John Wiegley 2010-06-19 13:34:15 -04:00
parent 6fd512cc11
commit 627162acc0

View file

@ -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