Skip to content

Commit

Permalink
[budget-feature] move unset_feature call to gnc_budget_gui_delete_budget
Browse files Browse the repository at this point in the history
because gnc_budget_gui_delete_budget is a more general function to
delete a budget.
  • Loading branch information
christopherlam committed Oct 31, 2022
1 parent 6c7e50e commit 05ffd3d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
8 changes: 0 additions & 8 deletions gnucash/gnome/gnc-plugin-budget.c
Expand Up @@ -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.");
}


}

/************************************************************
Expand Down
8 changes: 8 additions & 0 deletions gnucash/gnome/gnc-plugin-page-budget.c
Expand Up @@ -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 ();
}
Expand Down
22 changes: 14 additions & 8 deletions libgnucash/engine/ScrubBudget.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 05ffd3d

Please sign in to comment.