Skip to content

Commit

Permalink
[3/3][gnc-plugin-budget.c] set/unset feature creating/deleting budget
Browse files Browse the repository at this point in the history
If creating budget, and unfeatured, set feature.
If deleting budget, and num(budgets) == 0 afterwards, unset feature
  • Loading branch information
christopherlam committed Dec 3, 2021
1 parent 6070aec commit 99c2c82
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gnucash/gnome/gnc-plugin-budget.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "gnc-tree-model-budget.h"

#include "qof.h"
#include "gnc-features.h"
#include "gnc-ui-util.h"
#include "gnc-ui.h"
#include "gnc-component-manager.h"
Expand Down Expand Up @@ -158,9 +159,17 @@ gnc_plugin_budget_cmd_new_budget (GtkAction *action,
GncBudget *budget;
GncPluginPage *page;
gchar *description, *date;
QofBook *book = gnc_get_current_book();

g_return_if_fail (user_data != NULL);

if (!gnc_features_check_used (book, GNC_FEATURE_BUDGET_UNREVERSED))
{
gnc_features_set_used (book, GNC_FEATURE_BUDGET_UNREVERSED);
PWARN ("Setting feature BUDGET_UNREVERSED. This book now requires \
GnuCash 3.8 or later.");
}

budget = gnc_budget_new (gnc_get_current_book());
page = gnc_plugin_page_budget_new (budget);

Expand Down Expand Up @@ -259,6 +268,14 @@ 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

0 comments on commit 99c2c82

Please sign in to comment.