r19909 - gnucash/trunk/src/import-export - Bug #635355: Partly implement the correct "DTAUS import and send" feature again.

Christian Stimming cstim at code.gnucash.org
Sun Dec 5 08:27:03 EST 2010


Author: cstim
Date: 2010-12-05 08:27:02 -0500 (Sun, 05 Dec 2010)
New Revision: 19909
Trac: http://svn.gnucash.org/trac/changeset/19909

Modified:
   gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c
   gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.h
   gnucash/trunk/src/import-export/import-backend.c
   gnucash/trunk/src/import-export/import-backend.h
   gnucash/trunk/src/import-export/import-main-matcher.c
   gnucash/trunk/src/import-export/import-main-matcher.h
Log:
Bug #635355: Partly implement the correct "DTAUS import and send" feature again.

Patch by Manfred Usselmann.

The main part of the feature is delayed until the string freeze is lifted.
This part (without adding strings) implements the infrastructure for sending
only the correctly imported transactions to the bank later.

Modified: gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c
===================================================================
--- gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c	2010-12-05 01:57:08 UTC (rev 19908)
+++ gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c	2010-12-05 13:27:02 UTC (rev 19909)
@@ -79,6 +79,7 @@
     GtkWidget *parent;
     AB_JOB_LIST2 *job_list;
     GNCImportMainMatcher *generic_importer;
+    GData *tmp_job_list;
 };
 
 void
@@ -580,9 +581,6 @@
     /* Create a GnuCash transaction from ab_trans */
     gnc_trans = gnc_ab_trans_to_gnc(element, data->gnc_acc);
 
-    /* Instead of xaccTransCommitEdit(gnc_trans)  */
-    gnc_gen_trans_list_add_trans(data->generic_importer, gnc_trans);
-
     if (data->execute_txns && data->ab_acc)
     {
         AB_TRANSACTION *ab_trans = AB_Transaction_dup(element);
@@ -635,16 +633,65 @@
             {
                 gnc_error_dialog(NULL, "Sorry, not implemented yet. Please check the console or trace file logs to see which job was rejected.");
             }
-            /* else */
         }
-        AB_Job_List2_PushBack(data->job_list, job);
+        else
+        {
+            gnc_gen_trans_list_add_trans_with_ref_id(data->generic_importer, gnc_trans, AB_Job_GetJobId(job));
 
+            /* AB_Job_List2_PushBack(data->job_list, job); -> delayed until trans is successfully imported */
+            g_datalist_set_data(&data->tmp_job_list, gnc_AB_JOB_to_readable_string(job), job);
+        }
         AB_Transaction_free(ab_trans);
     }
+    else
+    {
+        /* Instead of xaccTransCommitEdit(gnc_trans)  */
+        gnc_gen_trans_list_add_trans(data->generic_importer, gnc_trans);
+    }
 
     return NULL;
 }
 
+static void gnc_ab_trans_processed_cb(GNCImportTransInfo *trans_info,
+                                      gboolean imported,
+                                      gpointer user_data)
+{
+    GncABImExContextImport *data = user_data;
+    gchar *jobname = gnc_AB_JOB_ID_to_string(gnc_import_TransInfo_get_ref_id(trans_info));
+    AB_JOB *job = g_datalist_get_data(&data->tmp_job_list, jobname);
+
+    if (imported)
+    {
+        AB_Job_List2_PushBack(data->job_list, job);
+    }
+    else
+    {
+        AB_Job_free(job);
+    }
+
+    g_datalist_remove_data(&data->tmp_job_list, jobname);
+}
+
+gchar *
+gnc_AB_JOB_to_readable_string(const AB_JOB *job)
+{
+    if (job)
+    {
+        return gnc_AB_JOB_ID_to_string(AB_Job_GetJobId(job));
+    }
+    else
+    {
+        return gnc_AB_JOB_ID_to_string(0);
+    }
+}
+gchar *
+gnc_AB_JOB_ID_to_string(gulong job_id)
+{
+    return g_strdup_printf("job_%lu", job_id);
+}
+
+
+
 static AB_IMEXPORTER_ACCOUNTINFO *
 txn_accountinfo_cb(AB_IMEXPORTER_ACCOUNTINFO *element, gpointer user_data)
 {
@@ -704,8 +751,15 @@
     }
 
     if (!data->generic_importer)
+    {
         data->generic_importer = gnc_gen_trans_list_new(data->parent, NULL,
                                  TRUE, 14);
+        if (data->execute_txns)
+        {
+            gnc_gen_trans_list_add_tp_cb(data->generic_importer,
+                                         gnc_ab_trans_processed_cb, data);
+        }
+    }
 
     /* Iterate through all transactions */
     AB_ImExporterAccountInfo_TransactionsForEach(element, txn_transaction_cb,
@@ -939,8 +993,11 @@
     data->api = api;
     data->parent = parent;
     data->job_list = AB_Job_List2_new();
+    data->tmp_job_list = NULL;
     data->generic_importer = NULL;
 
+    g_datalist_init(&data->tmp_job_list);
+
     /* Import transactions */
     if (!(awaiting & IGNORE_TRANSACTIONS))
         AB_ImExporterContext_AccountInfoForEach(context, txn_accountinfo_cb,

Modified: gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.h
===================================================================
--- gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.h	2010-12-05 01:57:08 UTC (rev 19908)
+++ gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.h	2010-12-05 13:27:02 UTC (rev 19909)
@@ -146,6 +146,22 @@
 gchar *gnc_AB_VALUE_to_readable_string(const AB_VALUE *value);
 
 /**
+ * Return the job as string.
+ *
+ * @param value AB_JOB or NULL
+ * @return A newly allocated string
+ */
+gchar *gnc_AB_JOB_to_readable_string(const AB_JOB *job);
+
+/**
+ * Return the job_id as string.
+ *
+ * @param job_id
+ * @return A newly allocated string
+ */
+gchar *gnc_AB_JOB_ID_to_string(gulong job_id);
+
+/**
  * Retrieve the merged "remote name" fields from a transaction.  The returned
  * string must be g_free'd by the caller.  If there was no "remote name" field,
  * NULL (!) is returned.

Modified: gnucash/trunk/src/import-export/import-backend.c
===================================================================
--- gnucash/trunk/src/import-export/import-backend.c	2010-12-05 01:57:08 UTC (rev 19908)
+++ gnucash/trunk/src/import-export/import-backend.c	2010-12-05 13:27:02 UTC (rev 19909)
@@ -92,6 +92,9 @@
     /* In case of a single destination account it is stored here. */
     Account *dest_acc;
     gboolean dest_acc_selected_manually;
+
+    /* Reference id to link gnc transaction to external object. E.g. aqbanking job id. */
+    guint32 ref_id;
 };
 
 struct _matchinfo
@@ -213,6 +216,22 @@
     return info->dest_acc_selected_manually;
 }
 
+guint32
+gnc_import_TransInfo_get_ref_id (const GNCImportTransInfo *info)
+{
+    g_assert (info);
+    return info->ref_id;
+}
+
+void
+gnc_import_TransInfo_set_ref_id (GNCImportTransInfo *info,
+                                 guint32 ref_id)
+{
+    g_assert (info);
+    info->ref_id = ref_id;
+}
+
+
 Split *
 gnc_import_MatchInfo_get_split (const GNCImportMatchInfo * info)
 {
@@ -891,8 +910,7 @@
         xaccSplitSetDateReconciledSecs(gnc_import_TransInfo_get_fsplit (trans_info),
                                        time(NULL));
         /* Done editing. */
-        xaccTransCommitEdit
-        (gnc_import_TransInfo_get_trans (trans_info));
+        xaccTransCommitEdit(gnc_import_TransInfo_get_trans (trans_info));
         return TRUE;
     case GNCImport_CLEAR:
     {

Modified: gnucash/trunk/src/import-export/import-backend.h
===================================================================
--- gnucash/trunk/src/import-export/import-backend.h	2010-12-05 01:57:08 UTC (rev 19908)
+++ gnucash/trunk/src/import-export/import-backend.h	2010-12-05 13:27:02 UTC (rev 19909)
@@ -226,6 +226,16 @@
 gboolean
 gnc_import_TransInfo_get_destacc_selected_manually (const GNCImportTransInfo *info);
 
+
+/** Returns the reference id for this TransInfo. */
+guint32
+gnc_import_TransInfo_get_ref_id (const GNCImportTransInfo *info);
+
+/** Set the reference id for this TransInfo. */
+void
+gnc_import_TransInfo_set_ref_id (GNCImportTransInfo *info,
+                                 guint32 ref_id);
+
 /**@}*/
 
 /** @name Getters/Setters for GNCImportMatchInfo */

Modified: gnucash/trunk/src/import-export/import-main-matcher.c
===================================================================
--- gnucash/trunk/src/import-export/import-main-matcher.c	2010-12-05 01:57:08 UTC (rev 19908)
+++ gnucash/trunk/src/import-export/import-main-matcher.c	2010-12-05 13:27:02 UTC (rev 19909)
@@ -53,6 +53,8 @@
     GdkColor color_back_green;
     GdkColor color_back_yellow;
     int selected_row;
+    GNCTransactionProcessedCB transaction_processed_cb;
+    gpointer user_data;
 };
 
 enum downloaded_cols
@@ -105,6 +107,14 @@
             gtk_tree_model_get(model, &iter,
                                DOWNLOADED_COL_DATA, &trans_info,
                                -1);
+
+            if (info->transaction_processed_cb)
+            {
+                info->transaction_processed_cb(trans_info,
+                                               FALSE,
+                                               info->user_data);
+            }
+
             gnc_import_TransInfo_delete(trans_info);
         }
         while (gtk_tree_model_iter_next (model, &iter));
@@ -140,13 +150,30 @@
         gtk_tree_model_get(model, &iter,
                            DOWNLOADED_COL_DATA, &trans_info,
                            -1);
-        if (gnc_import_process_trans_item (NULL, trans_info))
+
+        if (gnc_import_process_trans_item(NULL, trans_info))
         {
             path = gtk_tree_model_get_path(model, &iter);
             ref = gtk_tree_row_reference_new(model, path);
             refs_list = g_slist_append(refs_list, ref);
             gtk_tree_path_free(path);
+
+            if (info->transaction_processed_cb)
+            {
+                info->transaction_processed_cb(trans_info,
+                                               TRUE,
+                                               info->user_data);
+            }
         }
+        else
+        {
+            /* transaction skipped -> destroy
+             * Otherwise temporary transactions remains visible if account is open
+             * (see gnc_import_process_trans_item() case GNCImport_CLEAR) */
+            xaccTransDestroy(gnc_import_TransInfo_get_trans(trans_info));
+            xaccTransCommitEdit(gnc_import_TransInfo_get_trans(trans_info));
+        }
+
     }
     while (gtk_tree_model_iter_next (model, &iter));
 
@@ -544,21 +571,32 @@
 
     gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(info->dialog));
     gtk_widget_show_all (GTK_WIDGET (info->dialog));
+
+    info->transaction_processed_cb = NULL;
+
     return info;
 }
 
+void gnc_gen_trans_list_add_tp_cb(GNCImportMainMatcher *info,
+                                  GNCTransactionProcessedCB trans_processed_cb,
+                                  gpointer user_data)
+{
+    info->user_data = user_data;
+    info->transaction_processed_cb = trans_processed_cb;
+}
+
+
 gboolean gnc_gen_trans_list_run (GNCImportMainMatcher *info)
 {
     gboolean result;
 
     /* DEBUG("Begin"); */
-
     result = gtk_dialog_run (GTK_DIALOG (info->dialog));
-
     /* DEBUG("Result was %d", result); */
 
     /* No destroying here since the dialog was already destroyed through
        the ok_clicked handlers. */
+
     return result;
 }
 
@@ -752,6 +790,12 @@
 
 void gnc_gen_trans_list_add_trans(GNCImportMainMatcher *gui, Transaction *trans)
 {
+    gnc_gen_trans_list_add_trans_with_ref_id(gui, trans, 0);
+    return;
+}/* end gnc_import_add_trans() */
+
+void gnc_gen_trans_list_add_trans_with_ref_id(GNCImportMainMatcher *gui, Transaction *trans, guint32 ref_id)
+{
     GNCImportTransInfo * transaction_info = NULL;
     GtkTreeModel *model;
     GtkTreeIter iter;
@@ -764,16 +808,17 @@
     else
     {
         transaction_info = gnc_import_TransInfo_new(trans, NULL);
+        gnc_import_TransInfo_set_ref_id(transaction_info, ref_id);
 
-        gnc_import_TransInfo_init_matches (transaction_info,
-                                           gui->user_settings);
+        gnc_import_TransInfo_init_matches(transaction_info,
+                                          gui->user_settings);
 
         model = gtk_tree_view_get_model(gui->view);
         gtk_list_store_append(GTK_LIST_STORE(model), &iter);
         refresh_model_row (gui, model, &iter, transaction_info);
     }
     return;
-}/* end gnc_import_add_trans() */
+}/* end gnc_import_add_trans_with_ref_id() */
 
 /* Iterate through the rows of the clist and try to automatch each of them */
 static void

Modified: gnucash/trunk/src/import-export/import-main-matcher.h
===================================================================
--- gnucash/trunk/src/import-export/import-main-matcher.h	2010-12-05 01:57:08 UTC (rev 19908)
+++ gnucash/trunk/src/import-export/import-main-matcher.h	2010-12-05 13:27:02 UTC (rev 19909)
@@ -28,9 +28,14 @@
 #define GNC_IMPORT_MAIN_MATCHER_H
 
 #include "Transaction.h"
+#include "import-backend.h"
 
 typedef struct _main_matcher_info GNCImportMainMatcher;
 
+typedef void (*GNCTransactionProcessedCB) (GNCImportTransInfo *trans_info,
+        gboolean imported, gpointer user_data);
+
+
 /** Create a new generic transaction dialog window and return it.
  *
  * @param parent The parent GtkWidget. May be NULL.
@@ -56,6 +61,16 @@
         gboolean all_from_same_account,
         gint match_date_hardlimit);
 
+/** Add transaction processed callback to the transaction importer.
+ *
+ * @param info The Transaction Importer to use.
+ *
+ * @param trans_processed_cb The callback function.
+ */
+void gnc_gen_trans_list_add_tp_cb(GNCImportMainMatcher *info,
+                                  GNCTransactionProcessedCB trans_processed_cb,
+                                  gpointer user_data);
+
 /** Deletes the given object. */
 void gnc_gen_trans_list_delete (GNCImportMainMatcher *info);
 
@@ -71,6 +86,22 @@
  */
 void gnc_gen_trans_list_add_trans(GNCImportMainMatcher *gui, Transaction *trans);
 
+/** Add a newly imported Transaction to the Transaction Importer and provide an
+ * external reference id for it.
+ * The Importer takes over ownership of the passed transaction.
+ *
+ * @param gui The Transaction Importer to use.
+ *
+ * @param trans The Transaction to add.  The must contain at least one
+ * split, and this split must have been associated with an account
+ * Only the first split will be used for matching.  The transaction
+ * must NOT be commited. The Importer takes over ownership of the
+ * passed transaction.
+ *
+ * @param ref_id Reference id which links an external object to the transaction.
+ */
+void gnc_gen_trans_list_add_trans_with_ref_id(GNCImportMainMatcher *gui, Transaction *trans, guint32 ref_id);
+
 /** Run this dialog and return only after the user pressed Ok, Cancel,
   or closed the window. This means that all actual importing will
   have been finished upon returning.



More information about the gnucash-changes mailing list