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
This commit is contained in:
John Wiegley 2009-06-16 16:23:58 +01:00
parent 3c692a94d4
commit 463f741ed2
2 changed files with 14 additions and 2 deletions

View file

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

View file

@ -0,0 +1,10 @@
reg -E
<<<
2009/01/01 Sample
assets 0 FOO @ $8.88
equity
>>>1
09-Jan-01 Sample assets 0 0
equity 0 0
>>>2
=== 0