diff --git a/gnucash/gnome/gnc-plugin-budget.c b/gnucash/gnome/gnc-plugin-budget.c index be38d71e84..c135f98c31 100644 --- a/gnucash/gnome/gnc-plugin-budget.c +++ b/gnucash/gnome/gnc-plugin-budget.c @@ -301,14 +301,6 @@ gnc_plugin_budget_cmd_delete_budget (GtkAction *action, if (!bgt) return; gnc_budget_gui_delete_budget (bgt); - - if (qof_collection_count (qof_book_get_collection (book, GNC_ID_BUDGET)) == 0) - { - gnc_features_set_unused (book, GNC_FEATURE_BUDGET_UNREVERSED); - PWARN ("Removing feature BUDGET_UNREVERSED. No budgets left."); - } - - } /************************************************************ diff --git a/gnucash/gnome/gnc-plugin-page-budget.c b/gnucash/gnome/gnc-plugin-page-budget.c index a2479635f9..3106564dce 100644 --- a/gnucash/gnome/gnc-plugin-page-budget.c +++ b/gnucash/gnome/gnc-plugin-page-budget.c @@ -945,8 +945,16 @@ gnc_budget_gui_delete_budget (GncBudget *budget) if (gnc_verify_dialog (NULL, FALSE, _("Delete %s?"), name)) { + QofBook* book = gnc_get_current_book (); + gnc_suspend_gui_refresh (); gnc_budget_destroy (budget); + + if (qof_collection_count (qof_book_get_collection (book, GNC_ID_BUDGET)) == 0) + { + gnc_features_set_unused (book, GNC_FEATURE_BUDGET_UNREVERSED); + PWARN ("No budgets left. Removing feature BUDGET_UNREVERSED."); + } // Views should close themselves because the CM will notify them. gnc_resume_gui_refresh (); } diff --git a/libgnucash/engine/ScrubBudget.c b/libgnucash/engine/ScrubBudget.c index c1834f0621..67391175a9 100644 --- a/libgnucash/engine/ScrubBudget.c +++ b/libgnucash/engine/ScrubBudget.c @@ -193,18 +193,24 @@ maybe_scrub_budget (QofInstance* data, gpointer user_data) gboolean gnc_maybe_scrub_all_budget_signs (QofBook *book) { - Account* root = gnc_book_get_root_account (book); - gchar *retval = NULL; + QofCollection* collection = qof_book_get_collection (book, GNC_ID_BUDGET); + gboolean has_no_budgets = (qof_collection_count (collection) == 0); + gboolean featured = gnc_features_check_used (book, GNC_FEATURE_BUDGET_UNREVERSED); - if (gnc_features_check_used (book, GNC_FEATURE_BUDGET_UNREVERSED)) + /* If there are no budgets, there shouldn't be feature! */ + if (has_no_budgets && featured) + { + gnc_features_set_unused (book, GNC_FEATURE_BUDGET_UNREVERSED); + PWARN ("There are no budgets, removing feature BUDGET_UNREVERSED"); + } + + if (has_no_budgets || featured) return FALSE; - if (!gnc_budget_get_default (book)) - return FALSE; - - qof_collection_foreach (qof_book_get_collection (book, GNC_ID_BUDGET), - maybe_scrub_budget, root); - + /* There are budgets and feature is not set. Scrub, and set + feature. Return TRUE to show budget fix warning. */ + qof_collection_foreach (collection, maybe_scrub_budget, + gnc_book_get_root_account (book)); gnc_features_set_used (book, GNC_FEATURE_BUDGET_UNREVERSED); return TRUE; }