gnucash stable: Bug 798983 - Empty Orphan account appears after entering transactions in 5.3
John Ralls
jralls at code.gnucash.org
Fri Sep 8 18:26:10 EDT 2023
Updated via https://github.com/Gnucash/gnucash/commit/89360252 (commit)
from https://github.com/Gnucash/gnucash/commit/76ac345e (commit)
commit 89360252fb597077df82edc1d208d381f66ca828
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Sep 8 15:08:44 2023 -0700
Bug 798983 - Empty Orphan account appears after entering transactions in 5.3
Caused by trying to set the account on the blank split. The blank split
was present because the method used to clear the split list for the
receiving transaction in gnc_float_txn_to_txn_swap_accounts only removed
splits that belong to the transaction, and the blank split doesn't.
Adds new function xaccTransClearSplits to do a more thorough job.
Also improve the documentation for xaccSplitDestroy to better explain when
a transaction will be destroyed if it empties the split list.
# Please enter the commit message for your
changes. Lines starting
diff --git a/gnucash/register/ledger-core/split-register-copy-ops.c b/gnucash/register/ledger-core/split-register-copy-ops.c
index a7d36aff35..fcc688009c 100644
--- a/gnucash/register/ledger-core/split-register-copy-ops.c
+++ b/gnucash/register/ledger-core/split-register-copy-ops.c
@@ -400,9 +400,8 @@ void gnc_float_txn_to_txn_swap_accounts (const FloatingTxn *ft, Transaction *txn
xaccTransSetDatePostedSecs (txn, ft->m_date_posted);
/* strip off the old splits */
- while (xaccTransCountSplits (txn))
- xaccSplitDestroy (xaccTransGetSplit (txn, 0));
-
+ xaccTransClearSplits(txn);
+
/* and put on the new ones! Please note they go in the *same*
order as in the original transaction. This is important. */
for (iter = ft->m_splits; iter; iter = iter->next)
diff --git a/libgnucash/engine/Split.h b/libgnucash/engine/Split.h
index fffc8409cc..f33b63b5b5 100644
--- a/libgnucash/engine/Split.h
+++ b/libgnucash/engine/Split.h
@@ -108,9 +108,10 @@ void xaccSplitReinit(Split * split);
* leaving the accounting structure out-of-balance or otherwise
* inconsistent.
*
- * If the deletion of the split leaves the transaction with no splits,
- * then the transaction will be marked for deletion. (It will not be
- * deleted until the xaccTransCommitEdit() routine is called.)
+ * It begins and commits an edit on the transaction, so if after the
+ * split is removed the transaction has no more splits and if is not
+ * open it too will be destroyed, as it will if the outer edits are
+ * committed without adding transactions.
*
* @return TRUE upon successful deletion of the split. FALSE when
* the parenting Transaction is a read-only one.
diff --git a/libgnucash/engine/Transaction.c b/libgnucash/engine/Transaction.c
index 46caf5b5d5..2ea78062ff 100644
--- a/libgnucash/engine/Transaction.c
+++ b/libgnucash/engine/Transaction.c
@@ -2232,6 +2232,15 @@ xaccTransSetIsClosingTxn (Transaction *trans, gboolean is_closing)
/********************************************************************\
\********************************************************************/
+void
+xaccTransClearSplits(Transaction* trans)
+{
+ xaccTransBeginEdit(trans);
+ FOR_EACH_SPLIT(trans, xaccSplitDestroy(s));
+ g_list_free (trans->splits);
+ trans->splits = NULL;
+ xaccTransCommitEdit(trans);
+}
Split *
xaccTransGetSplit (const Transaction *trans, int i)
diff --git a/libgnucash/engine/Transaction.h b/libgnucash/engine/Transaction.h
index 1ecd58ffd3..04b7f3cebd 100644
--- a/libgnucash/engine/Transaction.h
+++ b/libgnucash/engine/Transaction.h
@@ -359,6 +359,17 @@ void xaccTransSetIsClosingTxn (Transaction *trans, gboolean is_closing)
/** Returns whether this transaction is a "closing transaction" */
gboolean xaccTransGetIsClosingTxn (const Transaction *trans);
+/** Remove all splits from the transaction
+ *
+ * Clears the split list of the transaction. All splits that the
+ * transaction still owns will be destroyed, and others will be
+ * unlinked.
+ *
+ * Opens and commits an edit on the transaction, so this will destroy
+ * the transaction if it isn't already open, as will committing the
+ * outer edits if new splits are not added before hand.
+ */
+void xaccTransClearSplits(Transaction* trans);
/** Add a split to the transaction
*
Summary of changes:
gnucash/register/ledger-core/split-register-copy-ops.c | 5 ++---
libgnucash/engine/Split.h | 7 ++++---
libgnucash/engine/Transaction.c | 9 +++++++++
libgnucash/engine/Transaction.h | 11 +++++++++++
4 files changed, 26 insertions(+), 6 deletions(-)
More information about the gnucash-changes
mailing list