gnucash master: Bug 764268 - MT940 import select account based on transaction info
Christian Stimming
cstim at code.gnucash.org
Tue Apr 5 15:54:18 EDT 2016
Updated via https://github.com/Gnucash/gnucash/commit/dc4fce0a (commit)
from https://github.com/Gnucash/gnucash/commit/ee40d5dc (commit)
commit dc4fce0aaea0cabcb83f9de9a4cffa5b53089747
Author: Christian Stimming <christian at cstimming.de>
Date: Tue Apr 5 21:51:49 2016 +0200
Bug 764268 - MT940 import select account based on transaction info
When importing MT940 files, AqBanking will (sometimes?) put
all transactions under a single AccountInfo, even when there
are multiple accounts in the file. Luckily the correct account
information can be recovered from the transaction information.
This patch will try to use the account information in the
transaction before trying to use the saved account state.
Patch by Jethro Beekman.
diff --git a/src/import-export/aqb/gnc-ab-utils.c b/src/import-export/aqb/gnc-ab-utils.c
index fb6c926..f6c1df2 100644
--- a/src/import-export/aqb/gnc-ab-utils.c
+++ b/src/import-export/aqb/gnc-ab-utils.c
@@ -62,6 +62,8 @@ static gint gnc_AB_BANKING_refcount = 0;
static gpointer join_ab_strings_cb(const gchar *str, gpointer user_data);
static Account *gnc_ab_accinfo_to_gnc_acc(
AB_IMEXPORTER_ACCOUNTINFO *account_info);
+static Account *gnc_ab_txn_to_gnc_acc(
+ const AB_TRANSACTION *transaction);
static const AB_TRANSACTION *txn_transaction_cb(
const AB_TRANSACTION *element, gpointer user_data);
static AB_IMEXPORTER_ACCOUNTINFO *txn_accountinfo_cb(
@@ -605,17 +607,59 @@ gnc_ab_accinfo_to_gnc_acc(AB_IMEXPORTER_ACCOUNTINFO *acc_info)
return gnc_acc;
}
+
+/**
+ * Call gnc_import_select_account() on the online id constructed using
+ * the local information in @a transaction.
+ *
+ * @param transaction AB_TRANSACTION
+ * @return A GnuCash account, or NULL otherwise
+ */
+static Account *
+gnc_ab_txn_to_gnc_acc(const AB_TRANSACTION *transaction)
+{
+ const gchar *bankcode, *accountnumber;
+ gchar *online_id;
+ Account *gnc_acc;
+
+ g_return_val_if_fail(transaction, NULL);
+
+ bankcode = AB_Transaction_GetLocalBankCode(transaction);
+ accountnumber = AB_Transaction_GetLocalAccountNumber(transaction);
+ if (!bankcode && !accountnumber)
+ {
+ return NULL;
+ }
+
+ online_id = g_strconcat(bankcode ? bankcode : "",
+ accountnumber ? accountnumber : "",
+ (gchar*)NULL);
+ gnc_acc = gnc_import_select_account(
+ NULL, online_id, 1, AB_Transaction_GetLocalName(transaction),
+ NULL, ACCT_TYPE_NONE, NULL, NULL);
+ if (!gnc_acc)
+ {
+ g_warning("gnc_ab_txn_to_gnc_acc: Could not determine source account"
+ " for online_id %s", online_id);
+ }
+ g_free(online_id);
+
+ return gnc_acc;
+}
+
static const AB_TRANSACTION *
txn_transaction_cb(const AB_TRANSACTION *element, gpointer user_data)
{
GncABImExContextImport *data = user_data;
Transaction *gnc_trans;
GncABTransType trans_type;
+ Account* txnacc;
g_return_val_if_fail(element && data, NULL);
/* Create a GnuCash transaction from ab_trans */
- gnc_trans = gnc_ab_trans_to_gnc(element, data->gnc_acc);
+ txnacc = gnc_ab_txn_to_gnc_acc(element);
+ gnc_trans = gnc_ab_trans_to_gnc(element, txnacc ? txnacc : data->gnc_acc);
if (data->execute_txns && data->ab_acc)
{
Summary of changes:
src/import-export/aqb/gnc-ab-utils.c | 46 +++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
More information about the gnucash-changes
mailing list