Add feature GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE

When the above function is activated, the slot 'equity type' is used and
set in relation to opening balances and the checkbox for marking the
opening balance in the accounts dialog can be changed.
This commit is contained in:
Ralf Habacker 2020-10-28 07:14:10 +01:00
parent 2bdc7dd1c9
commit 63580d91ba
5 changed files with 30 additions and 6 deletions

View File

@ -218,9 +218,14 @@ gnc_account_opening_balance_button_update (AccountWindow *aw, gnc_commodity *com
gtk_widget_set_sensitive (aw->opening_balance_button, FALSE);
return;
}
/* The opening balance flag can be edited, if there is no opening balance account
* or we are editing the only opening balance account and it has no splits assigned.
/* The opening balance flag can be edited, if the associated feature is enabled and
* there is no opening balance account or we are editing the only opening balance account
* and it has no splits assigned.
*/
if (!gnc_using_equity_type_opening_balance_account (gnc_get_current_book()))
return;
switch(aw->dialog_type)
{
case EDIT_ACCOUNT:

View File

@ -195,6 +195,15 @@ gnc_reverse_budget_balance (const Account *account, gboolean unreversed)
return FALSE;
}
gboolean gnc_using_equity_type_opening_balance_account (QofBook* book)
{
return gnc_features_check_used (book, GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE);
}
void gnc_set_use_equity_type_opening_balance_account (QofBook* book)
{
gnc_features_set_used (book, GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE);
}
gchar *
gnc_get_default_directory (const gchar *section)
@ -960,13 +969,16 @@ gnc_find_or_create_equity_account (Account *root,
gboolean base_name_exists;
const char *base_name;
char *name;
gboolean use_eq_op_feature;
g_return_val_if_fail (equity_type >= 0, NULL);
g_return_val_if_fail (equity_type < NUM_EQUITY_TYPES, NULL);
g_return_val_if_fail (currency != NULL, NULL);
g_return_val_if_fail (root != NULL, NULL);
if (equity_type == EQUITY_OPENING_BALANCE)
use_eq_op_feature = equity_type == EQUITY_OPENING_BALANCE && gnc_using_equity_type_opening_balance_account (gnc_get_current_book ());
if (use_eq_op_feature)
{
account = gnc_account_lookup_by_opening_balance (root, currency);
if (account)
@ -993,7 +1005,7 @@ gnc_find_or_create_equity_account (Account *root,
if (account &&
gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
{
if (equity_type == EQUITY_OPENING_BALANCE)
if (use_eq_op_feature)
xaccAccountSetIsOpeningBalance (account, TRUE);
return account;
}
@ -1009,7 +1021,7 @@ gnc_find_or_create_equity_account (Account *root,
if (account &&
gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
{
if (equity_type == EQUITY_OPENING_BALANCE)
if (use_eq_op_feature)
xaccAccountSetIsOpeningBalance (account, TRUE);
return account;
}
@ -1042,7 +1054,7 @@ gnc_find_or_create_equity_account (Account *root,
xaccAccountSetType (account, ACCT_TYPE_EQUITY);
xaccAccountSetCommodity (account, currency);
if (equity_type == EQUITY_OPENING_BALANCE)
if (use_eq_op_feature)
xaccAccountSetIsOpeningBalance (account, TRUE);
xaccAccountBeginEdit (parent);

View File

@ -56,6 +56,11 @@ gboolean gnc_using_unreversed_budgets (QofBook* book);
* don't match, return FALSE. */
gboolean gnc_reverse_budget_balance (const Account *account, gboolean unreversed);
/* Backward compatibility *******************************************
* Return that book's support opening balance accounts by equity type slot */
void gnc_set_use_equity_type_opening_balance_account (QofBook* book);
gboolean gnc_using_equity_type_opening_balance_account (QofBook* book);
/* Default directory sections ***************************************/
#define GNC_PREFS_GROUP_OPEN_SAVE "dialogs.open-save"
#define GNC_PREFS_GROUP_EXPORT "dialogs.export-accounts"

View File

@ -51,6 +51,7 @@ static gncFeature known_features[] =
{ GNC_FEATURE_REG_SORT_FILTER, "Store the register sort and filter settings in .gcm metadata file (requires at least GnuCash 3.3)"},
{ GNC_FEATURE_BUDGET_UNREVERSED, "Store budget amounts unreversed (i.e. natural) signs (requires at least Gnucash 3.8)"},
{ GNC_FEATURE_BUDGET_SHOW_EXTRA_ACCOUNT_COLS, "Show extra account columns in the Budget View (requires at least Gnucash 3.8)"},
{ GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE, GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE " (requires at least Gnucash 4.3)" },
{ NULL },
};

View File

@ -55,6 +55,7 @@ extern "C" {
#define GNC_FEATURE_REG_SORT_FILTER "Register sort and filter settings stored in .gcm file"
#define GNC_FEATURE_BUDGET_UNREVERSED "Use natural signs in budget amounts"
#define GNC_FEATURE_BUDGET_SHOW_EXTRA_ACCOUNT_COLS "Show extra account columns in the Budget View"
#define GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE "Use a dedicated opening balance account identified by an 'equity-type' slot"
/** @} */