r20015 - gnucash/trunk/src/import-export/qif-import - Bug #95635: QIF import: Mark matched transactions as cleared

Christian Stimming cstim at code.gnucash.org
Fri Dec 31 07:25:30 EST 2010


Author: cstim
Date: 2010-12-31 07:25:30 -0500 (Fri, 31 Dec 2010)
New Revision: 20015
Trac: http://svn.gnucash.org/trac/changeset/20015

Modified:
   gnucash/trunk/src/import-export/qif-import/druid-qif-import.c
   gnucash/trunk/src/import-export/qif-import/qif-to-gnc.scm
   gnucash/trunk/src/import-export/qif-import/qif.glade
   gnucash/trunk/src/import-export/qif-import/schemas/apps_gnucash_import_qif.schemas.in
Log:
Bug #95635: QIF import: Mark matched transactions as cleared

Patch by Tristan Faujour:

Please describe the problem:
My bank allows me to download bank statement files in the QIF format. They
contain paid transactions, but there is no status ("C") line, so all
transactions are left in the "not cleared" status.
I wish it would be possible to define the default status in user preferences.

Steps to reproduce:
- Import a QIF file with no "C" line.

Actual results:
- Transactions are not cleared.

Expected results:
- The "near split" of the imported transactions should be set to a default
status 'defined in user preferences).

Does this happen every time?
- Yes

Other information:
- I developed a patch. See attachment. It allows defining another status that
will be applied to the transactions that are imported as "not cleared".
- It is my first contribution, it should be taken with all due prudence.

Modified: gnucash/trunk/src/import-export/qif-import/druid-qif-import.c
===================================================================
--- gnucash/trunk/src/import-export/qif-import/druid-qif-import.c	2010-12-31 12:25:18 UTC (rev 20014)
+++ gnucash/trunk/src/import-export/qif-import/druid-qif-import.c	2010-12-31 12:25:30 UTC (rev 20015)
@@ -56,6 +56,7 @@
 #define DRUID_QIF_IMPORT_CM_CLASS "druid-qif-import"
 #define GCONF_SECTION "dialogs/import/qif"
 #define GCONF_NAME_SHOW_DOC "show_doc"
+#define GCONF_NAME_DEFAULT_TRANSACTION_STATUS "default_status"
 
 #define PREV_ROW "prev_row"
 
@@ -165,6 +166,7 @@
 
     SCM       imported_account_tree;
     SCM       match_transactions;
+    SCM       transaction_status;
     int       selected_transaction;
 };
 
@@ -2637,12 +2639,13 @@
     /* This step will fill 70% of the bar. */
     gnc_progress_dialog_push(wind->convert_progress, 0.7);
     retval = scm_apply(qif_to_gnc,
-                       SCM_LIST7(wind->imported_files,
+                       SCM_LIST8(wind->imported_files,
                                  wind->acct_map_info,
                                  wind->cat_map_info,
                                  wind->memo_map_info,
                                  wind->security_hash,
                                  scm_makfrom0str(currname),
+                                 wind->transaction_status, 
                                  progress),
                        SCM_EOL);
     gnc_progress_dialog_pop(wind->convert_progress);
@@ -3214,6 +3217,8 @@
 get_preferences(QIFImportWindow *wind)
 {
     GError * err = NULL;
+    gchar *status_pref = NULL;
+    gchar tmp_transaction_status = 'n';
 
     g_return_if_fail(wind);
 
@@ -3231,6 +3236,27 @@
         g_warning("QIF import: Documentation pages will be shown by default.");
         wind->show_doc_pages = TRUE;
     }
+
+    /* Clear / Reconcile transaction if not specified in QIF file. */
+    status_pref = gnc_gconf_get_string(
+                    GCONF_SECTION, GCONF_NAME_DEFAULT_TRANSACTION_STATUS, &err);
+    if (err != NULL)
+    {
+        g_warning("QIF import: gnc_gconf_get_string error: %s", err->message);
+        g_error_free(err);
+        g_warning("QIF import: Couldn't get %s setting from gconf.",
+                  GCONF_NAME_DEFAULT_TRANSACTION_STATUS);
+    } else {
+        if (g_strcmp0(status_pref, "cleared") == 0)
+        {
+            tmp_transaction_status = 'c';
+        } else if (g_strcmp0(status_pref, "reconciled") == 0)
+        {
+            tmp_transaction_status = 'y';
+        }
+    }
+    g_free(status_pref);
+    wind->transaction_status = SCM_MAKE_CHAR(tmp_transaction_status);
 }
 
 

Modified: gnucash/trunk/src/import-export/qif-import/qif-to-gnc.scm
===================================================================
--- gnucash/trunk/src/import-export/qif-import/qif-to-gnc.scm	2010-12-31 12:25:18 UTC (rev 20014)
+++ gnucash/trunk/src/import-export/qif-import/qif-to-gnc.scm	2010-12-31 12:25:30 UTC (rev 20015)
@@ -215,7 +215,9 @@
 (define (qif-import:qif-to-gnc qif-files-list
                                qif-acct-map qif-cat-map
                                qif-memo-map stock-map
-                               default-currency-name progress-dialog)
+                               default-currency-name
+                               transaction-status-pref
+                               progress-dialog)
 
   ;; This procedure does all the work. We'll define it, then call it safely.
   (define (private-convert)
@@ -392,6 +394,7 @@
                                                  qif-acct-map
                                                  qif-cat-map
                                                  qif-memo-map
+                                                 transaction-status-pref
                                                  progress-dialog)
 
                   ;; rebalance and commit everything
@@ -423,6 +426,7 @@
 (define (qif-import:qif-xtn-to-gnc-xtn qif-xtn qif-file gnc-xtn
                                        gnc-acct-hash
                                        qif-acct-map qif-cat-map qif-memo-map
+                                       transaction-status-pref
                                        progress-dialog)
   (let ((splits (qif-xtn:splits qif-xtn))
         (gnc-near-split (xaccMallocSplit (gnc-get-current-book)))
@@ -490,10 +494,15 @@
 	      ;; the debit/credit lines. See bug 495219 for more information.
 	      (xaccTransSetNotes gnc-xtn qif-memo)))
 
+    ;; Look for the transaction status (QIF "C" line). When it exists, apply
+    ;; the cleared (c) or reconciled (y) status to the split. Otherwise, apply
+    ;; user preference.
     (if (eq? qif-cleared 'cleared)
-        (xaccSplitSetReconcile gnc-near-split #\c))
-    (if (eq? qif-cleared 'reconciled)
-        (xaccSplitSetReconcile gnc-near-split #\y))
+        (xaccSplitSetReconcile gnc-near-split #\c)
+        (if (eq? qif-cleared 'reconciled)
+            (xaccSplitSetReconcile gnc-near-split #\y)
+            ;; Apply user preference by default.
+            (xaccSplitSetReconcile gnc-near-split transaction-status-pref)))
 
     (if (not qif-security)
         (begin

Modified: gnucash/trunk/src/import-export/qif-import/qif.glade
===================================================================
--- gnucash/trunk/src/import-export/qif-import/qif.glade	2010-12-31 12:25:18 UTC (rev 20014)
+++ gnucash/trunk/src/import-export/qif-import/qif.glade	2010-12-31 12:25:30 UTC (rev 20015)
@@ -1380,9 +1380,76 @@
           </packing>
         </child>
         <child>
-          <placeholder/>
+          <widget class="GtkRadioButton" id="gconf/dialogs/import/qif/default_status/reconciled">
+            <property name="label" translatable="yes">_Reconciled</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="tooltip" translatable="yes">When the status is not specified in a QIF file, the transactions are marked as reconciled.</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+          </widget>
+          <packing>
+            <property name="top_attach">6</property>
+            <property name="bottom_attach">7</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
+            <property name="x_padding">12</property>
+          </packing>
         </child>
         <child>
+          <widget class="GtkRadioButton" id="gconf/dialogs/import/qif/default_status/cleared">
+            <property name="label" translatable="yes">_Cleared</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="tooltip" translatable="yes">When the status is not specified in a QIF file, the transactions are marked as cleared.</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+            <property name="group">gconf/dialogs/import/qif/default_status/reconciled</property>
+          </widget>
+          <packing>
+            <property name="top_attach">5</property>
+            <property name="bottom_attach">6</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
+            <property name="x_padding">12</property>
+          </packing>
+        </child>
+         <child>
+             <widget class="GtkRadioButton" id="gconf/dialogs/import/qif/default_status/not_cleared">
+            <property name="label" translatable="yes">_Not cleared</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="tooltip" translatable="yes">When the status is not specified in a QIF file, the transactions are marked as not cleared.</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+            <property name="group">gconf/dialogs/import/qif/default_status/reconciled</property>
+          </widget>
+          <packing>
+            <property name="top_attach">4</property>
+            <property name="bottom_attach">5</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
+            <property name="x_padding">12</property>
+          </packing>
+        </child>
+        <child>
+           <widget class="GtkLabel" id="qif_default_transation_status">
+             <property name="visible">True</property>
+             <property name="xalign">0</property>
+             <property name="label" translatable="yes">Default transaction status (overridden by the status given by the QIF file):</property>
+           </widget>
+           <packing>
+             <property name="right_attach">4</property>
+             <property name="top_attach">2</property>
+             <property name="bottom_attach">3</property>
+             <property name="x_options">GTK_FILL</property>
+             <property name="y_options"></property>
+           </packing>
+        </child>
+        <child>
           <placeholder/>
         </child>
         <child>

Modified: gnucash/trunk/src/import-export/qif-import/schemas/apps_gnucash_import_qif.schemas.in
===================================================================
--- gnucash/trunk/src/import-export/qif-import/schemas/apps_gnucash_import_qif.schemas.in	2010-12-31 12:25:18 UTC (rev 20014)
+++ gnucash/trunk/src/import-export/qif-import/schemas/apps_gnucash_import_qif.schemas.in	2010-12-31 12:25:30 UTC (rev 20015)
@@ -16,5 +16,19 @@
       </locale>
     </schema>
 
+    <schema>
+      <key>/schemas/apps/gnucash/dialogs/import/qif/default_status</key>
+      <applyto>/apps/gnucash/dialogs/import/qif/default_status</applyto>
+      <owner>gnucash</owner>
+      <type>string</type>
+      <default>not_cleared</default>
+      <locale name="C">
+        <short>Default QIF transaction status</short>
+        <long>
+          Default status for QIF transaction when not specified in QIF file.
+        </long>
+      </locale>
+    </schema>
+
   </schemalist>
 </gconfschemafile>



More information about the gnucash-changes mailing list