Bug 796756 - OFX import fails to recognize associated income accounts.

Because qof_instance_set and qof_instance_get were being called with the
KVP key instead of the property name.

Since we don't really want references to KVP outside of engine and since
the two functions are called exactly once each in qof-ofx-import.c move
them inside qof-ofx-import.c and get rid of gnc-ofx-kvp.[ch] as well as
fix the bug.
This commit is contained in:
John Ralls
2018-07-13 11:46:50 -07:00
parent 983c7ce0bc
commit 9db7d89474
4 changed files with 33 additions and 101 deletions

View File

@@ -3,7 +3,6 @@ add_subdirectory(test)
set(ofx_SOURCES
gnc-ofx-import.c
gnc-ofx-kvp.c
gncmod-ofx-import.c
gnc-plugin-ofx.c
)
@@ -13,7 +12,6 @@ set_source_files_properties (${ofx_SOURCES} PROPERTIES OBJECT_DEPENDS ${CONFIG_H
set(ofx_noinst_HEADERS
gnc-ofx-import.h
gnc-ofx-kvp.h
gnc-plugin-ofx.h
)

View File

@@ -51,8 +51,6 @@
#include "dialog-account.h"
#include "dialog-utils.h"
#include "gnc-ofx-kvp.h"
#define GNC_PREFS_GROUP "dialogs.import.ofx"
#define GNC_PREF_AUTO_COMMODITY "auto-create-commodity"
@@ -78,6 +76,36 @@ int ofx_proc_status_cb(struct OfxStatusData data)
}
*/
static const char *PROP_OFX_INCOME_ACCOUNT = "ofx-income-account";
static Account*
get_associated_income_account(const Account* investment_account)
{
GncGUID *income_guid= NULL;
g_assert(investment_account);
qof_instance_get (QOF_INSTANCE (investment_account),
PROP_OFX_INCOME_ACCOUNT, &income_guid,
NULL);
return xaccAccountLookup(income_guid,
gnc_account_get_book(investment_account));
}
void set_associated_income_account(Account* investment_account,
const Account *income_account)
{
const GncGUID * income_acc_guid;
g_assert(investment_account);
g_assert(income_account);
income_acc_guid = xaccAccountGetGUID(income_account);
xaccAccountBeginEdit(investment_account);
qof_instance_set (QOF_INSTANCE (investment_account),
PROP_OFX_INCOME_ACCOUNT, income_acc_guid,
NULL);
xaccAccountCommitEdit(investment_account);
}
int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_user_data);
int ofx_proc_transaction_cb (struct OfxTransactionData data, void *user_data);
int ofx_proc_account_cb(struct OfxAccountData data, void * account_user_data);
@@ -756,7 +784,8 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void *user_data)
{
DEBUG("Now let's find an account for the destination split");
income_account = gnc_ofx_kvp_get_assoc_account(investment_account);
income_account =
get_associated_income_account(investment_account);
if (income_account == NULL)
{
@@ -778,7 +807,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void *user_data)
NULL);
if (income_account != NULL)
{
gnc_ofx_kvp_set_assoc_account(investment_account,
set_associated_income_account(investment_account,
income_account);
DEBUG("KVP written");
}

View File

@@ -1,57 +0,0 @@
/*******************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
/*
* gnc-ofx-kvp.c
*
* Created on: 13.03.2011
* Author: cs
*/
#include <config.h>
#include "gnc-ofx-kvp.h"
static const char *KEY_ASSOC_INCOME_ACCOUNT = "ofx/associated-income-account";
Account *gnc_ofx_kvp_get_assoc_account(const Account* investment_account)
{
GncGUID *income_guid= NULL;
g_assert(investment_account);
qof_instance_get (QOF_INSTANCE (investment_account),
KEY_ASSOC_INCOME_ACCOUNT, &income_guid,
NULL);
return xaccAccountLookup(income_guid,
gnc_account_get_book(investment_account));
}
void gnc_ofx_kvp_set_assoc_account(Account* investment_account,
const Account *income_account)
{
const GncGUID * income_acc_guid;
g_assert(investment_account);
g_assert(income_account);
income_acc_guid = xaccAccountGetGUID(income_account);
xaccAccountBeginEdit(investment_account);
qof_instance_set (QOF_INSTANCE (investment_account),
KEY_ASSOC_INCOME_ACCOUNT, income_acc_guid,
NULL);
xaccAccountCommitEdit(investment_account);
}

View File

@@ -1,38 +0,0 @@
/*******************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
/*
* gnc-ofx-kvp.h
*
* Created on: 13.03.2011
* Author: cs
*/
#ifndef GNC_OFX_KVP_H_
#define GNC_OFX_KVP_H_
#include <glib.h>
#include <Account.h>
Account *gnc_ofx_kvp_get_assoc_account(const Account* investment_account);
void gnc_ofx_kvp_set_assoc_account(Account* investment_account,
const Account *associated_income_accout);
#endif /* GNC_OFX_CONVERSIONS_H_ */