diff options
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"); } |