Bug 240914 - A stock account with stock split cannot be closed
Summary: A stock account with stock split cannot be closed
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-06 17:48 UTC by Jan
Modified: 2010-06-21 10:48 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
example KMY file (4.46 KB, application/octet-stream)
2010-06-08 01:06 UTC, Jan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan 2010-06-06 17:48:03 UTC
Version:           unspecified
OS:                Linux

A stock account containing a stock split cannot be closed even if its balance is zero and it is not referenced in any other account.  The problem does not always occur, but one case where it does is when transactions are entered after th stock split was defined.

Reproducible: Didn't try

Steps to Reproduce:
1. Create an investment ABC
2. Create a Buy of 1 share on 02/01/2010 for EUR 100
   Create a Split of 1/5 on 02/02/2010
   Create a Sell of 5 shares on 02/03/2010 for EUR 95
3. Go to Accounts and check that you can close ABC (do not close)
4. Create a Buy of 1 share of ABC on 01/31/2010 for EUR 95
   Create a Sell of 5 shares on 02/03/2010 for EUR 100
5. Go to Accounts and try to close ABC

Actual Results:  
The accounts list shows a zero balance for ABC, yet it cannot be closed.

Expected Results:  
It should be possible to close the stock.
Comment 1 Jan 2010-06-06 17:50:50 UTC
This is reproducible, but I was able to close stock accounts in a new KMM session that I was unable to close before.
Comment 2 Alvaro Soliverez 2010-06-06 19:17:16 UTC
There is nothing in the code that checks for splits before allowing to close an account.
We would need a test file or an anonymized file to check what's really going on.
Comment 3 Jan 2010-06-08 00:47:11 UTC
Alvaro,


> There is nothing in the code that checks for splits before allowing to
close an
> account.

Thanks for looking into this.  Did you try my example?

> We would need a test file or an anonymized file to check what's really
going
> on.

I will try to prepare this.

Jan
Comment 4 Jan 2010-06-08 01:06:51 UTC
Created attachment 47799 [details]
example KMY file
Comment 5 Jan 2010-06-08 01:09:05 UTC
I tried my example in a new KMY file and was able to reproduce the problem.  However, after leaving and re-entering KMM, I was able to close it.  So, I backed up the file (see attachment above), added a new BUY and SELL as in the example of comment #1, and again the "Close account" option for ABC was grayed out.
Comment 6 Jan 2010-06-10 12:39:12 UTC
Since this operation is not a pure stock split but a reshuffling after a Merger/Acquisition, I have replaced the Split by consecutive Remove/Add Shares operations.
Comment 7 Alvaro Soliverez 2010-06-10 12:51:25 UTC
The only place I can find where the investment_delete action is enabled is on slotUpdateActions()

  if (!d->m_selectedInvestment.id().isEmpty()) {
    action("investment_edit")->setEnabled(true);
   action("investment_delete")->setEnabled(!file->isReferenced(d->m_selectedInvestment));

I'll check the test file later.
Comment 8 Jan 2010-06-10 14:38:32 UTC
Alvaro,


> The only place I can find where the investment_delete action is enabled is
on
> slotUpdateActions()

Thanks for your help.  I have not installed the source code, but am more and
more tempted to do so.  It would certainly help save your time.
As I mentioned on the bulletin, I got rid of the issue by replacing the
"Split Shares" by a "Remove Shares" of the old quantity, followed by an "Add
Shares" of the new quantity.  This does allow me to close the stock account,
and it is probably a better way of representing a share reshuffle after a
company merger anyway.  In fact, I probably should have closed the old stock
and created a new one on top of that.

Jan
Comment 9 Alvaro Soliverez 2010-06-10 14:46:31 UTC
Sorry, the previous message was not meant for you but as a reference for other developers more skilled in the working of the file engine. There is no need for you to dive into the code, although you are welcome to do so if you want to.

The problem seems to be somewhere deep down in an area of the code of the code which I'm not really familiar with, other than by hearsay, so I added the comment to help triaging the bug for the right guys.
Comment 10 Alvaro Soliverez 2010-06-11 05:55:52 UTC
The problem seems to be somewhere in the split transaction. 

I used the test file and entered a new split for ABC stock. After entering this split, the balance is miscalculated starting with the first split. Therefore, the balance is not zero, and the account can't be closed.
Comment 11 Thomas Baumgart 2010-06-21 10:48:50 UTC
SVN commit 1140640 by tbaumgart:

Simply adjusting the account balance by the share value does not work in case of stock splits. So the balance will always be recalculated for stock accounts.

BUG: 240914

 M  +30 -15    mymoneyseqaccessmgr.cpp  
 M  +6 -0      mymoneyseqaccessmgr.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1140640