From 6cc28474beb0c41fc6d654656aec51314bb07a2e Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Fri, 18 Sep 2009 19:51:43 +0000 Subject: [PATCH] Bug #572938: Fix OFX Mutual fund buys that are imported as sells MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/import-export/ofx/gnc-ofx-import.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/import-export/ofx/gnc-ofx-import.c b/src/import-export/ofx/gnc-ofx-import.c index e1c0e03695..956961d3fb 100644 --- a/src/import-export/ofx/gnc-ofx-import.c +++ b/src/import-export/ofx/gnc-ofx-import.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #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_transaction_cb(struct OfxTransactionData data, void * transaction_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) { @@ -379,7 +381,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u xaccTransAppendSplit(transaction,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_RND_ROUND); 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); 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_RND_ROUND); xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction)); @@ -632,6 +634,26 @@ int ofx_proc_account_cb(struct OfxAccountData data, void * account_user_data) 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) { extern int ofx_PARSER_msg;