Add support for the opening balance accounts flag

Up to now, opening balance accounts have been identified by means of
fixed names and their translations, which in some cases is not
appropriate.

With this commit, therefore, opening balance accounts can now be
identified by a special slot, which should solve the above problem.

in gnc_find_or_create_equity_account(), when querying the
EQUITY_OPENING_BALANCE type, the system now first searches for an
account with an existing 'equity-type' slot having the value
'opening-balance' and returns it as an opening balance account if
one exists. If no corresponding account is found, the search is
continued as before. An account found in the process is automatically
given the status of an opening balance account (it is given an
'equity-type' slot with value 'opening-balance') to simplify the
future search.

The opening balance status of an account is visualized in the account
settings dialog with a check box. If a Gnucash file does not yet contain
an opening balance account, one can be selected in the account settings
dialog.

https://bugs.gnucash.org/show_bug.cgi?id=797836
This commit is contained in:
Ralf Habacker
2020-09-19 10:53:08 +02:00
parent 573f7aaa0b
commit f8dcd23023
9 changed files with 217 additions and 3 deletions

View File

@@ -955,7 +955,7 @@ gnc_find_or_create_equity_account (Account *root,
gnc_commodity *currency)
{
Account *parent;
Account *account;
Account *account = NULL;
gboolean name_exists;
gboolean base_name_exists;
const char *base_name;
@@ -966,6 +966,13 @@ gnc_find_or_create_equity_account (Account *root,
g_return_val_if_fail (currency != NULL, NULL);
g_return_val_if_fail (root != NULL, NULL);
if (equity_type == EQUITY_OPENING_BALANCE)
{
account = gnc_account_lookup_by_opening_balance (root, currency);
if (account)
return account;
}
base_name = equity_base_name (equity_type);
account = gnc_account_lookup_by_name(root, base_name);
@@ -985,7 +992,11 @@ gnc_find_or_create_equity_account (Account *root,
if (account &&
gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
{
if (equity_type == EQUITY_OPENING_BALANCE)
xaccAccountSetIsOpeningBalance (account, TRUE);
return account;
}
name = g_strconcat (base_name, " - ",
gnc_commodity_get_mnemonic (currency), NULL);
@@ -997,7 +1008,11 @@ gnc_find_or_create_equity_account (Account *root,
if (account &&
gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
{
if (equity_type == EQUITY_OPENING_BALANCE)
xaccAccountSetIsOpeningBalance (account, TRUE);
return account;
}
/* Couldn't find one, so create it */
if (name_exists && base_name_exists)
@@ -1027,6 +1042,9 @@ gnc_find_or_create_equity_account (Account *root,
xaccAccountSetType (account, ACCT_TYPE_EQUITY);
xaccAccountSetCommodity (account, currency);
if (equity_type == EQUITY_OPENING_BALANCE)
xaccAccountSetIsOpeningBalance (account, TRUE);
xaccAccountBeginEdit (parent);
gnc_account_append_child (parent, account);
xaccAccountCommitEdit (parent);