From 67243cd0ab8ccbdf0df968c4d2a93e20c943daa9 Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Mon, 9 Dec 2002 19:33:51 +0000 Subject: [PATCH] * src/gnome/window-acct-tree.c: Disallow the deletion of accounts with ReadOnly Transacation in them. You must first "delete" the RO Txns before you delete the account. Fix for bug# 100727 (although it requires invoice unposting to work). git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7667 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 7 +++++ src/gnome/window-acct-tree.c | 55 +++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b9ed7b8a7..e60fa1980e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-12-09 Derek Atkins + + * src/gnome/window-acct-tree.c: Disallow the deletion of accounts + with ReadOnly Transacation in them. You must first "delete" the + RO Txns before you delete the account. Fix for bug# 100727 (although + it requires invoice unposting to work). + 2002-12-9 Benoit Grégoire * src/import-export/import-main-matcher.c: * src/import-export/generic-import.glade: Change colors, remove diff --git a/src/gnome/window-acct-tree.c b/src/gnome/window-acct-tree.c index fa04477acf..afbc8042f5 100644 --- a/src/gnome/window-acct-tree.c +++ b/src/gnome/window-acct-tree.c @@ -396,13 +396,32 @@ gnc_acct_tree_window_toolbar_add_account_cb (GtkWidget *widget, gpointer data) * and return the same value to stop walking the account tree if * appropriate. ********************************************************************/ +typedef struct _delete_helper { + gboolean has_splits; + gboolean has_ro_splits; +} delete_helper_t; + static gpointer delete_account_helper (Account *account, gpointer data) { - gboolean *has_splits = data; + delete_helper_t *helper_res = data; + GList *splits; - *has_splits = (xaccAccountGetSplitList(account) != NULL); - return (gpointer)*has_splits; + splits = xaccAccountGetSplitList(account); + if (splits) { + helper_res->has_splits = TRUE; + while (splits) { + Split *s = splits->data; + Transaction *txn = xaccSplitGetParent (s); + if (xaccTransGetReadOnly (txn)) { + helper_res->has_ro_splits = TRUE; + break; + } + splits = splits->next; + } + } + + return (gpointer)(helper_res->has_splits || helper_res->has_ro_splits); } static void @@ -421,22 +440,44 @@ gnc_acct_tree_window_delete_common (Account *account) _("One (or more) children of this account contain\n" "transactions. Are you sure you want to delete the\n" "%s account and all its children?"); + const char *acct_has_ro_splits = + _("This account contains read-only transactions. You " + "may not delete %s."); + const char *child_has_ro_splits = + _("One (or more) children of this account contains " + "read-only transactions. You may not delete %s."); const char *format; char *name; + GList *splits; name = xaccAccountGetFullName(account, gnc_get_account_separator ()); if (!name) name = g_strdup (""); - if (xaccAccountGetSplitList(account) != NULL) { + if ((splits = xaccAccountGetSplitList(account)) != NULL) { + /* Check for RO txns -- if there are any, disallow deletion */ + for ( ; splits ; splits = splits->next) { + Split *s = splits->data; + Transaction *txn = xaccSplitGetParent (s); + if (xaccTransGetReadOnly (txn)) { + gnc_error_dialog (acct_has_ro_splits, name); + return; + } + } format = acct_has_splits; } else { AccountGroup *children; - gboolean has_splits = FALSE; + delete_helper_t delete_res = { FALSE, FALSE }; children = xaccAccountGetChildren(account); - xaccGroupForEachAccount(children, delete_account_helper, &has_splits, TRUE); - if (has_splits) + xaccGroupForEachAccount(children, delete_account_helper, &delete_res, TRUE); + + /* Check for RO txns in the children -- disallow deletion if there are any */ + if (delete_res.has_ro_splits) { + gnc_error_dialog (child_has_ro_splits, name); + return; + + } else if (delete_res.has_splits) format= child_has_splits; else format = children ? no_splits : no_splits_no_children;