Fix failed assertion if there is no A/R or A/P account involved.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21389 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2011-10-08 09:20:07 +00:00
parent 049b06e37a
commit 40000ee934

View File

@ -837,17 +837,19 @@ PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn)
return NULL; return NULL;
if (countAssetAccounts(slist) == 0) 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; return NULL;
} }
{ {
Split *xferaccount_split = getFirstAssetAccountSplit(slist); Split *assetaccount_split = getFirstAssetAccountSplit(slist);
Split *postaccount_split = getFirstAPARAccountSplit(slist); Split *postaccount_split = getFirstAPARAccountSplit(slist); // watch out: Might be NULL
gnc_numeric amount = xaccSplitGetValue(xferaccount_split); gnc_numeric amount = xaccSplitGetValue(assetaccount_split);
PaymentWindow *pw = gnc_ui_payment_new(owner, PaymentWindow *pw = gnc_ui_payment_new(owner,
qof_instance_get_book(QOF_INSTANCE(txn))); 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 // Fill in the values from the given txn
pw->pre_existing_txn = txn; pw->pre_existing_txn = txn;
@ -858,8 +860,9 @@ PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn)
gnc_ui_payment_window_set_date(pw, &txn_date); 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_amount(pw, gnc_numeric_abs(amount));
gnc_ui_payment_window_set_xferaccount(pw, xaccSplitGetAccount(xferaccount_split)); gnc_ui_payment_window_set_xferaccount(pw, xaccSplitGetAccount(assetaccount_split));
gnc_ui_payment_window_set_postaccount(pw, xaccSplitGetAccount(postaccount_split)); if (postaccount_split)
gnc_ui_payment_window_set_postaccount(pw, xaccSplitGetAccount(postaccount_split));
return pw; return pw;
} }