Bug 322381 - Fees(taxes) are deducted twice from dividend amount after QIF import
Summary: Fees(taxes) are deducted twice from dividend amount after QIF import
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: general (show other bugs)
Version: 4.6.3
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-15 09:39 UTC by timothy
Modified: 2015-03-29 13:08 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.7.2
Sentry Crash Report:


Attachments
attachment-12660-0.html (9.70 KB, text/html)
2014-12-01 14:35 UTC, timothy
Details
attachment-16662-0.html (1.97 KB, text/html)
2014-12-01 16:21 UTC, timothy
Details
attachment-20946-0.html (2.16 KB, text/html)
2014-12-03 08:29 UTC, timothy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description timothy 2013-07-15 09:39:29 UTC
The QIF file contains a dividend amount and a fee/tax amount. When the QIF is imported into the investment  account the displayed amounts show a double deduction of the fees from the dividend.
QIF                                                             KMM (display after import)
dividend = 1150                                          dividend = 1000
fee = 150                                                    fee = 150
                                                                    total = 850 (this amount is recorded in the ledger, wrong!)

Reproducible: Always

Steps to Reproduce:
1.Open Investment account
2.Import QIF file with dividend transaction containing fees (actually dividend tax)
3.The incorrect dividend which has the fee deducted twice is recorded.
Actual Results:  
The Dividend is shown as net (the fee is deducted before display)
The Fee is displayed correctly.
The Total amount shows the net dividend less the fee again ie a double deduction of the fee from the dividend as recorded in the import QIF file

Expected Results:  
Asuming the dividend is the gross dividend (including the fee) the dividend amount should display as the gross amount, the fee should display as the fee, and the total amount which gets put into the ledger should be net (gross dividend minus fee/tax). This is the actual money recieived.

I am running KMM 4.6.3 Using KDE 4.8.5 on Mint 13.
--------------------------------------------------------------
QIF FILE
!Account
NJSE-Shares:XYZ Shares
TInvst
^
!Type:Invst
D03/06/2013
YABSA Group Ltd
NDivX
MDividend Payment
L[Bank Accounts:Barclays Cheque]
T1150.0
O150.0
^
--------------------------------------------------------
SUPPORTING INFORMATION AS DISCUSSED ON THE LIST
> > > I am importing a dividend (DivX) via a QIF file into an investment
> > > account to be transferred to a cheque account. The QIF file has
> > > the dividend amount (T) as 1150.00 and the fees/commission (O) as
> > > 150.00.
> > > 
> > > After import KMM shows the fees as 150.00, the dividend as
> > > 1000.00 and the total as 850.00. The net dividend amount is
> > > displayed in the ledger as 850.00 which is 300 less than the QIF
> > > amount.
> > > 
> > > If I make the fees negative -150, the amounts are added twice and
> > > the total amount of 1450 is shown.
> > > 
> > > The only way to get the correct amounts is to enter a bogus
> > > dividend of 1300 in the QIF which is then subtracted twice and
> > > 1000 is then shown as the net net amount in the ledger.
> > > 
> > > I tried to get a QIF output file from Allan's CSV-plugin with no
> > > success as I am not sure of the content of the input CSV file,
> > > but I would be interested to know whether the same code is used
> > > for the import in the plugin and how the fees are handled there.
> > > 
> > > Is this a bug or am I doing something wrong?
> > > 
> > > Regards
> > > Timothy
> > > 
> > 
> > Hi Timothy
> > 
> > I wouldn't waste time trying to produce a QIF file via the CSV
> > plugin. It's now really there for historical reasons and because I
> > haven't had time to remove it.
> > 
> > However, if you attempted to use the plugin, did you try to follow
> > through to complete the import?
> > 
> > However, if you already have a QIF file, then that needs to be made
> > to work.  To be sure I try to do what you tried, can you send me
> > your QIF file direct, with any private info disguised.
> > 
> > Allan
> > 
> Hi Allan
> 
> No, I was more interested in comparing your QIF with mine to see how
> you handled the fees and whether you used the net or gross dividend.
> 
> Anyway here is the QIF I am using.
> 
> Regards
> Timothy
> 

Yes, that does not look right.  Would you raise a bug at
https://bugs.kde.org/ so it doesn't get forgotten.

Allan
Comment 1 timothy 2014-12-01 08:06:35 UTC
> > On Sun, 2014-11-30 at 13:13 +0000, Allan wrote:
> >> Hi Timothy
> >>
> >> On 30/11/14 12:18, timothy wrote:
> >>> Hi
> >>>
> >>> Could you please give me the sign convention for QIF investment format
> >>> expected by Kymoney. ie Should the QIF file show positive or negative
> >>> numbers.
> >>
> >> In general, the sign is taken care of in the activity type.  That
> >> is,both a Buy and a Sell expect no sign.  Similarly, a Div and a Fee
> >> will be expected to be  with no sign.
> >>
> >>> Specifically in the DIVX file for the Amount (T) and the Fees (O).
> >>>
> >>> Things seem to have changed since I last imported a Dividend?
> >>
> >> Well, that might depend on when you last imported a Dividend!  The
> >> general case has not changed.  However, there may well have been some
> >> minor changes, to cater for certain activity types previously not
> >> expecting say, a fee, but which some users wished otherwise.
> >>
> >> If that doesn't help, the best thing might be to give us an example
> >> which is not doing what you expect/expected.
> >>
> >> Allan
> >
> > Thanks Alan. Could you also please specify whether the amount (T) is
> > expected net of fees (O) or inclusive of the fees.
> >
> > In KMM it appears that when amount and fees are positive or no sign, the
> > the fees are being subtracted from the QIF file amount to give the KMM
> > "Interest Amount" and then subtracted again to give the "Total Amount".
> > The sign of the amount or interest is then changed to negative.
> >
> > Example
> > The QIF file gives
> > !Type:Invst
> > D15/09/2014
> > NDIVX
> > T1853.00  \\ This is net of fees being the amount received by me
> > O327.00   \\ These are the fees as taken off by broker. The total
> >               dividend declared should be T+O
> >
> > After manual import KMM gives
> > Fee Amount    ZAR 327.00
> > Interest      ZAR -1526.00
> > Total         ZAR 1199.00
> >
> > Regards
> > Timothy
> >
> > Further to above I have found that the Total 1199.00 which is transferred to my
> > cheque account is actually negative and appears in the cheque a/c as a payment not a deposit.
> > So it looks like the QIF amount T has the sign changed and then the fees are added to give the
> > Interest Amount and then added again to give the Total. Wow!
> >
> > Timothy
> >
> 
> Just a quick test for the moment, but that doesn't look right to me.
> 
> I'll need to investigate, but would you please raise a bug at 
> https://bugs.kde.org
> 
> Allan


Will do so.
Timothy

Hi Allan

This is a duplicate of Bug 322381 filed July 2013 with the variation the sign is also changed.
I did not follow up on this bug as I had implemented a work-around in my own QIF preprocessor 
and things had worked quite nicely from then. However the negative sign has now thrown out my
work-around logic.
I had forgotten the original bug filed, as dividend import was working for me. You can import my
original bug numbers and see that the result has now changed. If you want me to add anything to 
the original bug filed let me know.

Timothy
Comment 2 timothy 2014-12-01 08:11:14 UTC
BTW I amusin the latest KMM from Clay Weber daily updates Version 4.7.90
Using KDE Development Platform 4.13.3. The update was dowmloaded yesterday.
Comment 3 allan 2014-12-01 12:25:39 UTC
There is definitely a problem.
Here is a simple QIF file.

!Account
NInv
TInvst
^
!Type:Invst
D03/06/2014
YsecurityB
NDivX
MDividend Payment
T1150.00
O150.00
^

If I create an Investment account called Inv, which has an associated (Brokerage) account, and a security called securityB, and then import that file into Inv, the Brokerage account shows a payment of 850.00, instead of a net deposit of 1000.00, and a missing assignment of 300.00 is flagged.  The splits show a payment of 1000.00 and a fee payment of 150.00
If for comparison, I manually create a Dividend transaction, with amount 1150.00 and fee of 150.00, then that is correctly entered, with the Brokerage account showing a deposit of 1000.00, and a fee of 150.00
Comment 4 timothy 2014-12-01 14:35:24 UTC
Created attachment 89791 [details]
attachment-12660-0.html

Hi Allan

The DIVX transaction is defaulting to the brokerage account. Try adding
the line 
L[Bank Accounts:Cheque]
for transfer to the cheque account. Maybe you will get the minus amount
that I got.
Regards
Timothy
 

     On Monday, December 1, 2014 2:25 PM, allan <agander93@gmail.com> wrote:
   

 https://bugs.kde.org/show_bug.cgi?id=322381

allan <agander93@gmail.com> changed:

          What    |Removed                    |Added
----------------------------------------------------------------------------
    Ever confirmed|0                          |1
                CC|                            |agander93@gmail.com
            Status|UNCONFIRMED                |CONFIRMED

--- Comment #3 from allan <agander93@gmail.com> ---
There is definitely a problem.
Here is a simple QIF file.

!Account
NInv
TInvst
^
!Type:Invst
D03/06/2014
YsecurityB
NDivX
MDividend Payment
T1150.00
O150.00
^

If I create an Investment account called Inv, which has an associated
(Brokerage) account, and a security called securityB, and then import that file
into Inv, the Brokerage account shows a payment of 850.00, instead of a net
deposit of 1000.00, and a missing assignment of 300.00 is flagged.  The splits
show a payment of 1000.00 and a fee payment of 150.00
If for comparison, I manually create a Dividend transaction, with amount
1150.00 and fee of 150.00, then that is correctly entered, with the Brokerage
account showing a deposit of 1000.00, and a fee of 150.00
Comment 5 allan 2014-12-01 14:55:27 UTC
That doesn't make any difference, Tim, but I'm not sure we're getting different results.

When you say "Maybe you will get the minus amount", where are you seeing that?  Looking at either the brokerage account or the cheque account, the result is the same - 850.00.
Looking at the investment account, if the imported  transaction is *not* selected, the Value shows as 850.00.  If it is selected, then -1000.00 shows under Quantity, but if you are using the Transaction form to view, then that -1000.00 is the interest amount,  the fee is 150.00 and the total is 850.00.

It is definitely wrong.
Comment 6 timothy 2014-12-01 16:21:18 UTC
Created attachment 89793 [details]
attachment-16662-0.html

Yes I thought we were getting different results, but I see they are the same.
 BTW I am using the latest daily-build from Clay Weber downloaded yesterday on Mint 17 

     On Monday, December 1, 2014 4:55 PM, allan <agander93@gmail.com> wrote:
   

 https://bugs.kde.org/show_bug.cgi?id=322381

--- Comment #5 from allan <agander93@gmail.com> ---
That doesn't make any difference, Tim, but I'm not sure we're getting different
results.

When you say "Maybe you will get the minus amount", where are you seeing that? 
Looking at either the brokerage account or the cheque account, the result is
the same - 850.00.
Looking at the investment account, if the imported  transaction is *not*
selected, the Value shows as 850.00.  If it is selected, then -1000.00 shows
under Quantity, but if you are using the Transaction form to view, then that
-1000.00 is the interest amount,  the fee is 150.00 and the total is 850.00.

It is definitely wrong.
Comment 7 allan 2014-12-01 18:05:41 UTC
After processing in mymoneyqifreader.cpp, the data is passed to moneystatementreader.cpp. 
On 12 Sept 2014, a change was applied here -
"Remove the OFX investment transactions amount sign inversion hack.
As the author of the hack states he's not sure why this was necessary.
This hack also caused a lot of workarounds in MyMoneyStatementReader
so it definitely should be removed. I've tried to keep the current
behaviour in MyMoneyStatementReader but since I'm not familiar with
investment transaction these should be double checked.
BUG: 333522
REVIEW: 120153"

This might be implicated.
Comment 8 allan 2014-12-01 20:53:45 UTC
Going back to the top, your first problem (July 2013), importing that file now, or my similar version -
!Account
NInv
TInvst
^
!Type:Invst
D03/06/2014
YsecurityB
NDivX
MDividend Payment
T1150
O150
^
This now imports correctly, sort of.  and after import it appears to be correct.  Viewed in the Transaction form, fee = 150.00, Interest = 1000.00, total = 1150.00. So, that looks promising.
However, if I now open to edit the transaction, the Total now = 850.00.  So, I think I know where to go next.
Comment 9 timothy 2014-12-03 08:29:32 UTC
Created attachment 89819 [details]
attachment-20946-0.html

Hi AllanJust a thought. The amount or interest in both the OFX and QIF dividend processing should always be net input (ie total declared dividend less fees).  As this is what will shown by the bank or share company (to pay out or buy more shares).RegardsTimothy
 

     On Monday, December 1, 2014 10:53 PM, allan <agander93@gmail.com> wrote:
   

 https://bugs.kde.org/show_bug.cgi?id=322381

--- Comment #8 from allan <agander93@gmail.com> ---
Going back to the top, your first problem (July 2013), importing that file now,
or my similar version -
!Account
NInv
TInvst
^
!Type:Invst
D03/06/2014
YsecurityB
NDivX
MDividend Payment
T1150
O150
^
This now imports correctly, sort of.  and after import it appears to be
correct.  Viewed in the Transaction form, fee = 150.00, Interest = 1000.00,
total = 1150.00. So, that looks promising.
However, if I now open to edit the transaction, the Total now = 850.00.  So, I
think I know where to go next.
Comment 10 allan 2014-12-03 11:32:44 UTC
On 03/12/14 08:29, egroegbaker@yahoo.com wrote:
> https://bugs.kde.org/show_bug.cgi?id=322381
>
> --- Comment #9 from egroegbaker@yahoo.com ---
> Hi AllanJust a thought. The amount or interest in both the OFX and QIF dividend
> processing should always be net input (ie total declared dividend less fees).
> As this is what will shown by the bank or share company (to pay out or buy more
> shares).RegardsTimothy
>

I'm not sure that that is exactly true.
The gross amount is the dividend that was earned - the income, the fee 
is the expense, and the difference is the transfer amount that gets 
transferred to the cheque/brokerage account.

The recent fix for the OFX problem, and the related removal of the hack 
requiring a negation appears to have fixed that problem, but QIF 
handling took that negation into account, so that explains the current 
QIF problem, not just for Dividends, but some other activity types as 
well. So, they are all wrong if there is a fee to take into account.

However, your problem predates those OFX fixes so there is another 
problem yet.  Manual dividend entry is unaffected - only imports fail.

Allan
Comment 11 allan 2014-12-06 13:01:28 UTC
Git commit e09e3467305aa926ba49852638b44ceb8089c318 by Allan Anderson.
Committed on 06/12/2014 at 12:35.
Pushed by allananderson into branch 'master'.
Fix fees(taxes) being deducted twice from dividend amount during QIF import.
Also fix imported amount being negated.

The former appears to be a very long-standing problem.

The latter is a consequence of the fix for BUG 333522 5c54aafef7aa8a39ffd3b5e2dcb6538301652ee5.

M  +6    -2    kmymoney/converter/mymoneyqifreader.cpp
M  +9    -5    kmymoney/converter/mymoneystatementreader.cpp
M  +7    -2    kmymoney/plugins/csvimport/investprocessing.cpp

http://commits.kde.org/kmymoney/e09e3467305aa926ba49852638b44ceb8089c318
Comment 12 Daniel Hahler 2014-12-19 15:10:46 UTC
Thanks for fixing this!

Can/should this be backported to the stable / 4.7 branch?
Cherry-picking the commit (e09e3467305aa926ba49852638b44ceb8089c318) appears to work without conflicts.
Comment 13 allan 2014-12-19 17:57:15 UTC
(In reply to Daniel Hahler from comment #12)
> Thanks for fixing this!
> 
> Can/should this be backported to the stable / 4.7 branch?
> Cherry-picking the commit (e09e3467305aa926ba49852638b44ceb8089c318) appears
> to work without conflicts.

It's good to know that people care!

Yes, I'll be doing that very soon, just a bit busy.  I have also a minor tidy-up to do on it first, then I'll backport.
Comment 14 allan 2014-12-20 22:35:25 UTC
Git commit d172e4c1339a80d2c2fbc3651fa005a092d8a33d by Allan Anderson.
Committed on 06/12/2014 at 12:35.
Pushed by allananderson into branch '4.7'.
Fix fees(taxes) being deducted twice from dividend amount during QIF import.
Also fix imported amount being negated.

The former appears to be a very long-standing problem.

The latter is a consequence of the fix for BUG 333522 5c54aafef7aa8a39ffd3b5e2dcb6538301652ee5.

Also, remove unwanted comments.

(cherry-picked from e09e3467305aa926ba49852638b44ceb8089c318)

M  +2    -2    kmymoney/converter/mymoneyqifreader.cpp
M  +9    -5    kmymoney/converter/mymoneystatementreader.cpp
M  +5    -2    kmymoney/plugins/csvimport/investprocessing.cpp

http://commits.kde.org/kmymoney/d172e4c1339a80d2c2fbc3651fa005a092d8a33d
Comment 15 allan 2015-03-29 13:08:15 UTC
Git commit a4946c87e51e031812160471dae8933b0c0f04d5 by Allan Anderson.
Committed on 06/12/2014 at 12:35.
Pushed by allananderson into branch '4.7'.
Fix fees(taxes) being deducted twice from dividend amount during QIF import.
Also fix imported amount being negated.

The former appears to be a very long-standing problem.

The latter is a consequence of the fix for BUG 333522 5c54aafef7aa8a39ffd3b5e2dcb6538301652ee5.

(cherry picked from commit e09e3467305aa926ba49852638b44ceb8089c318)

Conflicts:
	kmymoney/converter/mymoneyqifreader.cpp
	kmymoney/plugins/csvimport/investprocessing.cpp

M  +4    -0    kmymoney/converter/mymoneyqifreader.cpp
M  +2    -0    kmymoney/plugins/csvimport/investprocessing.cpp

http://commits.kde.org/kmymoney/a4946c87e51e031812160471dae8933b0c0f04d5