From 06eeaebb2a9420228f8c0020c46f9257efd2c33b Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sat, 31 Oct 2009 19:58:49 +0000 Subject: [PATCH] Fix amount sign of imported bank transfers (e.g. from DTAUS file). Usually an imported DTAUS file describes debit notes, which means "our account" is credited (and the other debited). But DTAUS can also contain transfers, which means "our account" is debited. In the DTAUS case, the value would still be positive, so we have to query the transaction type for this case as well. This is now fixed. (Needs aqbanking-4.1.10 though because the earlier versions forgot to set the TypeTransfer.) git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18402 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/import-export/aqbanking/gnc-ab-utils.c | 16 ++++++++++++---- src/import-export/hbci/gnc-hbci-gettrans.c | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/import-export/aqbanking/gnc-ab-utils.c b/src/import-export/aqbanking/gnc-ab-utils.c index 1cc4962d03..42e903c66c 100644 --- a/src/import-export/aqbanking/gnc-ab-utils.c +++ b/src/import-export/aqbanking/gnc-ab-utils.c @@ -346,8 +346,6 @@ gnc_ab_trans_to_gnc(const AB_TRANSACTION *ab_trans, Account *gnc_acc) const char *custref; gchar *description; Split *split; - const AB_VALUE *ab_value; - gnc_numeric gnc_amount; gchar *memo; g_return_val_if_fail(ab_trans && gnc_acc, NULL); @@ -400,15 +398,25 @@ gnc_ab_trans_to_gnc(const AB_TRANSACTION *ab_trans, Account *gnc_acc) if (fitid && *fitid) gnc_import_set_split_online_id(split, fitid); + { /* Amount into the split */ - ab_value = AB_Transaction_GetValue(ab_trans); + const AB_VALUE *ab_value = AB_Transaction_GetValue(ab_trans); + double d_value = ab_value ? AB_Value_GetValueAsDouble (ab_value) : 0.0; + AB_TRANSACTION_TYPE ab_type = AB_Transaction_GetType (ab_trans); + gnc_numeric gnc_amount; + + printf("Transaction with value %f has type %d\n", d_value, ab_type); + if (d_value > 0.0 && ab_type == AB_Transaction_TypeTransfer) + d_value = -d_value; + gnc_amount = double_to_gnc_numeric( - ab_value ? AB_Value_GetValueAsDouble(ab_value) : 0.0, + d_value, xaccAccountGetCommoditySCU(gnc_acc), GNC_RND_ROUND); if (!ab_value) g_warning("transaction_cb: Oops, value was NULL. Using 0"); xaccSplitSetBaseValue(split, gnc_amount, xaccAccountGetCommodity(gnc_acc)); + } /* Memo in the Split. */ memo = gnc_ab_memo_to_gnc(ab_trans); diff --git a/src/import-export/hbci/gnc-hbci-gettrans.c b/src/import-export/hbci/gnc-hbci-gettrans.c index 5ea3bc8414..4b8643f9af 100644 --- a/src/import-export/hbci/gnc-hbci-gettrans.c +++ b/src/import-export/hbci/gnc-hbci-gettrans.c @@ -321,8 +321,19 @@ AB_TRANSACTION *gnc_hbci_trans_list_cb(AB_TRANSACTION *h_trans, void *user_data) { /* Amount into the split */ const AB_VALUE *h_value = AB_Transaction_GetValue (h_trans); - gnc_numeric gnc_amount = double_to_gnc_numeric - (h_value ? AB_Value_GetValue (h_value) : 0.0, + double d_value = h_value ? AB_Value_GetValue (h_value) : 0.0; + AB_TRANSACTION_TYPE h_type = AB_Transaction_GetType (h_trans); + gnc_numeric gnc_amount; + + /*printf("Transaction with value %f has type %d\n", d_value, h_type);*/ + /* If the value is positive, but the transaction type says the + money is transferred away from our account (Transfer instead of + DebitNote), we switch the value to negative. */ + if (d_value > 0.0 && h_type == AB_Transaction_TypeTransfer) + d_value = -d_value; + + gnc_amount = double_to_gnc_numeric + (d_value, xaccAccountGetCommoditySCU(gnc_acc), GNC_RND_ROUND); if (!h_value)