Cost of a post with neg. amount should be negative
This commit is contained in:
parent
6d0ab845ea
commit
f1a2a5a18d
3 changed files with 8 additions and 2 deletions
|
|
@ -458,6 +458,9 @@ xact_t * draft_t::insert(journal_t& journal)
|
||||||
*post.cost *= new_post->amount;
|
*post.cost *= new_post->amount;
|
||||||
post.cost->set_commodity(cost_commodity);
|
post.cost->set_commodity(cost_commodity);
|
||||||
}
|
}
|
||||||
|
else if (new_post->amount.sign() < 0) {
|
||||||
|
new_post->cost->in_place_negate();
|
||||||
|
}
|
||||||
|
|
||||||
new_post->cost = *post.cost;
|
new_post->cost = *post.cost;
|
||||||
DEBUG("derive.xact", "Copied over posting cost");
|
DEBUG("derive.xact", "Copied over posting cost");
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ commodity_pool_t::exchange(const amount_t& amount,
|
||||||
current_annotation = &as_annotated_commodity(commodity).details;
|
current_annotation = &as_annotated_commodity(commodity).details;
|
||||||
|
|
||||||
amount_t per_unit_cost =
|
amount_t per_unit_cost =
|
||||||
(is_per_unit || amount.is_realzero() ? cost : cost / amount).abs();
|
(is_per_unit || amount.is_realzero()) ? cost.abs() : (cost / amount).abs();
|
||||||
|
|
||||||
DEBUG("commodity.prices.add", "exchange: per-unit-cost = " << per_unit_cost);
|
DEBUG("commodity.prices.add", "exchange: per-unit-cost = " << per_unit_cost);
|
||||||
|
|
||||||
|
|
@ -255,7 +255,7 @@ commodity_pool_t::exchange(const amount_t& amount,
|
||||||
exchange(commodity, per_unit_cost, moment ? *moment : CURRENT_TIME());
|
exchange(commodity, per_unit_cost, moment ? *moment : CURRENT_TIME());
|
||||||
|
|
||||||
cost_breakdown_t breakdown;
|
cost_breakdown_t breakdown;
|
||||||
breakdown.final_cost = ! is_per_unit ? cost : cost * amount;
|
breakdown.final_cost = ! is_per_unit ? cost : cost * amount.abs();
|
||||||
|
|
||||||
DEBUG("commodity.prices.add",
|
DEBUG("commodity.prices.add",
|
||||||
"exchange: final-cost = " << breakdown.final_cost);
|
"exchange: final-cost = " << breakdown.final_cost);
|
||||||
|
|
|
||||||
|
|
@ -1050,6 +1050,9 @@ post_t * instance_t::parse_post(char * line,
|
||||||
*post->cost *= post->amount;
|
*post->cost *= post->amount;
|
||||||
post->cost->set_commodity(cost_commodity);
|
post->cost->set_commodity(cost_commodity);
|
||||||
}
|
}
|
||||||
|
else if (post->amount.sign() < 0) {
|
||||||
|
post->cost->in_place_negate();
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG("textual.parse", "line " << linenum << ": "
|
DEBUG("textual.parse", "line " << linenum << ": "
|
||||||
<< "Total cost is " << *post->cost);
|
<< "Total cost is " << *post->cost);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue