gnucash maint: Bug 798385 - Description to often only "Landesbank Hessen-Thuringen Girozentrale"

John Ralls jralls at code.gnucash.org
Fri Aug 19 15:18:36 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/1b384df6 (commit)
	from  https://github.com/Gnucash/gnucash/commit/12419e28 (commit)



commit 1b384df62249d0f4601858a9839d583dc33f18e7
Author: John Ralls <jralls at ceridwen.us>
Date:   Fri Aug 19 12:18:07 2022 -0700

    Bug 798385 - Description to often only "Landesbank Hessen-Thuringen Girozentrale"
    
    Prepend the Ulitimate Creditor or Ultimate Debtor to the transaction description.

diff --git a/gnucash/import-export/aqb/gnc-ab-utils.c b/gnucash/import-export/aqb/gnc-ab-utils.c
index d6d5b01dd..e5df69225 100644
--- a/gnucash/import-export/aqb/gnc-ab-utils.c
+++ b/gnucash/import-export/aqb/gnc-ab-utils.c
@@ -453,7 +453,7 @@ gnc_ab_get_purpose (const AB_TRANSACTION *ab_trans, gboolean is_ofx)
          * meaning. Some banks place valuable text into the transaction text,
          * hence we put this text in front of the purpose. */
         ab_transactionText = AB_Transaction_GetTransactionText (ab_trans);
-        if (ab_transactionText)
+        if (ab_transactionText && *ab_transactionText)
             gnc_description = g_strdup (ab_transactionText);
     }
 
@@ -474,44 +474,84 @@ gnc_ab_get_purpose (const AB_TRANSACTION *ab_trans, gboolean is_ofx)
     GWEN_StringList_free (ab_purpose);
 #endif
 
-    if (!gnc_description)
-        gnc_description = g_strdup ("");
-
     return gnc_description;
 }
 
+/* Ultimate Creditor and Ultimate Debtor are newish parameters added
+ * to SWIFT MT940 and CAMT.053 designating the originating
+ * payer or payee on the tranaction. It's unlikely, but still
+ * possible, that a bank would use both this markup and the Non-swift
+ * TransactionText or RemoteName tags.
+ */
+static gchar *
+ab_ultimate_creditor_debtor_to_gnc (const AB_TRANSACTION *ab_trans,
+                                    gboolean is_ofx)
+{
+#if AQBANKING_VERSION_INT < 60200
+    return NULL;
+#else
+    const gchar* ultimate;
+
+    if (is_ofx)
+        return NULL;
+
+    ultimate = AB_Transaction_GetUltimateCreditor (ab_trans);
+
+    if (!ultimate || !*ultimate)
+        ultimate = AB_Transaction_GetUltimateDebtor (ab_trans);
+
+    if (!ultimate || !*ultimate)
+        return NULL;
+
+    return g_strdup (ultimate);
+#endif
+}
+
 gchar *
 gnc_ab_description_to_gnc (const AB_TRANSACTION *ab_trans, gboolean is_ofx)
 {
     /* Description */
     gchar *description = gnc_ab_get_purpose (ab_trans, is_ofx);
     gchar *other_name = gnc_ab_get_remote_name (ab_trans);
-    gchar *retval;
+    gchar *ultimate = ab_ultimate_creditor_debtor_to_gnc (ab_trans, is_ofx);
+    gchar *retval = NULL;
 
-    if (other_name)
+    if (ultimate)
+        retval = ultimate;
+    if (description)
     {
-        if (description && *description)
+        if (retval)
         {
-            retval = g_strdup_printf ("%s; %s", description, other_name);
+            char *tmp = g_strdup_printf ("%s; %s", retval, description);
+            g_free (retval);
+            g_free (description);
+            retval = tmp;
         }
         else
         {
-            retval = g_strdup (other_name);
+            retval = description;
         }
     }
-    else
+
+    if (other_name)
     {
-        if (description && *description)
+        if (retval)
         {
-            retval = g_strdup (description);
+            char *tmp = g_strdup_printf ("%s; %s", retval, other_name);
+            g_free (retval);
+            g_free (other_name);
+            retval = tmp;
         }
         else
         {
-            retval = g_strdup (_("Unspecified"));
+            retval = other_name;
         }
     }
-    g_free (description);
-    g_free (other_name);
+
+    if (!retval)
+    {
+        retval = g_strdup (_("Unspecified"));
+    }
 
     return retval;
 }



Summary of changes:
 gnucash/import-export/aqb/gnc-ab-utils.c | 70 +++++++++++++++++++++++++-------
 1 file changed, 55 insertions(+), 15 deletions(-)



More information about the gnucash-changes mailing list