From 37b8b5e3373151a75e720161ce860cbce074da32 Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Mon, 14 Jul 2014 20:39:04 -0400 Subject: Preserve original cost basis when gain or loss is made Change the definition of cost: in the past, if you bought 1 AAA for $10 and then sold it for $12, ledger would take $12 as the cost. With the patch, the original cost of $10 is preserved ss the cost basis. In my opinion, this brings ledger in line with accounting expectations. This change fixes bugs #712 and #713. Bug #712 is about Equity:Capital Gains and Equity:Capital Loss entries ledger automatically generates that are in my opinion incorrect. Bug #713 is about strange behaviour with -B after a capital gain or loss is made. Patch from John Wiegley. --- src/xact.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/xact.cc b/src/xact.cc index eec4cff3..3e563714 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -304,10 +304,9 @@ bool xact_base_t::finalize() 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 0 account_t * account; if (gain_loss.sign() > 0) account = journal->find_account(_("Equity:Capital Gains")); @@ -321,6 +320,9 @@ bool xact_base_t::finalize() p->add_flags(post->flags() & (POST_VIRTUAL | POST_MUST_BALANCE)); } add_post(p); +#else + *post->cost += gain_loss; +#endif DEBUG("xact.finalize", "added gain_loss, balance = " << balance); } else { DEBUG("xact.finalize", "gain_loss would have displayed as zero"); -- cgit v1.2.3 From b88634206402814f63ba8db192e52d3e3bec2b38 Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Mon, 14 Jul 2014 21:05:54 -0400 Subject: Preserve the given cost for print Patch from John Wiegley --- src/post.h | 1 + src/print.cc | 6 +++--- src/textual.cc | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/post.h b/src/post.h index 51a75ade..c2f77b32 100644 --- a/src/post.h +++ b/src/post.h @@ -68,6 +68,7 @@ public: amount_t amount; // can be null until finalization optional amount_expr; optional cost; + optional given_cost; optional assigned_amount; optional checkin; optional checkout; diff --git a/src/print.cc b/src/print.cc index 9be3b511..54cfa578 100644 --- a/src/print.cc +++ b/src/print.cc @@ -243,7 +243,7 @@ namespace { amtbuf << string(2 - (slip + amt_slip), ' '); amtbuf << amt; - if (post->cost && + if (post->given_cost && ! post->has_flags(POST_CALCULATED | POST_COST_CALCULATED)) { std::string cost_op; if (post->has_flags(POST_COST_IN_FULL)) @@ -254,10 +254,10 @@ namespace { cost_op = "(" + cost_op + ")"; if (post->has_flags(POST_COST_IN_FULL)) - amtbuf << " " << cost_op << " " << post->cost->abs(); + amtbuf << " " << cost_op << " " << post->given_cost->abs(); else amtbuf << " " << cost_op << " " - << (*post->cost / post->amount).abs(); + << (*post->given_cost / post->amount).abs(); } if (post->assigned_amount) diff --git a/src/textual.cc b/src/textual.cc index eea79de0..156e2b9c 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -1578,6 +1578,8 @@ post_t * instance_t::parse_post(char * line, if (fixed_cost) post->add_flags(POST_COST_FIXATED); + post->given_cost = post->cost; + DEBUG("textual.parse", "line " << context.linenum << ": " << "Total cost is " << *post->cost); DEBUG("textual.parse", "line " << context.linenum << ": " -- cgit v1.2.3