r21389 - gnucash/trunk/src/business/business-gnome - Fix failed assertion if there is no A/R or A/P account involved.

Christian Stimming cstim at code.gnucash.org
Sat Oct 8 05:20:08 EDT 2011


Author: cstim
Date: 2011-10-08 05:20:07 -0400 (Sat, 08 Oct 2011)
New Revision: 21389
Trac: http://svn.gnucash.org/trac/changeset/21389

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-payment.c
Log:
Fix failed assertion if there is no A/R or A/P account involved.

Modified: gnucash/trunk/src/business/business-gnome/dialog-payment.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-payment.c	2011-10-08 09:19:54 UTC (rev 21388)
+++ gnucash/trunk/src/business/business-gnome/dialog-payment.c	2011-10-08 09:20:07 UTC (rev 21389)
@@ -837,17 +837,19 @@
         return NULL;
     if (countAssetAccounts(slist) == 0)
     {
-        g_message("No asset splits in txn");
+        g_message("No asset splits in txn \"%s\"; cannot use this for assigning a payment.",
+                  xaccTransGetDescription(txn));
         return NULL;
     }
 
     {
-        Split *xferaccount_split = getFirstAssetAccountSplit(slist);
-        Split *postaccount_split = getFirstAPARAccountSplit(slist);
-        gnc_numeric amount = xaccSplitGetValue(xferaccount_split);
+        Split *assetaccount_split = getFirstAssetAccountSplit(slist);
+        Split *postaccount_split = getFirstAPARAccountSplit(slist); // watch out: Might be NULL
+        gnc_numeric amount = xaccSplitGetValue(assetaccount_split);
 
         PaymentWindow *pw = gnc_ui_payment_new(owner,
                                                qof_instance_get_book(QOF_INSTANCE(txn)));
+        g_assert(assetaccount_split); // we can rely on this because of the countAssetAccounts() check above
 
         // Fill in the values from the given txn
         pw->pre_existing_txn = txn;
@@ -858,8 +860,9 @@
             gnc_ui_payment_window_set_date(pw, &txn_date);
         }
         gnc_ui_payment_window_set_amount(pw, gnc_numeric_abs(amount));
-        gnc_ui_payment_window_set_xferaccount(pw, xaccSplitGetAccount(xferaccount_split));
-        gnc_ui_payment_window_set_postaccount(pw, xaccSplitGetAccount(postaccount_split));
+        gnc_ui_payment_window_set_xferaccount(pw, xaccSplitGetAccount(assetaccount_split));
+        if (postaccount_split)
+            gnc_ui_payment_window_set_postaccount(pw, xaccSplitGetAccount(postaccount_split));
 
         return pw;
     }



More information about the gnucash-changes mailing list