r18402 - gnucash/trunk/src/import-export - Fix amount sign of imported bank transfers (e.g. from DTAUS file).

Christian Stimming cstim at code.gnucash.org
Sat Oct 31 15:58:50 EDT 2009


Author: cstim
Date: 2009-10-31 15:58:49 -0400 (Sat, 31 Oct 2009)
New Revision: 18402
Trac: http://svn.gnucash.org/trac/changeset/18402

Modified:
   gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c
   gnucash/trunk/src/import-export/hbci/gnc-hbci-gettrans.c
Log:
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.)

Modified: gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c
===================================================================
--- gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c	2009-10-30 20:07:25 UTC (rev 18401)
+++ gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c	2009-10-31 19:58:49 UTC (rev 18402)
@@ -346,8 +346,6 @@
     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 @@
     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);

Modified: gnucash/trunk/src/import-export/hbci/gnc-hbci-gettrans.c
===================================================================
--- gnucash/trunk/src/import-export/hbci/gnc-hbci-gettrans.c	2009-10-30 20:07:25 UTC (rev 18401)
+++ gnucash/trunk/src/import-export/hbci/gnc-hbci-gettrans.c	2009-10-31 19:58:49 UTC (rev 18402)
@@ -321,8 +321,19 @@
   {
     /* 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)



More information about the gnucash-changes mailing list