gnucash master: [budget-feature] move unset_feature call to gnc_budget_gui_delete_budget

Christopher Lam clam at code.gnucash.org
Tue Nov 1 12:36:17 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/05ffd3d4 (commit)
	from  https://github.com/Gnucash/gnucash/commit/6c7e50ef (commit)



commit 05ffd3d4eb8230b8fb49bacbd5a2ede74a92beb6
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Oct 29 15:06:06 2022 +0800

    [budget-feature] move unset_feature call to gnc_budget_gui_delete_budget
    
    because gnc_budget_gui_delete_budget is a more general function to
    delete a budget.

diff --git a/gnucash/gnome/gnc-plugin-budget.c b/gnucash/gnome/gnc-plugin-budget.c
index be38d71e8..c135f98c3 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 a2479635f..3106564dc 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 c1834f062..67391175a 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))
-        return FALSE;
+    /* 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 (!gnc_budget_get_default (book))
+    if (has_no_budgets || featured)
         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;
 }



Summary of changes:
 gnucash/gnome/gnc-plugin-budget.c      |  8 --------
 gnucash/gnome/gnc-plugin-page-budget.c |  8 ++++++++
 libgnucash/engine/ScrubBudget.c        | 22 ++++++++++++++--------
 3 files changed, 22 insertions(+), 16 deletions(-)



More information about the gnucash-changes mailing list