Don't do cost finalization for auto/period xacts
This commit is contained in:
parent
205dd3a1ee
commit
1f3dba7756
1 changed files with 47 additions and 45 deletions
92
src/xact.cc
92
src/xact.cc
|
|
@ -269,63 +269,65 @@ bool xact_base_t::finalize()
|
|||
|
||||
posts_list copy(posts);
|
||||
|
||||
foreach (post_t * post, copy) {
|
||||
if (! post->cost)
|
||||
continue;
|
||||
if (has_date()) {
|
||||
foreach (post_t * post, copy) {
|
||||
if (! post->cost)
|
||||
continue;
|
||||
|
||||
if (post->amount.commodity() == post->cost->commodity())
|
||||
throw_(balance_error,
|
||||
_("A posting's cost must be of a different commodity than its amount"));
|
||||
if (post->amount.commodity() == post->cost->commodity())
|
||||
throw_(balance_error,
|
||||
_("A posting's cost must be of a different commodity than its amount"));
|
||||
|
||||
cost_breakdown_t breakdown =
|
||||
commodity_pool_t::current_pool->exchange
|
||||
cost_breakdown_t breakdown =
|
||||
commodity_pool_t::current_pool->exchange
|
||||
(post->amount, *post->cost, false,
|
||||
datetime_t(date(), time_duration(0, 0, 0, 0)));
|
||||
|
||||
if (post->amount.has_annotation() && post->amount.annotation().price) {
|
||||
if (breakdown.basis_cost.commodity() == breakdown.final_cost.commodity()) {
|
||||
if (amount_t gain_loss = breakdown.basis_cost - breakdown.final_cost) {
|
||||
DEBUG("xact.finalize", "gain_loss = " << gain_loss);
|
||||
gain_loss.in_place_round();
|
||||
DEBUG("xact.finalize", "gain_loss rounds to = " << gain_loss);
|
||||
if (post->amount.has_annotation() && post->amount.annotation().price) {
|
||||
if (breakdown.basis_cost.commodity() == breakdown.final_cost.commodity()) {
|
||||
if (amount_t gain_loss = breakdown.basis_cost - breakdown.final_cost) {
|
||||
DEBUG("xact.finalize", "gain_loss = " << gain_loss);
|
||||
gain_loss.in_place_round();
|
||||
DEBUG("xact.finalize", "gain_loss rounds to = " << gain_loss);
|
||||
|
||||
if (post->must_balance())
|
||||
add_or_set_value(balance, gain_loss.reduced());
|
||||
if (post->must_balance())
|
||||
add_or_set_value(balance, gain_loss.reduced());
|
||||
|
||||
account_t * account;
|
||||
if (gain_loss.sign() > 0)
|
||||
account = journal->find_account(_("Equity:Capital Gains"));
|
||||
else
|
||||
account = journal->find_account(_("Equity:Capital Losses"));
|
||||
account_t * account;
|
||||
if (gain_loss.sign() > 0)
|
||||
account = journal->find_account(_("Equity:Capital Gains"));
|
||||
else
|
||||
account = journal->find_account(_("Equity:Capital Losses"));
|
||||
|
||||
post_t * p = new post_t(account, gain_loss, ITEM_GENERATED);
|
||||
p->set_state(post->state());
|
||||
if (post->has_flags(POST_VIRTUAL)) {
|
||||
DEBUG("xact.finalize", "gain_loss came from a virtual post");
|
||||
p->add_flags(post->flags() & (POST_VIRTUAL | POST_MUST_BALANCE));
|
||||
post_t * p = new post_t(account, gain_loss, ITEM_GENERATED);
|
||||
p->set_state(post->state());
|
||||
if (post->has_flags(POST_VIRTUAL)) {
|
||||
DEBUG("xact.finalize", "gain_loss came from a virtual post");
|
||||
p->add_flags(post->flags() & (POST_VIRTUAL | POST_MUST_BALANCE));
|
||||
}
|
||||
add_post(p);
|
||||
DEBUG("xact.finalize", "added gain_loss, balance = " << balance);
|
||||
} else {
|
||||
DEBUG("xact.finalize", "gain_loss would have displayed as zero");
|
||||
}
|
||||
add_post(p);
|
||||
DEBUG("xact.finalize", "added gain_loss, balance = " << balance);
|
||||
} else {
|
||||
DEBUG("xact.finalize", "gain_loss would have displayed as zero");
|
||||
}
|
||||
} else {
|
||||
if (post->amount.has_annotation()) {
|
||||
if (breakdown.amount.has_annotation())
|
||||
breakdown.amount.annotation().tag = post->amount.annotation().tag;
|
||||
else
|
||||
breakdown.amount.annotate
|
||||
(annotation_t(none, none, post->amount.annotation().tag));
|
||||
}
|
||||
post->amount = breakdown.amount;
|
||||
DEBUG("xact.finalize", "added breakdown, balance = " << balance);
|
||||
}
|
||||
} else {
|
||||
if (post->amount.has_annotation()) {
|
||||
if (breakdown.amount.has_annotation())
|
||||
breakdown.amount.annotation().tag = post->amount.annotation().tag;
|
||||
else
|
||||
breakdown.amount.annotate
|
||||
(annotation_t(none, none, post->amount.annotation().tag));
|
||||
}
|
||||
post->amount = breakdown.amount;
|
||||
DEBUG("xact.finalize", "added breakdown, balance = " << balance);
|
||||
}
|
||||
|
||||
if (post->has_flags(POST_COST_FIXATED) &&
|
||||
post->amount.has_annotation() && post->amount.annotation().price) {
|
||||
DEBUG("xact.finalize", "fixating annotation price");
|
||||
post->amount.annotation().add_flags(ANNOTATION_PRICE_FIXATED);
|
||||
if (post->has_flags(POST_COST_FIXATED) &&
|
||||
post->amount.has_annotation() && post->amount.annotation().price) {
|
||||
DEBUG("xact.finalize", "fixating annotation price");
|
||||
post->amount.annotation().add_flags(ANNOTATION_PRICE_FIXATED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue