Bug #572938: Fix OFX Mutual fund buys that are imported as sells

When I try to import a downloaded OFX from Fidelity NetBenefits, my mutual fund
purchases become sales. I looked at the code and it seemed like a pretty simple
fix, it seems as if it was treading all non-income investing transactions as sales.
I wrote and tested this patch to fix the problem.

Patch by Matt Lavin, signed-off by Benoit Grégoire.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18321 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2009-09-18 19:51:43 +00:00
parent 03585ce69e
commit 6cc28474be

View File

@ -31,6 +31,7 @@
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <libguile.h> #include <libguile.h>
#include <math.h>
#include <libofx/libofx.h> #include <libofx/libofx.h>
#include "import-account-matcher.h" #include "import-account-matcher.h"
@ -71,6 +72,7 @@ int ofx_proc_status_cb(struct OfxStatusData data)
int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_user_data); int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_user_data);
int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_user_data); int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_user_data);
int ofx_proc_account_cb(struct OfxAccountData data, void * account_user_data); int ofx_proc_account_cb(struct OfxAccountData data, void * account_user_data);
double ofx_get_investment_amount(struct OfxTransactionData data);
int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_user_data) int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_user_data)
{ {
@ -379,7 +381,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
xaccTransAppendSplit(transaction,split); xaccTransAppendSplit(transaction,split);
xaccAccountInsertSplit(investment_account,split); xaccAccountInsertSplit(investment_account,split);
gnc_amount = double_to_gnc_numeric (-(data.amount), gnc_amount = double_to_gnc_numeric (ofx_get_investment_amount(data),
gnc_commodity_get_fraction(investment_commodity), gnc_commodity_get_fraction(investment_commodity),
GNC_RND_ROUND); GNC_RND_ROUND);
gnc_units = double_to_gnc_numeric (data.units, gnc_units = double_to_gnc_numeric (data.units,
@ -505,7 +507,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
xaccTransAppendSplit(transaction,split); xaccTransAppendSplit(transaction,split);
xaccAccountInsertSplit(account,split); xaccAccountInsertSplit(account,split);
gnc_amount = double_to_gnc_numeric (data.amount, gnc_amount = double_to_gnc_numeric (-ofx_get_investment_amount(data),
gnc_commodity_get_fraction(xaccTransGetCurrency(transaction)), gnc_commodity_get_fraction(xaccTransGetCurrency(transaction)),
GNC_RND_ROUND); GNC_RND_ROUND);
xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction)); xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction));
@ -632,6 +634,26 @@ int ofx_proc_account_cb(struct OfxAccountData data, void * account_user_data)
return 0; return 0;
} }
double ofx_get_investment_amount(struct OfxTransactionData data)
{
switch(data.invtransactiontype){
case OFX_BUYDEBT:
case OFX_BUYMF:
case OFX_BUYOPT:
case OFX_BUYOTHER:
case OFX_BUYSTOCK:
return fabs(data.amount);
case OFX_SELLDEBT:
case OFX_SELLMF:
case OFX_SELLOPT:
case OFX_SELLOTHER:
case OFX_SELLSTOCK:
return -1*fabs(data.amount);
default:
return -1*data.amount;
}
}
void gnc_file_ofx_import (void) void gnc_file_ofx_import (void)
{ {
extern int ofx_PARSER_msg; extern int ofx_PARSER_msg;