summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/xact.cc18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/xact.cc b/src/xact.cc
index eebe4be9..d943e611 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -187,7 +187,7 @@ bool xact_base_t::finalize()
post_t * top_post = NULL;
foreach (post_t * post, posts) {
- if (! post->amount.is_null()) {
+ if (! post->amount.is_null() && post->must_balance()) {
if (post->amount.has_annotation())
top_post = post;
else if (! top_post)
@@ -220,9 +220,10 @@ bool xact_base_t::finalize()
DEBUG("xact.finalize", "primary amount = " << *x);
DEBUG("xact.finalize", "secondary amount = " << *y);
- commodity_t& comm(x->commodity());
- amount_t per_unit_cost;
- amount_t total_cost;
+ commodity_t& comm(x->commodity());
+ amount_t per_unit_cost;
+ amount_t total_cost;
+ const amount_t * prev_y = y;
foreach (post_t * post, posts) {
if (post != top_post && post->must_balance() &&
@@ -233,9 +234,16 @@ bool xact_base_t::finalize()
if (total_cost.is_null()) {
total_cost = temp;
y = &total_cost;
- } else {
+ }
+ else if (total_cost.commodity() == temp.commodity()) {
total_cost += temp;
}
+ else {
+ DEBUG("xact.finalize",
+ "multiple price commodities, aborting price calc");
+ y = prev_y;
+ break;
+ }
DEBUG("xact.finalize", "total_cost = " << total_cost);
}
}