gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Mon Nov 16 12:28:37 EST 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/5de4fe5d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/63580d91 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/2bdc7dd1 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a2aca9da (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f8dcd230 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/573f7aaa (commit)
	 via  https://github.com/Gnucash/gnucash/commit/1cce12f8 (commit)
	from  https://github.com/Gnucash/gnucash/commit/fdbbc130 (commit)



commit 5de4fe5dff5e10e15cf3e8d7e67f31f39e5f7be1
Merge: fdbbc1305 63580d91b
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Nov 16 09:27:29 2020 -0800

    Merge Ralf Habacker's add-opening-balance-accounts into maint.


commit 63580d91ba0ef6de49c9c4f3a07771329e6ffdf7
Author: Ralf Habacker <ralf.habacker at freenet.de>
Date:   Wed Oct 28 07:14:10 2020 +0100

    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.

diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c
index 072ddfc99..3b69abded 100644
--- a/gnucash/gnome-utils/dialog-account.c
+++ b/gnucash/gnome-utils/dialog-account.c
@@ -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:
diff --git a/libgnucash/app-utils/gnc-ui-util.c b/libgnucash/app-utils/gnc-ui-util.c
index 86b61b296..81aa50682 100644
--- a/libgnucash/app-utils/gnc-ui-util.c
+++ b/libgnucash/app-utils/gnc-ui-util.c
@@ -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);
diff --git a/libgnucash/app-utils/gnc-ui-util.h b/libgnucash/app-utils/gnc-ui-util.h
index 881dd6a89..fa9839a30 100644
--- a/libgnucash/app-utils/gnc-ui-util.h
+++ b/libgnucash/app-utils/gnc-ui-util.h
@@ -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"
diff --git a/libgnucash/engine/gnc-features.c b/libgnucash/engine/gnc-features.c
index 163bd36f5..10ea1009c 100644
--- a/libgnucash/engine/gnc-features.c
+++ b/libgnucash/engine/gnc-features.c
@@ -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 },
 };
 
diff --git a/libgnucash/engine/gnc-features.h b/libgnucash/engine/gnc-features.h
index 0ceeee3eb..030c02531 100644
--- a/libgnucash/engine/gnc-features.h
+++ b/libgnucash/engine/gnc-features.h
@@ -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"
 
 /** @} */
 

commit 2bdc7dd1c9bbad343f16d4045a738a7ba27286a7
Author: Ralf Habacker <ralf.habacker at freenet.de>
Date:   Fri Oct 23 16:53:41 2020 +0200

    Update opening balance account on adding, editing and deleting accounts

diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c
index 3bf1d21ec..072ddfc99 100644
--- a/gnucash/gnome-utils/dialog-account.c
+++ b/gnucash/gnome-utils/dialog-account.c
@@ -894,6 +894,9 @@ gnc_common_ok (AccountWindow *aw)
         return FALSE;
     }
 
+    /* update opening balance account */
+    gnc_find_or_create_equity_account (root, EQUITY_OPENING_BALANCE, commodity);
+
     LEAVE("passed");
     return TRUE;
 }
diff --git a/gnucash/gnome/gnc-plugin-page-account-tree.c b/gnucash/gnome/gnc-plugin-page-account-tree.c
index 07654d1b7..fb2154dc4 100644
--- a/gnucash/gnome/gnc-plugin-page-account-tree.c
+++ b/gnucash/gnome/gnc-plugin-page-account-tree.c
@@ -1669,6 +1669,11 @@ gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPag
           gnc_account_n_children (account)))
     {
         do_delete_account (account, NULL, NULL, NULL);
+
+        /* update opening balance account */
+        gnc_find_or_create_equity_account (gnc_account_get_root(account),
+                                           EQUITY_OPENING_BALANCE,
+                                           xaccAccountGetCommodity (account));
         return;
     }
 
@@ -1703,8 +1708,15 @@ gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPag
                                 adopt.subtrans.new_account,
                                 adopt.subacct.new_account,
                                 adopt.delete_res) == GTK_RESPONSE_ACCEPT)
+    {
         do_delete_account (account, adopt.subacct.new_account,
                            adopt.subtrans.new_account, adopt.trans.new_account);
+
+        /* update opening balance account */
+        gnc_find_or_create_equity_account (gnc_account_get_root(account),
+                                           EQUITY_OPENING_BALANCE,
+                                           xaccAccountGetCommodity (account));
+    }
 }
 
 static int

commit a2aca9da66e9c5eeb38484629907f4bb8df2af1b
Author: Ralf Habacker <ralf.habacker at freenet.de>
Date:   Fri Oct 23 14:30:42 2020 +0200

    Do not create additional opening balance account on creating new gnucash file
    
    Without this patch an additional opening balance account is created by the
    assistant-hierarchy.

diff --git a/gnucash/gnome/assistant-hierarchy.c b/gnucash/gnome/assistant-hierarchy.c
index 40160221d..761ce5637 100644
--- a/gnucash/gnome/assistant-hierarchy.c
+++ b/gnucash/gnome/assistant-hierarchy.c
@@ -1423,13 +1423,6 @@ on_finish (GtkAssistant  *gtkassistant,
     ENTER (" ");
     com = gnc_currency_edit_get_currency (GNC_CURRENCY_EDIT(data->currency_selector));
 
-    if (data->our_account_tree)
-    {
-        gnc_account_foreach_descendant (data->our_account_tree,
-                                        (AccountCb)starting_balance_helper,
-                                        data);
-    }
-
     // delete before we suspend GUI events, and then muck with the model,
     // because the model doesn't seem to handle this correctly.
     if (data->initial_category)
@@ -1452,6 +1445,13 @@ on_finish (GtkAssistant  *gtkassistant,
 
     gnc_resume_gui_refresh ();
 
+    if (data->our_account_tree)
+    {
+        gnc_account_foreach_descendant (data->our_account_tree,
+                                        (AccountCb)starting_balance_helper,
+                                        data);
+    }
+
     if (when_completed)
     {
         (*when_completed)();

commit f8dcd2302366a3d0032038b81f5fb5252fd09f87
Author: Ralf Habacker <ralf.habacker at freenet.de>
Date:   Sat Sep 19 10:53:08 2020 +0200

    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

diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c
index f72debba1..3bf1d21ec 100644
--- a/gnucash/gnome-utils/dialog-account.c
+++ b/gnucash/gnome-utils/dialog-account.c
@@ -106,6 +106,7 @@ typedef struct _AccountWindow
     GtkTreeView * parent_tree;
     GtkWidget * parent_scroll;
 
+    GtkWidget * opening_balance_button;
     GtkWidget * opening_balance_edit;
     GtkWidget * opening_balance_date_edit;
     GtkWidget * opening_balance_page;
@@ -205,6 +206,32 @@ gnc_account_commodity_from_type (AccountWindow * aw, gboolean update)
     aw->commodity_mode = new_mode;
 }
 
+static void
+gnc_account_opening_balance_button_update (AccountWindow *aw, gnc_commodity *commodity)
+{
+    Account *account = aw_get_account (aw);
+    Account *ob_account = gnc_account_lookup_by_opening_balance (gnc_book_get_root_account (aw->book), commodity);
+    gboolean has_splits = xaccAccountCountSplits (account, FALSE) > 0;
+
+    if (xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
+    {
+        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.
+     */
+    switch(aw->dialog_type)
+    {
+    case EDIT_ACCOUNT:
+        gtk_widget_set_sensitive (aw->opening_balance_button, (ob_account == NULL || ob_account == account) && has_splits == 0);
+        break;
+    case NEW_ACCOUNT:
+        gtk_widget_set_sensitive (aw->opening_balance_button, ob_account == NULL);
+        break;
+    }
+}
+
 /* Copy the account values to the GUI widgets */
 static void
 gnc_account_to_ui(AccountWindow *aw)
@@ -268,6 +295,12 @@ gnc_account_to_ui(AccountWindow *aw)
 
     gtk_text_buffer_set_text (aw->notes_text_buffer, string, strlen(string));
 
+    gnc_account_opening_balance_button_update (aw, commodity);
+
+    flag = xaccAccountGetIsOpeningBalance (account);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (aw->opening_balance_button),
+                                  flag);
+
     flag = xaccAccountGetTaxRelated (account);
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (aw->tax_related_button),
                                   flag);
@@ -434,6 +467,11 @@ gnc_ui_to_account(AccountWindow *aw)
     if (null_strcmp (string, old_string) != 0)
         xaccAccountSetNotes (account, string);
 
+    flag =
+        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (aw->opening_balance_button));
+    if (xaccAccountGetIsOpeningBalance (account) != flag)
+        xaccAccountSetIsOpeningBalance (account, flag);
+
     flag =
         gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (aw->tax_related_button));
     if (xaccAccountGetTaxRelated (account) != flag)
@@ -1271,11 +1309,33 @@ commodity_changed_cb (GNCGeneralSelect *gsl, gpointer data)
     AccountWindow *aw = data;
     gnc_commodity *currency;
     GtkTreeSelection *selection;
+    Account *account = aw_get_account (aw);
 
     currency = (gnc_commodity *) gnc_general_select_get_selected (gsl);
     if (!currency)
         return;
 
+    if (xaccAccountGetIsOpeningBalance (account))
+    {
+        Account *ob_account = gnc_account_lookup_by_opening_balance (gnc_book_get_root_account (aw->book), currency);
+        if (ob_account != account)
+        {
+            gchar *dialog_msg = _("An account with opening balance already exists for the desired currency.");
+            gchar *dialog_title = _("Cannot change currency");
+            GtkWidget *dialog = gtk_message_dialog_new (gnc_ui_get_main_window (NULL),
+                                                        0,
+                                                        GTK_MESSAGE_ERROR,
+                                                        GTK_BUTTONS_OK,
+                                                        "%s", dialog_title);
+            gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
+                                 "%s", dialog_msg);
+            gtk_dialog_run(GTK_DIALOG(dialog));
+            gtk_widget_destroy(dialog);
+            gnc_general_select_set_selected (gsl, xaccAccountGetCommodity (account));
+            return;
+        }
+    }
+
     gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (aw->opening_balance_edit),
                                   gnc_commodity_get_fraction (currency));
     gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (aw->opening_balance_edit),
@@ -1283,6 +1343,7 @@ commodity_changed_cb (GNCGeneralSelect *gsl, gpointer data)
 
     selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->transfer_tree));
     gtk_tree_selection_unselect_all (selection);
+    gnc_account_opening_balance_button_update (aw, currency);
 }
 
 static gboolean
@@ -1420,6 +1481,7 @@ gnc_account_window_create(GtkWindow *parent, AccountWindow *aw)
     g_signal_connect (G_OBJECT (selection), "changed",
                       G_CALLBACK (gnc_account_parent_changed_cb), aw);
 
+    aw->opening_balance_button = GTK_WIDGET(gtk_builder_get_object (builder, "opening_balance_button"));
     aw->tax_related_button = GTK_WIDGET(gtk_builder_get_object (builder, "tax_related_button"));
     aw->placeholder_button = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_button"));
     aw->hidden_button = GTK_WIDGET(gtk_builder_get_object (builder, "hidden_button"));
diff --git a/gnucash/gnome-utils/gnc-tree-model-account.c b/gnucash/gnome-utils/gnc-tree-model-account.c
index 0a93faf4d..5c3160e5a 100644
--- a/gnucash/gnome-utils/gnc-tree-model-account.c
+++ b/gnucash/gnome-utils/gnc-tree-model-account.c
@@ -420,6 +420,7 @@ gnc_tree_model_account_get_column_type (GtkTreeModel *tree_model, int index)
 
     case GNC_TREE_MODEL_ACCOUNT_COL_HIDDEN:
     case GNC_TREE_MODEL_ACCOUNT_COL_PLACEHOLDER:
+    case GNC_TREE_MODEL_ACCOUNT_COL_OPENING_BALANCE:
         return G_TYPE_BOOLEAN;
 
     default:
@@ -956,6 +957,11 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model,
         g_value_set_boolean (value, xaccAccountGetPlaceholder (account));
         break;
 
+    case GNC_TREE_MODEL_ACCOUNT_COL_OPENING_BALANCE:
+        g_value_init (value, G_TYPE_BOOLEAN);
+        g_value_set_boolean (value, xaccAccountGetIsOpeningBalance (account));
+        break;
+
     default:
         g_assert_not_reached ();
         break;
diff --git a/gnucash/gnome-utils/gnc-tree-model-account.h b/gnucash/gnome-utils/gnc-tree-model-account.h
index 17fd76d53..177587305 100644
--- a/gnucash/gnome-utils/gnc-tree-model-account.h
+++ b/gnucash/gnome-utils/gnc-tree-model-account.h
@@ -81,8 +81,9 @@ typedef enum
     GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO_SUB_ACCT,
     GNC_TREE_MODEL_ACCOUNT_COL_HIDDEN,
     GNC_TREE_MODEL_ACCOUNT_COL_PLACEHOLDER,
+    GNC_TREE_MODEL_ACCOUNT_COL_OPENING_BALANCE,
 
-    GNC_TREE_MODEL_ACCOUNT_COL_LAST_VISIBLE = GNC_TREE_MODEL_ACCOUNT_COL_PLACEHOLDER,
+    GNC_TREE_MODEL_ACCOUNT_COL_LAST_VISIBLE = GNC_TREE_MODEL_ACCOUNT_COL_OPENING_BALANCE,
 
     /* internal hidden columns */
     GNC_TREE_MODEL_ACCOUNT_COL_COLOR_PRESENT,
diff --git a/gnucash/gnome-utils/gnc-tree-view-account.c b/gnucash/gnome-utils/gnc-tree-view-account.c
index f4abff187..0da39e117 100644
--- a/gnucash/gnome-utils/gnc-tree-view-account.c
+++ b/gnucash/gnome-utils/gnc-tree-view-account.c
@@ -494,6 +494,29 @@ sort_by_placeholder (GtkTreeModel *f_model,
     return xaccAccountOrder(account_a, account_b);
 }
 
+static gint
+sort_by_opening_balance (GtkTreeModel *f_model,
+                         GtkTreeIter *f_iter_a,
+                         GtkTreeIter *f_iter_b,
+                         gpointer user_data)
+{
+    const Account *account_a, *account_b;
+    gboolean flag_a, flag_b;
+
+    /* Find the accounts */
+    sort_cb_setup (f_model, f_iter_a, f_iter_b, &account_a, &account_b);
+
+    /* Get the opening balance flags. */
+    flag_a = xaccAccountGetIsOpeningBalance (account_a);
+    flag_b = xaccAccountGetIsOpeningBalance (account_b);
+
+    if (flag_a > flag_b)
+        return -1;
+    else if (flag_a < flag_b)
+        return 1;
+    return xaccAccountOrder(account_a, account_b);
+}
+
 static gint
 sort_by_xxx_period_value (GtkTreeModel *f_model,
                           GtkTreeIter *f_iter_a,
@@ -970,6 +993,14 @@ gnc_tree_view_account_new_with_root (Account *root, gboolean show_root)
                                     sort_by_placeholder,
                                     gnc_tree_view_account_placeholder_toggled);
 
+    gnc_tree_view_add_toggle_column(view, _("Opening Balance"),
+                    C_("Column header for 'Opening Balance'", "O"),
+                                    "opening-balance",
+                                    GNC_TREE_MODEL_ACCOUNT_COL_OPENING_BALANCE,
+                                    GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
+                                    sort_by_opening_balance,
+                                    NULL);
+
     /* Add function to each column that optionally sets a background color for accounts */
     col_list = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
     for (node = col_list; node; node = node->next)
diff --git a/gnucash/gtkbuilder/dialog-account.glade b/gnucash/gtkbuilder/dialog-account.glade
index 18f5d9d70..dd63585fd 100644
--- a/gnucash/gtkbuilder/dialog-account.glade
+++ b/gnucash/gtkbuilder/dialog-account.glade
@@ -1504,6 +1504,23 @@
                             <property name="top_attach">7</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkCheckButton" id="opening_balance_button">
+                            <property name="label" translatable="yes">Opening balance</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="tooltip_text" translatable="yes">This account holds opening balance transactions. Only one account per commodity can hold opening balance transactions.</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="top_attach">11</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                         <child>
                           <placeholder/>
                         </child>
diff --git a/libgnucash/app-utils/gnc-ui-util.c b/libgnucash/app-utils/gnc-ui-util.c
index 02f487f5b..86b61b296 100644
--- a/libgnucash/app-utils/gnc-ui-util.c
+++ b/libgnucash/app-utils/gnc-ui-util.c
@@ -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);
diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index cdba3c20f..5bcfe1a6c 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -116,6 +116,7 @@ enum
 
     PROP_LOT_NEXT_ID,                   /* KVP */
     PROP_ONLINE_ACCOUNT,                /* KVP */
+    PROP_IS_OPENING_BALANCE,            /* KVP */
     PROP_OFX_INCOME_ACCOUNT,            /* KVP */
     PROP_AB_ACCOUNT_ID,                 /* KVP */
     PROP_AB_ACCOUNT_UID,                /* KVP */
@@ -467,6 +468,9 @@ gnc_account_get_property (GObject         *object,
     case PROP_AUTO_INTEREST:
         g_value_set_boolean (value, xaccAccountGetAutoInterest (account));
         break;
+    case PROP_IS_OPENING_BALANCE:
+        g_value_set_boolean(value, xaccAccountGetIsOpeningBalance(account));
+        break;
     case PROP_PLACEHOLDER:
         g_value_set_boolean(value, xaccAccountGetPlaceholder(account));
         break;
@@ -595,6 +599,9 @@ gnc_account_set_property (GObject         *object,
     case PROP_AUTO_INTEREST:
         xaccAccountSetAutoInterest (account, g_value_get_boolean (value));
         break;
+    case PROP_IS_OPENING_BALANCE:
+        xaccAccountSetIsOpeningBalance (account, g_value_get_boolean (value));
+        break;
     case PROP_PLACEHOLDER:
         xaccAccountSetPlaceholder(account, g_value_get_boolean(value));
         break;
@@ -940,6 +947,15 @@ gnc_account_class_init (AccountClass *klass)
                            FALSE,
                            static_cast<GParamFlags>(G_PARAM_READWRITE)));
 
+    g_object_class_install_property
+    (gobject_class,
+     PROP_IS_OPENING_BALANCE,
+     g_param_spec_boolean ("opening-balance",
+                           "Opening Balance",
+                           "Whether the account holds opening balances",
+                           FALSE,
+                           static_cast<GParamFlags>(G_PARAM_READWRITE)));
+
     g_object_class_install_property
     (gobject_class,
      PROP_TAX_CODE,
@@ -3018,6 +3034,21 @@ gnc_account_lookup_by_code (const Account *parent, const char * code)
     return NULL;
 }
 
+static gpointer
+is_opening_balance_account (Account* account, gpointer data)
+{
+    gnc_commodity* commodity = GNC_COMMODITY(data);
+    if (xaccAccountGetIsOpeningBalance(account) && gnc_commodity_equiv(commodity, xaccAccountGetCommodity(account)))
+        return account;
+    return nullptr;
+}
+
+Account*
+gnc_account_lookup_by_opening_balance (Account* account, gnc_commodity* commodity)
+{
+    return (Account *)gnc_account_foreach_descendant_until (account, is_opening_balance_account, commodity);
+}
+
 /********************************************************************\
  * Fetch an account, given its full name                            *
 \********************************************************************/
@@ -4128,6 +4159,22 @@ xaccAccountSetPlaceholder (Account *acc, gboolean val)
     set_boolean_key(acc, {"placeholder"}, val);
 }
 
+gboolean
+xaccAccountGetIsOpeningBalance (const Account *acc)
+{
+    if (GET_PRIVATE(acc)->type != ACCT_TYPE_EQUITY)
+        return false;
+    return g_strcmp0(get_kvp_string_tag(acc, "equity-type"), "opening-balance") == 0;
+}
+
+void
+xaccAccountSetIsOpeningBalance (Account *acc, gboolean val)
+{
+    if (GET_PRIVATE(acc)->type != ACCT_TYPE_EQUITY)
+        return;
+    set_kvp_string_tag(acc, "equity-type", val ? "opening-balance" : "");
+}
+
 GNCPlaceholderType
 xaccAccountGetDescendantPlaceholder (const Account *acc)
 {
@@ -6034,6 +6081,11 @@ gboolean xaccAccountRegister (void)
             (QofAccessFunc) xaccAccountGetTaxRelated,
             (QofSetterFunc) xaccAccountSetTaxRelated
         },
+        {
+            ACCOUNT_OPENING_BALANCE_, QOF_TYPE_BOOLEAN,
+            (QofAccessFunc) xaccAccountGetIsOpeningBalance,
+            (QofSetterFunc) xaccAccountSetIsOpeningBalance
+        },
         {
             ACCOUNT_SCU, QOF_TYPE_INT32,
             (QofAccessFunc) xaccAccountGetCommoditySCU,
diff --git a/libgnucash/engine/Account.h b/libgnucash/engine/Account.h
index 2afe184d9..cb93c64a5 100644
--- a/libgnucash/engine/Account.h
+++ b/libgnucash/engine/Account.h
@@ -930,6 +930,14 @@ Account *gnc_account_lookup_by_full_name (const Account *any_account,
 Account *gnc_account_lookup_by_code (const Account *parent,
                                      const char *code);
 
+/** Find the opening balance account for the currency.
+ *
+ *  @param account The account of which the sought-for account is a descendant.
+ *  @param commodity The commodity in which the account should be denominated
+ *  @return The descendant account of EQUITY_TYPE_OPENING_BALANCE or NULL if one doesn't exist.
+ */
+Account *gnc_account_lookup_by_opening_balance (Account *account, gnc_commodity *commodity);
+
 /** @} */
 
 /* ------------------ */
@@ -1191,6 +1199,22 @@ gboolean xaccAccountGetPlaceholder (const Account *account);
  *  @param val The new state for the account's "placeholder" flag. */
 void xaccAccountSetPlaceholder (Account *account, gboolean val);
 
+/** Get the "opening-balance" flag for an account.  If this flag is set
+ *  then the account is used for opening balance transactions.
+ *
+ *  @param account The account whose flag should be retrieved.
+ *
+ *  @return The current state of the account's "opening-balance" flag. */
+gboolean xaccAccountGetIsOpeningBalance (const Account *account);
+
+/** Set the "opening-balance" flag for an account. If this flag is set
+ *  then the account is used for opening balance transactions.
+ *
+ *  @param account The account whose flag should be set.
+ *
+ *  @param val The new state for the account's "opening-balance" flag. */
+void xaccAccountSetIsOpeningBalance (Account *account, gboolean val);
+
 /** Returns PLACEHOLDER_NONE if account is NULL or neither account nor
  *  any descendant of account is a placeholder.  If account is a
  *  placeholder, returns PLACEHOLDER_THIS.  Otherwise, if any
@@ -1568,6 +1592,7 @@ const char * dxaccAccountGetQuoteTZ (const Account *account);
 #define ACCOUNT_NOTES_		"notes"
 #define ACCOUNT_BALANCE_	"balance"
 #define ACCOUNT_NOCLOSING_	"noclosing"
+#define ACCOUNT_OPENING_BALANCE_ "opening-balance"
 #define ACCOUNT_CLEARED_	"cleared"
 #define ACCOUNT_RECONCILED_	"reconciled"
 #define ACCOUNT_PRESENT_	"present"
diff --git a/libgnucash/engine/test/utest-Account.cpp b/libgnucash/engine/test/utest-Account.cpp
index 7c146153d..eab36c325 100644
--- a/libgnucash/engine/test/utest-Account.cpp
+++ b/libgnucash/engine/test/utest-Account.cpp
@@ -546,7 +546,7 @@ test_gnc_account_create_and_destroy (void)
     GNCAccountType type;
     gnc_commodity *commo;
     gint commo_scu, mark;
-    gboolean non_std_scu, sort_dirty, bal_dirty, tax_rel, hide, hold;
+    gboolean non_std_scu, sort_dirty, bal_dirty, opening_balance, tax_rel, hide, hold;
     gint64 copy_num;
     gnc_numeric *start_bal, *start_clr_bal, *start_rec_bal;
     gnc_numeric *end_bal, *end_clr_bal, *end_rec_bal;
@@ -571,6 +571,7 @@ test_gnc_account_create_and_destroy (void)
                   "end-balance", &end_bal,
                   "end-cleared-balance", &end_clr_bal,
                   "end-reconciled-balance", &end_rec_bal,
+                  "opening-balance", &opening_balance,
                   "policy", &pol,
                   "acct-mark", &mark,
                   "tax-related", &tax_rel,
@@ -599,6 +600,7 @@ test_gnc_account_create_and_destroy (void)
     g_assert (gnc_numeric_zero_p (*start_bal));
     g_assert (gnc_numeric_zero_p (*start_clr_bal));
     g_assert (gnc_numeric_zero_p (*start_rec_bal));
+    g_assert (!opening_balance);
     g_assert (pol == xaccGetFIFOPolicy ());
     g_assert (!mark);
     g_assert (!tax_rel);

commit 573f7aaa0b427fda4a1874b5c35b95e4ad48b816
Author: Ralf Habacker <ralf.habacker at freenet.de>
Date:   Tue Sep 15 03:11:22 2020 +0200

    Add slot "equity-type" with value "opening-balance" to account templates
    
    The slots are added by running `util/add-opening-balances` on the
    gnucash sources.

diff --git a/data/accounts/C/acctchrt_business.gnucash-xea b/data/accounts/C/acctchrt_business.gnucash-xea
index d770547de..b21e191f6 100644
--- a/data/accounts/C/acctchrt_business.gnucash-xea
+++ b/data/accounts/C/acctchrt_business.gnucash-xea
@@ -1422,6 +1422,12 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">87e02e757b32b3059652cfe09fe9ae00</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Retained Earnings</act:name>
diff --git a/data/accounts/C/acctchrt_checkbook.gnucash-xea b/data/accounts/C/acctchrt_checkbook.gnucash-xea
index f3c279219..569543223 100644
--- a/data/accounts/C/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/C/acctchrt_checkbook.gnucash-xea
@@ -147,5 +147,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/C/acctchrt_common.gnucash-xea b/data/accounts/C/acctchrt_common.gnucash-xea
index 883f0cf71..0cfb6360f 100644
--- a/data/accounts/C/acctchrt_common.gnucash-xea
+++ b/data/accounts/C/acctchrt_common.gnucash-xea
@@ -783,6 +783,12 @@
   </act:commodity>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 
 </gnc-account-example>
diff --git a/data/accounts/C/acctchrt_full.gnucash-xea b/data/accounts/C/acctchrt_full.gnucash-xea
index acc2a8bac..7ffe7e09d 100644
--- a/data/accounts/C/acctchrt_full.gnucash-xea
+++ b/data/accounts/C/acctchrt_full.gnucash-xea
@@ -1396,6 +1396,12 @@
   </act:commodity>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">68d4074f91295062c0b773b4ae8de6bd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 
 </gnc-account-example>
diff --git a/data/accounts/da/acctchrt_common.gnucash-xea b/data/accounts/da/acctchrt_common.gnucash-xea
index 05c98d6f9..efcdd580d 100644
--- a/data/accounts/da/acctchrt_common.gnucash-xea
+++ b/data/accounts/da/acctchrt_common.gnucash-xea
@@ -684,5 +684,11 @@
   </act:commodity>
   <act:description>Ã…bningssaldi</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/de_AT/acctchrt_business.gnucash-xea b/data/accounts/de_AT/acctchrt_business.gnucash-xea
index c8b7afa18..3ce69178c 100644
--- a/data/accounts/de_AT/acctchrt_business.gnucash-xea
+++ b/data/accounts/de_AT/acctchrt_business.gnucash-xea
@@ -964,5 +964,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Anfangsbestand</act:description>
   <act:parent type="new">1972cce2e2364f95b2b0bc014502661d</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/de_AT/acctchrt_common.gnucash-xea b/data/accounts/de_AT/acctchrt_common.gnucash-xea
index 2a361f4e1..b364ccd26 100644
--- a/data/accounts/de_AT/acctchrt_common.gnucash-xea
+++ b/data/accounts/de_AT/acctchrt_common.gnucash-xea
@@ -964,5 +964,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Anfangsbestand</act:description>
   <act:parent type="new">1972cce2e2364f95b2b0bc014502661d</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/de_CH/acctchrt_common.gnucash-xea b/data/accounts/de_CH/acctchrt_common.gnucash-xea
index 005489c23..42bb958cc 100644
--- a/data/accounts/de_CH/acctchrt_common.gnucash-xea
+++ b/data/accounts/de_CH/acctchrt_common.gnucash-xea
@@ -739,5 +739,11 @@
   </act:commodity>
   <act:description>Anfangsbestand</act:description>
   <act:parent type="new">1972cce2e2364f95b2b0bc014502661d</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/de_DE/acctchrt_common.gnucash-xea b/data/accounts/de_DE/acctchrt_common.gnucash-xea
index 461249d9a..9db3399e9 100644
--- a/data/accounts/de_DE/acctchrt_common.gnucash-xea
+++ b/data/accounts/de_DE/acctchrt_common.gnucash-xea
@@ -843,6 +843,12 @@
   </act:commodity>
   <act:description>Anfangsbestand</act:description>
   <act:parent type="new">1972cce2e2364f95b2b0bc014502661d</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 
 </gnc-account-example>
diff --git a/data/accounts/de_DE/acctchrt_full.gnucash-xea b/data/accounts/de_DE/acctchrt_full.gnucash-xea
index dde38e39d..8b80d3d59 100644
--- a/data/accounts/de_DE/acctchrt_full.gnucash-xea
+++ b/data/accounts/de_DE/acctchrt_full.gnucash-xea
@@ -1192,6 +1192,12 @@
   </act:commodity>
   <act:description>Anfangsbestand</act:description>
   <act:parent type="new">320d3cf62b418db6281c3cd8ec2e95c7</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 
 </gnc-account-example>
diff --git a/data/accounts/de_DE/acctchrt_skr03.gnucash-xea b/data/accounts/de_DE/acctchrt_skr03.gnucash-xea
index f774dbd93..3107b1301 100644
--- a/data/accounts/de_DE/acctchrt_skr03.gnucash-xea
+++ b/data/accounts/de_DE/acctchrt_skr03.gnucash-xea
@@ -1269,6 +1269,12 @@
     <act:commodity-scu>100</act:commodity-scu>
     <act:code>9000</act:code>
     <act:parent type="new">26c3f10c1c7621661c1b813d6141280d</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
   </gnc:account>
   <gnc:account version="2.0.0">
     <act:name>9008 Saldenvorträge Debitoren</act:name>
diff --git a/data/accounts/de_DE/acctchrt_skr04.gnucash-xea b/data/accounts/de_DE/acctchrt_skr04.gnucash-xea
index 8c78b57fd..17beccb93 100644
--- a/data/accounts/de_DE/acctchrt_skr04.gnucash-xea
+++ b/data/accounts/de_DE/acctchrt_skr04.gnucash-xea
@@ -15678,6 +15678,12 @@
     <act:commodity-scu>100</act:commodity-scu>
     <act:code>9000</act:code>
     <act:parent type="new">e57d948c9a884e179bd090118b9212f8</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
   </gnc:account>
   <gnc:account version="2.0.0">
     <act:name>Saldenvorträge Debitoren</act:name>
diff --git a/data/accounts/de_DE/acctchrt_skr49.gnucash-xea b/data/accounts/de_DE/acctchrt_skr49.gnucash-xea
index 6351998b7..7f976f9fa 100644
--- a/data/accounts/de_DE/acctchrt_skr49.gnucash-xea
+++ b/data/accounts/de_DE/acctchrt_skr49.gnucash-xea
@@ -14305,6 +14305,12 @@ Den Bereich habe ich mit „9999“ bezeichet, damit er unterhalb der regulären
     </slot>
   </act:slots>
   <act:parent type="guid">ffca2686cb9963bea1089b796763dda0</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>9001-9007 Saldenvorträge, Sachkonten</act:name>
diff --git a/data/accounts/el_GR/acctchrt_common.gnucash-xea b/data/accounts/el_GR/acctchrt_common.gnucash-xea
index 80a881f5f..be832eab3 100644
--- a/data/accounts/el_GR/acctchrt_common.gnucash-xea
+++ b/data/accounts/el_GR/acctchrt_common.gnucash-xea
@@ -786,5 +786,11 @@
   </act:commodity>
   <act:description>Αρχικά υπόλοιπα</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/en_GB/acctchrt_business.gnucash-xea b/data/accounts/en_GB/acctchrt_business.gnucash-xea
index 436b1bb7f..2504a208f 100644
--- a/data/accounts/en_GB/acctchrt_business.gnucash-xea
+++ b/data/accounts/en_GB/acctchrt_business.gnucash-xea
@@ -1420,6 +1420,12 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">87e02e757b32b3059652cfe09fe9ae00</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Retained Earnings</act:name>
diff --git a/data/accounts/en_GB/acctchrt_checkbook.gnucash-xea b/data/accounts/en_GB/acctchrt_checkbook.gnucash-xea
index 91167f330..9d8227f3f 100644
--- a/data/accounts/en_GB/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/en_GB/acctchrt_checkbook.gnucash-xea
@@ -149,6 +149,12 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 
 </gnc-account-example>
diff --git a/data/accounts/en_GB/acctchrt_common.gnucash-xea b/data/accounts/en_GB/acctchrt_common.gnucash-xea
index c679f0949..dc0557988 100644
--- a/data/accounts/en_GB/acctchrt_common.gnucash-xea
+++ b/data/accounts/en_GB/acctchrt_common.gnucash-xea
@@ -781,5 +781,11 @@
   </act:commodity>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/en_GB/acctchrt_full.gnucash-xea b/data/accounts/en_GB/acctchrt_full.gnucash-xea
index 4f6dd11a1..c422a5426 100644
--- a/data/accounts/en_GB/acctchrt_full.gnucash-xea
+++ b/data/accounts/en_GB/acctchrt_full.gnucash-xea
@@ -1393,5 +1393,11 @@
   </act:commodity>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">68d4074f91295062c0b773b4ae8de6bd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/en_GB/uk-vat.gnucash-xea b/data/accounts/en_GB/uk-vat.gnucash-xea
index 8222baa89..1cfe3a6f1 100644
--- a/data/accounts/en_GB/uk-vat.gnucash-xea
+++ b/data/accounts/en_GB/uk-vat.gnucash-xea
@@ -398,6 +398,12 @@
   </act:commodity>
   <act:commodity-scu>100</act:commodity-scu>
   <act:parent type="new">c0b1160d2dd6b3059acc5083348b282f</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Grants</act:name>
diff --git a/data/accounts/en_IN/acctchrt_gstindia.gnucash-xea b/data/accounts/en_IN/acctchrt_gstindia.gnucash-xea
index 8530719db..8ec978f4e 100644
--- a/data/accounts/en_IN/acctchrt_gstindia.gnucash-xea
+++ b/data/accounts/en_IN/acctchrt_gstindia.gnucash-xea
@@ -1137,6 +1137,12 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">599b08659324698f0177ce3dbb513e5f</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Reserves and Surplus</act:name>
diff --git a/data/accounts/es_ES/acctchrt_common.gnucash-xea b/data/accounts/es_ES/acctchrt_common.gnucash-xea
index 7eac72d74..64c40c516 100644
--- a/data/accounts/es_ES/acctchrt_common.gnucash-xea
+++ b/data/accounts/es_ES/acctchrt_common.gnucash-xea
@@ -753,5 +753,11 @@
   </act:commodity>
   <act:description>Balances de apertura</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/es_MX/acctchrt_common.gnucash-xea b/data/accounts/es_MX/acctchrt_common.gnucash-xea
index 862ce6a93..86e61a49d 100644
--- a/data/accounts/es_MX/acctchrt_common.gnucash-xea
+++ b/data/accounts/es_MX/acctchrt_common.gnucash-xea
@@ -830,5 +830,11 @@
   </act:commodity>
   <act:description>Balances de apertura</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/fi_FI/acctchrt_ry.gnucash-xea b/data/accounts/fi_FI/acctchrt_ry.gnucash-xea
index 2e906c66a..e33ae8d99 100644
--- a/data/accounts/fi_FI/acctchrt_ry.gnucash-xea
+++ b/data/accounts/fi_FI/acctchrt_ry.gnucash-xea
@@ -397,6 +397,12 @@
       <act:commodity-scu>100</act:commodity-scu>
       <act:description>Opening Balances</act:description>
       <act:parent type="new">7081f24a5685d4dfcb8f143f0b7ee31d</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
     </gnc:account>
 
 </gnc-account-example>
diff --git a/data/accounts/fr_BE/acctchrt_business.gnucash-xea b/data/accounts/fr_BE/acctchrt_business.gnucash-xea
index d85130923..8878ee26a 100644
--- a/data/accounts/fr_BE/acctchrt_business.gnucash-xea
+++ b/data/accounts/fr_BE/acctchrt_business.gnucash-xea
@@ -1378,6 +1378,12 @@ Les utilisateurs gérant une entreprise sélectionneront ceci au lieu des autres
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Soldes initiaux</act:description>
   <act:parent type="new">87e02e757b32b3059652cfe09fe9ae00</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Gains enregistrés</act:name>
diff --git a/data/accounts/fr_BE/acctchrt_common.gnucash-xea b/data/accounts/fr_BE/acctchrt_common.gnucash-xea
index 3d49f4c91..a14410017 100644
--- a/data/accounts/fr_BE/acctchrt_common.gnucash-xea
+++ b/data/accounts/fr_BE/acctchrt_common.gnucash-xea
@@ -750,5 +750,11 @@
   </act:commodity>
   <act:description>Soldes initiaux</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/fr_CH/acctchrt_business.gnucash-xea b/data/accounts/fr_CH/acctchrt_business.gnucash-xea
index 9dfa99cf4..001bb3c8a 100644
--- a/data/accounts/fr_CH/acctchrt_business.gnucash-xea
+++ b/data/accounts/fr_CH/acctchrt_business.gnucash-xea
@@ -1378,6 +1378,12 @@ Les utilisateurs gérant une entreprise sélectionneront ceci au lieu des autres
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Soldes initiaux</act:description>
   <act:parent type="new">87e02e757b32b3059652cfe09fe9ae00</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Gains enregistrés</act:name>
diff --git a/data/accounts/fr_CH/acctchrt_common.gnucash-xea b/data/accounts/fr_CH/acctchrt_common.gnucash-xea
index b245735fb..acfd3481e 100644
--- a/data/accounts/fr_CH/acctchrt_common.gnucash-xea
+++ b/data/accounts/fr_CH/acctchrt_common.gnucash-xea
@@ -750,5 +750,11 @@
   </act:commodity>
   <act:description>Soldes initiaux</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/fr_FR/acctchrt_business.gnucash-xea b/data/accounts/fr_FR/acctchrt_business.gnucash-xea
index 70f02996f..294fbfc1f 100644
--- a/data/accounts/fr_FR/acctchrt_business.gnucash-xea
+++ b/data/accounts/fr_FR/acctchrt_business.gnucash-xea
@@ -1378,6 +1378,12 @@ Les utilisateurs gérant une entreprise sélectionneront ceci au lieu des autres
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Soldes initiaux</act:description>
   <act:parent type="new">87e02e757b32b3059652cfe09fe9ae00</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Gains enregistrés</act:name>
diff --git a/data/accounts/fr_FR/acctchrt_common.gnucash-xea b/data/accounts/fr_FR/acctchrt_common.gnucash-xea
index 790957534..cdaaaeccf 100644
--- a/data/accounts/fr_FR/acctchrt_common.gnucash-xea
+++ b/data/accounts/fr_FR/acctchrt_common.gnucash-xea
@@ -750,5 +750,11 @@
   </act:commodity>
   <act:description>Soldes initiaux</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/he/acctchrt_checkbook.gnucash-xea b/data/accounts/he/acctchrt_checkbook.gnucash-xea
index ea74c8188..975c29dab 100644
--- a/data/accounts/he/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/he/acctchrt_checkbook.gnucash-xea
@@ -147,5 +147,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>יתרת פתיחה</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/hr/acctchrt_checkbook.gnucash-xea b/data/accounts/hr/acctchrt_checkbook.gnucash-xea
index 6cd485e4c..c55c6ee50 100644
--- a/data/accounts/hr/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/hr/acctchrt_checkbook.gnucash-xea
@@ -147,5 +147,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Početni saldo</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/hr/acctchrt_common.gnucash-xea b/data/accounts/hr/acctchrt_common.gnucash-xea
index 9d52bb6d5..cce4ac53f 100644
--- a/data/accounts/hr/acctchrt_common.gnucash-xea
+++ b/data/accounts/hr/acctchrt_common.gnucash-xea
@@ -800,6 +800,12 @@
   </act:commodity>
   <act:description>Početni saldo</act:description>
   <act:parent type="new">73f3a388cebe42a3bc40ab8db179d32d</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
 
diff --git a/data/accounts/hu/acctchrt_business.gnucash-xea b/data/accounts/hu/acctchrt_business.gnucash-xea
index 0e190fbb6..6bc09f304 100644
--- a/data/accounts/hu/acctchrt_business.gnucash-xea
+++ b/data/accounts/hu/acctchrt_business.gnucash-xea
@@ -1378,6 +1378,12 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Nyitóegyenlegek</act:description>
   <act:parent type="new">87e02e757b32b3059652cfe09fe9ae00</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Céltartalékok</act:name>
diff --git a/data/accounts/hu/acctchrt_checkbook.gnucash-xea b/data/accounts/hu/acctchrt_checkbook.gnucash-xea
index c9ce82784..8b86cd68d 100644
--- a/data/accounts/hu/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/hu/acctchrt_checkbook.gnucash-xea
@@ -139,5 +139,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Nyitóegyenlegek</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/hu/acctchrt_common.gnucash-xea b/data/accounts/hu/acctchrt_common.gnucash-xea
index 6728e1d1a..f9335cd5c 100644
--- a/data/accounts/hu/acctchrt_common.gnucash-xea
+++ b/data/accounts/hu/acctchrt_common.gnucash-xea
@@ -728,5 +728,11 @@
   </act:commodity>
   <act:description>Nyitóegyenlegek</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/it/acctchrt_checkbook.gnucash-xea b/data/accounts/it/acctchrt_checkbook.gnucash-xea
index 10d3ec31b..a55cb3b15 100644
--- a/data/accounts/it/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/it/acctchrt_checkbook.gnucash-xea
@@ -144,5 +144,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Bilanci d'apertura</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/it/acctchrt_common.gnucash-xea b/data/accounts/it/acctchrt_common.gnucash-xea
index 075415a61..1e5b68326 100644
--- a/data/accounts/it/acctchrt_common.gnucash-xea
+++ b/data/accounts/it/acctchrt_common.gnucash-xea
@@ -747,5 +747,11 @@
   </act:commodity>
   <act:description>Bilanci d'apertura</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/ja/acctchrt_business.gnucash-xea b/data/accounts/ja/acctchrt_business.gnucash-xea
index d346a792b..3ad89b710 100644
--- a/data/accounts/ja/acctchrt_business.gnucash-xea
+++ b/data/accounts/ja/acctchrt_business.gnucash-xea
@@ -1414,6 +1414,12 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>開始残高</act:description>
   <act:parent type="new">87e02e757b32b3059652cfe09fe9ae00</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>内部留保</act:name>
diff --git a/data/accounts/ja/acctchrt_checkbook.gnucash-xea b/data/accounts/ja/acctchrt_checkbook.gnucash-xea
index 02b63dc1e..f203a3c49 100644
--- a/data/accounts/ja/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/ja/acctchrt_checkbook.gnucash-xea
@@ -147,5 +147,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>開始残高</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/ja/acctchrt_common.gnucash-xea b/data/accounts/ja/acctchrt_common.gnucash-xea
index 8a5974b91..8bee4af8d 100644
--- a/data/accounts/ja/acctchrt_common.gnucash-xea
+++ b/data/accounts/ja/acctchrt_common.gnucash-xea
@@ -775,5 +775,11 @@
   </act:commodity>
   <act:description>開始残高</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/ja/acctchrt_full.gnucash-xea b/data/accounts/ja/acctchrt_full.gnucash-xea
index 535271b50..299076812 100644
--- a/data/accounts/ja/acctchrt_full.gnucash-xea
+++ b/data/accounts/ja/acctchrt_full.gnucash-xea
@@ -1390,5 +1390,11 @@
   </act:commodity>
   <act:description>開始残高</act:description>
   <act:parent type="new">68d4074f91295062c0b773b4ae8de6bd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/lv/acctchrt_checkbook.gnucash-xea b/data/accounts/lv/acctchrt_checkbook.gnucash-xea
index 1887b7281..f0abacc0c 100644
--- a/data/accounts/lv/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/lv/acctchrt_checkbook.gnucash-xea
@@ -129,5 +129,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Sākuma bilance</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/lv/acctchrt_common.gnucash-xea b/data/accounts/lv/acctchrt_common.gnucash-xea
index fcfe56ac8..6e739371f 100644
--- a/data/accounts/lv/acctchrt_common.gnucash-xea
+++ b/data/accounts/lv/acctchrt_common.gnucash-xea
@@ -736,5 +736,11 @@
   </act:commodity>
   <act:description>Kontu sākuma bilances</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/lv/acctchrt_full.gnucash-xea b/data/accounts/lv/acctchrt_full.gnucash-xea
index a92df3bb8..d8afe8ee7 100644
--- a/data/accounts/lv/acctchrt_full.gnucash-xea
+++ b/data/accounts/lv/acctchrt_full.gnucash-xea
@@ -1354,5 +1354,11 @@
   </act:commodity>
   <act:description>Sākuma bilances</act:description>
   <act:parent type="new">68d4074f91295062c0b773b4ae8de6bd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/nb/acctchrt_common.gnucash-xea b/data/accounts/nb/acctchrt_common.gnucash-xea
index 9b62c7305..862e086f4 100644
--- a/data/accounts/nb/acctchrt_common.gnucash-xea
+++ b/data/accounts/nb/acctchrt_common.gnucash-xea
@@ -739,5 +739,11 @@
   </act:commodity>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/nb/acctchrt_full.gnucash-xea b/data/accounts/nb/acctchrt_full.gnucash-xea
index ac1654a34..bdc03878e 100644
--- a/data/accounts/nb/acctchrt_full.gnucash-xea
+++ b/data/accounts/nb/acctchrt_full.gnucash-xea
@@ -1319,5 +1319,11 @@
   </act:commodity>
   <act:description>Opening Balances</act:description>
   <act:parent type="new">68d4074f91295062c0b773b4ae8de6bd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/nl/acctchrt_checkbook.gnucash-xea b/data/accounts/nl/acctchrt_checkbook.gnucash-xea
index 0928229d6..bcfddcc29 100644
--- a/data/accounts/nl/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/nl/acctchrt_checkbook.gnucash-xea
@@ -147,5 +147,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Beginsaldi</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/nl/acctchrt_full.gnucash-xea b/data/accounts/nl/acctchrt_full.gnucash-xea
index 7a0ee89ca..46f6761be 100644
--- a/data/accounts/nl/acctchrt_full.gnucash-xea
+++ b/data/accounts/nl/acctchrt_full.gnucash-xea
@@ -1387,5 +1387,11 @@
   </act:commodity>
   <act:description>Openingsbalans</act:description>
   <act:parent type="new">68d4074f91295062c0b773b4ae8de6bd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/pl/acctchrt_business.gnucash-xea b/data/accounts/pl/acctchrt_business.gnucash-xea
index ac6d9dd34..adc08f40e 100644
--- a/data/accounts/pl/acctchrt_business.gnucash-xea
+++ b/data/accounts/pl/acctchrt_business.gnucash-xea
@@ -1414,6 +1414,12 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Bilanse otwarcia</act:description>
   <act:parent type="new">87e02e757b32b3059652cfe09fe9ae00</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Zyski zatrzymane</act:name>
diff --git a/data/accounts/pl/acctchrt_checkbook.gnucash-xea b/data/accounts/pl/acctchrt_checkbook.gnucash-xea
index 0133c929a..2a6c20130 100644
--- a/data/accounts/pl/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/pl/acctchrt_checkbook.gnucash-xea
@@ -147,5 +147,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>Bilanse otwarcia</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/pl/acctchrt_common.gnucash-xea b/data/accounts/pl/acctchrt_common.gnucash-xea
index 8d8a35d8f..4c9bb6545 100644
--- a/data/accounts/pl/acctchrt_common.gnucash-xea
+++ b/data/accounts/pl/acctchrt_common.gnucash-xea
@@ -775,5 +775,11 @@
   </act:commodity>
   <act:description>Bilanse otwarcia</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/pl/acctchrt_full.gnucash-xea b/data/accounts/pl/acctchrt_full.gnucash-xea
index 14b62f9c3..2098358a1 100644
--- a/data/accounts/pl/acctchrt_full.gnucash-xea
+++ b/data/accounts/pl/acctchrt_full.gnucash-xea
@@ -1387,5 +1387,11 @@
   </act:commodity>
   <act:description>Bilanse otwarcia</act:description>
   <act:parent type="new">68d4074f91295062c0b773b4ae8de6bd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/pt_BR/acctchrt_common.gnucash-xea b/data/accounts/pt_BR/acctchrt_common.gnucash-xea
index 971518a0c..1b9df1d4b 100644
--- a/data/accounts/pt_BR/acctchrt_common.gnucash-xea
+++ b/data/accounts/pt_BR/acctchrt_common.gnucash-xea
@@ -728,5 +728,11 @@
   </act:commodity>
   <act:description>Saldos Iniciais</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/pt_PT/acctchrt_common.gnucash-xea b/data/accounts/pt_PT/acctchrt_common.gnucash-xea
index e3e48ae12..97a3f45b6 100644
--- a/data/accounts/pt_PT/acctchrt_common.gnucash-xea
+++ b/data/accounts/pt_PT/acctchrt_common.gnucash-xea
@@ -746,5 +746,11 @@
     </act:commodity>
     <act:description>Saldos iniciais</act:description>
     <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
   </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/ru/acctchrt_common.gnucash-xea b/data/accounts/ru/acctchrt_common.gnucash-xea
index 9108c22da..0029599c5 100644
--- a/data/accounts/ru/acctchrt_common.gnucash-xea
+++ b/data/accounts/ru/acctchrt_common.gnucash-xea
@@ -843,6 +843,12 @@
   </act:commodity>
   <act:description>Остаток средств на начало периода</act:description>
   <act:parent type="new">1972cce2e2364f95b2b0bc014502661d</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 
 </gnc-account-example>
diff --git a/data/accounts/tr_TR/acctchrt_TEKDUZ.gnucash-xea b/data/accounts/tr_TR/acctchrt_TEKDUZ.gnucash-xea
index c539e5719..b0a76ba42 100644
--- a/data/accounts/tr_TR/acctchrt_TEKDUZ.gnucash-xea
+++ b/data/accounts/tr_TR/acctchrt_TEKDUZ.gnucash-xea
@@ -3835,6 +3835,12 @@
     </slot>
   </act:slots>
   <act:parent type="new">cfd3ff3dffa577973d3c1c5def43e568</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Ödenmemiş Sermaye(-)</act:name>
@@ -3871,6 +3877,12 @@
     </slot>
   </act:slots>
   <act:parent type="new">cfd3ff3dffa577973d3c1c5def43e568</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>Sermaye Düzeltmesi Olumsuz Farkları(-)</act:name>
diff --git a/data/accounts/zh_CN/acctchrt_business.gnucash-xea b/data/accounts/zh_CN/acctchrt_business.gnucash-xea
index 2e28e8ff7..20696beb1 100644
--- a/data/accounts/zh_CN/acctchrt_business.gnucash-xea
+++ b/data/accounts/zh_CN/acctchrt_business.gnucash-xea
@@ -1414,6 +1414,12 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>期初余额</act:description>
   <act:parent type="new">87e02e757b32b3059652cfe09fe9ae00</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 <gnc:account version="2.0.0">
   <act:name>留存收益</act:name>
diff --git a/data/accounts/zh_CN/acctchrt_checkbook.gnucash-xea b/data/accounts/zh_CN/acctchrt_checkbook.gnucash-xea
index c8b04a6bc..8624a4f0f 100644
--- a/data/accounts/zh_CN/acctchrt_checkbook.gnucash-xea
+++ b/data/accounts/zh_CN/acctchrt_checkbook.gnucash-xea
@@ -147,5 +147,11 @@
   <act:commodity-scu>100</act:commodity-scu>
   <act:description>期初余额</act:description>
   <act:parent type="new">b8b72887da1adf889f171923d23efbdd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/zh_CN/acctchrt_common.gnucash-xea b/data/accounts/zh_CN/acctchrt_common.gnucash-xea
index 1547f7d06..a7d21c829 100644
--- a/data/accounts/zh_CN/acctchrt_common.gnucash-xea
+++ b/data/accounts/zh_CN/acctchrt_common.gnucash-xea
@@ -775,5 +775,11 @@
   </act:commodity>
   <act:description>期初余额</act:description>
   <act:parent type="new">3ab6a6d97b216c11333e48aa2b749a91</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>
diff --git a/data/accounts/zh_CN/acctchrt_full.gnucash-xea b/data/accounts/zh_CN/acctchrt_full.gnucash-xea
index 72306e0d4..c8e003703 100644
--- a/data/accounts/zh_CN/acctchrt_full.gnucash-xea
+++ b/data/accounts/zh_CN/acctchrt_full.gnucash-xea
@@ -1387,5 +1387,11 @@
   </act:commodity>
   <act:description>期初余额</act:description>
   <act:parent type="new">68d4074f91295062c0b773b4ae8de6bd</act:parent>
+  <act:slots>
+    <slot>
+      <slot:key>equity-type</slot:key>
+      <slot:value type="string">opening-balance</slot:value>
+    </slot>
+  </act:slots>
 </gnc:account>
 </gnc-account-example>

commit 1cce12f8beb3983e4fc61c7a7d382cdd0cfbd4fd
Author: Ralf Habacker <ralf.habacker at freenet.de>
Date:   Mon Jul 6 20:03:41 2020 +0200

    Add script to add slots with key 'equity-type' and value 'opening-balance' to detected opening balance accounts

diff --git a/util/add-opening-balances b/util/add-opening-balances
new file mode 100755
index 000000000..692a0d190
--- /dev/null
+++ b/util/add-opening-balances
@@ -0,0 +1,118 @@
+#!/bin/sh
+#
+# Find opening balance accounts by translations and add slot with key 'opening-balance' to make them translation independent
+#
+# @author Ralf Habacker <ralf.habacker at freenet.de>
+#
+r=$(realpath $0)
+r=$(dirname $r)
+r=$(dirname $r)
+
+# debug
+#grep -rn -A1 '"Opening Balances"' $r/po | grep msgstr > translation-of-opening-balance-with-files.txt
+#grep -rnf translation-of-opening-balance.txt $r/data/accounts > all-opening-balances-accounts.txt
+
+if test -z "$1" || test "$1" == "--collect"; then
+    # collect all translations for 'Opening Balances'
+    grep -rn -A1 '"Opening Balances"' $r/po | grep msgstr | gawk '{ $1=""; print $0}' | sed 's,^ ,,g;s,",,g' | grep -v "^$" | sed 's,^,<act:name>,g;s,$,.*</act:name>,g' > translation-of-opening-balance.txt
+
+    # collect all translations for 'Opening Balances' with optional last character
+    grep -rn -A1 '"Opening Balances"' $r/po | grep msgstr | gawk '{ $1=""; print $0}' | sed 's,^ ,,g;s,",,g' | grep -v "^$" | sed 's,^,<act:name>,g;s,$,*</act:name>,g' >> translation-of-opening-balance.txt
+
+    # add custom strings
+    cat << EOF >> translation-of-opening-balance.txt
+<act:name>Openingsbalans</act:name>
+<act:name>9000 Saldenvortrag Sachkonten</act:name>
+<act:name>9000 Saldenvorträge Sachkonten</act:name>
+<act:name>Saldenvorträge Sachkonten</act:name>
+EOF
+
+fi
+
+# collect all files that contains a translation for 'Opening Balances'
+for i in $(grep -rnf translation-of-opening-balance.txt $r/data/accounts | sed 's,:[ ]*,:,g;s, ,#,g'); do
+    #echo $i
+    file=$(echo $i | sed 's,:.*$,,g')
+    pattern=$(echo $i | sed 's,^.*:<,<,g;s,#, ,g')
+    #echo "searching for $pattern in $file"
+    # add equity-type slot
+    gawk '
+BEGIN {
+    found = 0;
+    slotadded = 0;
+    slotpresent = 0;
+    patternfound = 0;
+}
+
+# search for account name
+$0 ~ PATTERN {
+    slotadded = 0
+    slotpresent = 0
+    patternfound = 1
+    replace = 1
+    #print "<!-- replace -->"
+}
+
+# opening-balance slot is already available
+replace && $1 == "<slot:key>equity-type</slot:key>" {
+    slotkeypresent = 1
+}
+
+slotkeypresent && $1 == "<slot:value type=\"string\">opening-balance</slot:value>" {
+    replace = 0
+    slotpresent = 1
+}
+
+#exclude parent named like opening balance account
+replace && $1 == "<slot:key>placeholder</slot:key>" {
+    replace = 0
+}
+
+# add new slots tag
+replace && $1 == "</gnc:account>" {
+    if (slotkeypresent) {
+        print FILE ": slot equity-type already present with different value, could not tag '" PATTERN "' as opening balance account" > /dev/stderr
+    } else {
+        print "  <act:slots>"
+        print "    <slot>"
+        print "      <slot:key>equity-type</slot:key>"
+        print "      <slot:value type=\"string\">opening-balance</slot:value>"
+        print "    </slot>"
+        print "  </act:slots>"
+        slotadded = 1
+        replace = 0
+    }
+}
+
+{
+    print $0;
+}
+
+END {
+    if (!patternfound)
+        print FILE ": opening balance account not found with pattern " PATTERN > /dev/stderr
+    #if (!slotpresent && !slotadded)
+    #print FILE " opening balance account not found with pattern " PATTERN > /dev/stderr
+}
+    ' "PATTERN=$pattern" $file > $file.new
+    mv $file.new $file
+done
+
+oba=""
+nooba=""
+for i in $(find $r/data/accounts -name '*.gnucash-xea'); do
+    o=$(grep -Hn "opening-balance" $i)
+    if test -z "$o"; then
+        nooba="$nooba\n$i"
+    else
+        oba="$oba\n$i"
+    fi
+done
+
+echo "------------------------------------------------------------"
+echo -e "The following files do not have an account with slot key 'opening-balance'"
+echo -e $nooba
+echo
+echo "------------------------------------------------------------"
+echo -e "The following files have an account with slot key 'opening-balance'"
+echo -e $oba



Summary of changes:
 data/accounts/C/acctchrt_business.gnucash-xea      |   6 ++
 data/accounts/C/acctchrt_checkbook.gnucash-xea     |   6 ++
 data/accounts/C/acctchrt_common.gnucash-xea        |   6 ++
 data/accounts/C/acctchrt_full.gnucash-xea          |   6 ++
 data/accounts/da/acctchrt_common.gnucash-xea       |   6 ++
 data/accounts/de_AT/acctchrt_business.gnucash-xea  |   6 ++
 data/accounts/de_AT/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/de_CH/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/de_DE/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/de_DE/acctchrt_full.gnucash-xea      |   6 ++
 data/accounts/de_DE/acctchrt_skr03.gnucash-xea     |   6 ++
 data/accounts/de_DE/acctchrt_skr04.gnucash-xea     |   6 ++
 data/accounts/de_DE/acctchrt_skr49.gnucash-xea     |   6 ++
 data/accounts/el_GR/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/en_GB/acctchrt_business.gnucash-xea  |   6 ++
 data/accounts/en_GB/acctchrt_checkbook.gnucash-xea |   6 ++
 data/accounts/en_GB/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/en_GB/acctchrt_full.gnucash-xea      |   6 ++
 data/accounts/en_GB/uk-vat.gnucash-xea             |   6 ++
 data/accounts/en_IN/acctchrt_gstindia.gnucash-xea  |   6 ++
 data/accounts/es_ES/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/es_MX/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/fi_FI/acctchrt_ry.gnucash-xea        |   6 ++
 data/accounts/fr_BE/acctchrt_business.gnucash-xea  |   6 ++
 data/accounts/fr_BE/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/fr_CH/acctchrt_business.gnucash-xea  |   6 ++
 data/accounts/fr_CH/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/fr_FR/acctchrt_business.gnucash-xea  |   6 ++
 data/accounts/fr_FR/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/he/acctchrt_checkbook.gnucash-xea    |   6 ++
 data/accounts/hr/acctchrt_checkbook.gnucash-xea    |   6 ++
 data/accounts/hr/acctchrt_common.gnucash-xea       |   6 ++
 data/accounts/hu/acctchrt_business.gnucash-xea     |   6 ++
 data/accounts/hu/acctchrt_checkbook.gnucash-xea    |   6 ++
 data/accounts/hu/acctchrt_common.gnucash-xea       |   6 ++
 data/accounts/it/acctchrt_checkbook.gnucash-xea    |   6 ++
 data/accounts/it/acctchrt_common.gnucash-xea       |   6 ++
 data/accounts/ja/acctchrt_business.gnucash-xea     |   6 ++
 data/accounts/ja/acctchrt_checkbook.gnucash-xea    |   6 ++
 data/accounts/ja/acctchrt_common.gnucash-xea       |   6 ++
 data/accounts/ja/acctchrt_full.gnucash-xea         |   6 ++
 data/accounts/lv/acctchrt_checkbook.gnucash-xea    |   6 ++
 data/accounts/lv/acctchrt_common.gnucash-xea       |   6 ++
 data/accounts/lv/acctchrt_full.gnucash-xea         |   6 ++
 data/accounts/nb/acctchrt_common.gnucash-xea       |   6 ++
 data/accounts/nb/acctchrt_full.gnucash-xea         |   6 ++
 data/accounts/nl/acctchrt_checkbook.gnucash-xea    |   6 ++
 data/accounts/nl/acctchrt_full.gnucash-xea         |   6 ++
 data/accounts/pl/acctchrt_business.gnucash-xea     |   6 ++
 data/accounts/pl/acctchrt_checkbook.gnucash-xea    |   6 ++
 data/accounts/pl/acctchrt_common.gnucash-xea       |   6 ++
 data/accounts/pl/acctchrt_full.gnucash-xea         |   6 ++
 data/accounts/pt_BR/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/pt_PT/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/ru/acctchrt_common.gnucash-xea       |   6 ++
 data/accounts/tr_TR/acctchrt_TEKDUZ.gnucash-xea    |  12 +++
 data/accounts/zh_CN/acctchrt_business.gnucash-xea  |   6 ++
 data/accounts/zh_CN/acctchrt_checkbook.gnucash-xea |   6 ++
 data/accounts/zh_CN/acctchrt_common.gnucash-xea    |   6 ++
 data/accounts/zh_CN/acctchrt_full.gnucash-xea      |   6 ++
 gnucash/gnome-utils/dialog-account.c               |  70 ++++++++++++
 gnucash/gnome-utils/gnc-tree-model-account.c       |   6 ++
 gnucash/gnome-utils/gnc-tree-model-account.h       |   3 +-
 gnucash/gnome-utils/gnc-tree-view-account.c        |  31 ++++++
 gnucash/gnome/assistant-hierarchy.c                |  14 +--
 gnucash/gnome/gnc-plugin-page-account-tree.c       |  12 +++
 gnucash/gtkbuilder/dialog-account.glade            |  17 +++
 libgnucash/app-utils/gnc-ui-util.c                 |  32 +++++-
 libgnucash/app-utils/gnc-ui-util.h                 |   5 +
 libgnucash/engine/Account.cpp                      |  52 +++++++++
 libgnucash/engine/Account.h                        |  25 +++++
 libgnucash/engine/gnc-features.c                   |   1 +
 libgnucash/engine/gnc-features.h                   |   1 +
 libgnucash/engine/test/utest-Account.cpp           |   4 +-
 util/add-opening-balances                          | 118 +++++++++++++++++++++
 75 files changed, 747 insertions(+), 10 deletions(-)
 create mode 100755 util/add-opening-balances



More information about the gnucash-changes mailing list