summaryrefslogtreecommitdiff
path: root/src/commodity.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-06-16 16:23:58 +0100
committerJohn Wiegley <johnw@newartisans.com>2009-06-16 16:23:58 +0100
commit463f741ed247f7486a5bdce8a331281887f476fe (patch)
treef015127bfd65371efcdbf715716bae8dfd5f732e /src/commodity.cc
parent3c692a94d42349e6f0d40ec8341f6fd4d6052a6e (diff)
downloadfork-ledger-463f741ed247f7486a5bdce8a331281887f476fe.tar.gz
fork-ledger-463f741ed247f7486a5bdce8a331281887f476fe.tar.bz2
fork-ledger-463f741ed247f7486a5bdce8a331281887f476fe.zip
Allow an amount to be zero, even if cost is non-zero
The only real change is that exchanges of zero-amount will not result in any exchange at all, just the "motions". Fixes 6DAB9FE3-1399-4727-9AB1-FE413FB85A03
Diffstat (limited to 'src/commodity.cc')
-rw-r--r--src/commodity.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/commodity.cc b/src/commodity.cc
index 67a86b87..d826feb6 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -418,11 +418,13 @@ commodity_t::exchange(const amount_t& amount,
if (commodity.annotated)
current_annotation = &as_annotated_commodity(commodity).details;
- amount_t per_unit_cost = (is_per_unit ? cost : cost / amount).abs();
+ amount_t per_unit_cost =
+ (is_per_unit || amount.is_realzero() ? cost : cost / amount).abs();
DEBUG("commodity.prices.add", "exchange: per-unit-cost = " << per_unit_cost);
- exchange(commodity, per_unit_cost, moment ? *moment : CURRENT_TIME());
+ if (! per_unit_cost.is_realzero())
+ exchange(commodity, per_unit_cost, moment ? *moment : CURRENT_TIME());
cost_breakdown_t breakdown;
breakdown.final_cost = ! is_per_unit ? cost : cost * amount;