[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.
This commit is contained in:
Christopher Lam 2022-10-29 15:06:06 +08:00
parent 6c7e50efb2
commit 05ffd3d4eb
3 changed files with 23 additions and 17 deletions

View File

@ -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.");
}
}
/************************************************************

View File

@ -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 ();
}

View File

@ -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;
}