gnucash maint: Bug 798664 - Result of 'gnucash --nofile' is marked dirty

John Ralls jralls at code.gnucash.org
Mon Dec 12 14:33:39 EST 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/b4bab92d (commit)
	from  https://github.com/Gnucash/gnucash/commit/fae5de80 (commit)



commit b4bab92da21e294f4f54dade5aee27a8be66ee85
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Dec 12 11:23:53 2022 -0800

    Bug 798664 - Result of 'gnucash --nofile' is marked dirty
    
    Don't create a new book in the new-user dialog unless the user says to.
    Don't automatically create a new book when retrieving default commodities
    because the retrieve might be requested in a context like the Preferences
    dialog when there is no book.
    
    Some report tests relied on requesting the default commodity creating
    the book, so in those tests ensure that the book is created first.

diff --git a/bindings/guile/test/test-engine-extras.scm b/bindings/guile/test/test-engine-extras.scm
index 7b12a18d8..a6a060202 100644
--- a/bindings/guile/test/test-engine-extras.scm
+++ b/bindings/guile/test/test-engine-extras.scm
@@ -1049,6 +1049,5 @@
      (list (vector bank   150  150)
            (vector aapl  -150    0))
      #:description "spin-off $150")
-
     account-alist))
 
diff --git a/gnucash/gnome-utils/dialog-preferences.c b/gnucash/gnome-utils/dialog-preferences.c
index 62d40ddcd..b2be9d298 100644
--- a/gnucash/gnome-utils/dialog-preferences.c
+++ b/gnucash/gnome-utils/dialog-preferences.c
@@ -75,6 +75,7 @@
 #include "gnc-prefs.h"
 #include "gnc-ui.h"
 #include "gnc-ui-util.h"
+#include <gnc-session.h>
 #include "gnc-component-manager.h"
 #include "dialog-preferences.h"
 #include "dialog-doclink-utils.h"
@@ -122,10 +123,14 @@ GSList *add_ins = NULL;
 static gchar *gnc_account_separator_is_valid (const gchar *separator,
                                               gchar **normalized_separator)
 {
-    QofBook *book = gnc_get_current_book ();
+    QofBook *book;
     GList *conflict_accts = NULL;
     gchar *message = NULL;
 
+    if (!gnc_current_session_exist())
+        return NULL;
+
+    book = gnc_get_current_book ();
     *normalized_separator = gnc_normalize_account_separator (separator);
     conflict_accts = gnc_account_list_name_violations (book, *normalized_separator);
     if (conflict_accts)
@@ -151,7 +156,7 @@ gnc_account_separator_pref_changed_cb (GtkEntry *entry, GtkWidget *dialog)
 {
     GtkWidget *label, *image;
     gchar *sample;
-    gchar *separator;
+    gchar *separator = NULL;
 
     gchar *conflict_msg = gnc_account_separator_is_valid (gtk_entry_get_text (entry), &separator);
 
@@ -200,7 +205,7 @@ gnc_account_separator_validate (GtkWidget *dialog)
 {
     GtkWidget *entry = g_object_get_data (G_OBJECT(dialog), "account-separator");
     gboolean ret = TRUE;
-    gchar *separator;
+    gchar *separator = NULL;
     gchar *conflict_msg = gnc_account_separator_is_valid (gtk_entry_get_text (GTK_ENTRY(entry)), &separator);
 
     /* Check if the new separator clashes with existing account names */
@@ -1337,7 +1342,6 @@ gnc_preferences_dialog_create (GtkWindow *parent)
     GtkTreeIter iter;
     gnc_commodity *locale_currency;
     const gchar *currency_name;
-    QofBook *book;
     GDate fy_end;
     gboolean date_is_valid = FALSE;
 
@@ -1412,11 +1416,14 @@ gnc_preferences_dialog_create (GtkWindow *parent)
                             prefs_table, (GDestroyNotify)g_hash_table_destroy);
 
 
-    book = gnc_get_current_book ();
-    g_date_clear (&fy_end, 1);
-    qof_instance_get (QOF_INSTANCE(book),
-                      "fy-end", &fy_end,
-                      NULL);
+    if (gnc_current_session_exist())
+    {
+        QofBook *book = gnc_get_current_book ();
+        g_date_clear (&fy_end, 1);
+        qof_instance_get (QOF_INSTANCE(book),
+                          "fy-end", &fy_end,
+                          NULL);
+    }
     box = GTK_WIDGET(gtk_builder_get_object (builder,
                      "pref/" GNC_PREFS_GROUP_ACCT_SUMMARY "/" GNC_PREF_START_PERIOD));
     period = gnc_period_select_new (TRUE);
diff --git a/gnucash/gnome/dialog-new-user.c b/gnucash/gnome/dialog-new-user.c
index ef1aebd18..234566155 100644
--- a/gnucash/gnome/dialog-new-user.c
+++ b/gnucash/gnome/dialog-new-user.c
@@ -123,7 +123,6 @@ gnc_ui_new_user_ok_cb (GtkWidget * widget, gpointer data)
     else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (new_user->tutorial_button)))
     {
         gnc_gnome_help (GTK_WINDOW(new_user->window), HF_GUIDE, NULL);
-        gncp_new_user_finish ();
     }
     gtk_widget_destroy (new_user->window);
 }
@@ -198,7 +197,6 @@ gnc_ui_new_user_cancel_dialog (GtkWindow *parent)
     keepshowing = (result == GTK_RESPONSE_YES);
 
     gnc_set_first_startup (keepshowing);
-    gncp_new_user_finish ();
 
     g_object_unref(G_OBJECT(builder));
     gtk_widget_destroy(dialog);
diff --git a/gnucash/report/reports/standard/test/test-average-balance.scm b/gnucash/report/reports/standard/test/test-average-balance.scm
index 7dbb6219c..1ca9e3535 100644
--- a/gnucash/report/reports/standard/test/test-average-balance.scm
+++ b/gnucash/report/reports/standard/test/test-average-balance.scm
@@ -43,6 +43,7 @@
 
 (define (test-average-balance)
   (let* ((env (create-test-env))
+         (book (gnc-get-current-book))
          (account-alist (env-create-account-structure-alist env structure))
          (options (gnc:make-report-options uuid))
          (bank (cdr (assoc "Bank" account-alist)))
diff --git a/gnucash/report/reports/standard/test/test-balsheet-pnl.scm b/gnucash/report/reports/standard/test/test-balsheet-pnl.scm
index e2d0489f6..fa2adf5ea 100644
--- a/gnucash/report/reports/standard/test/test-balsheet-pnl.scm
+++ b/gnucash/report/reports/standard/test/test-balsheet-pnl.scm
@@ -49,7 +49,9 @@
    (gnc-commodity-get-namespace (gnc-default-report-currency))
    sym))
 
-(define USD (gnc-default-report-currency)) ;default currency should be USD because LC_ALL="C"
+(define USD
+  (let ((book (gnc-get-current-book))) ; ensure the book is set 
+        (gnc-default-report-currency))) ;default currency should be USD because LC_ALL="C"
 (define GBP (mnemonic->commodity "GBP"))
 (define FUNDS (gnc-commodity-new (gnc-get-current-book)
                                  "Funds"            ;fullname
@@ -91,6 +93,7 @@
 (define (create-test-data)
   ;; This function will perform implementation testing on the transaction report.
   (let* ((env (create-test-env))
+         (book (gnc-get-current-book))
          (account-alist (env-create-account-structure-alist env structure))
          (bank1savings (cdr (assoc "Savings" account-alist)))
          (bank1bonds (cdr (assoc "Bonds" account-alist)))
diff --git a/gnucash/report/reports/standard/test/test-income-gst.scm b/gnucash/report/reports/standard/test/test-income-gst.scm
index 8c069d8b9..97c267ab4 100644
--- a/gnucash/report/reports/standard/test/test-income-gst.scm
+++ b/gnucash/report/reports/standard/test/test-income-gst.scm
@@ -76,6 +76,7 @@
           (list "Expenses" (list (cons 'type ACCT-TYPE-EXPENSE)))))
   ;; This function will perform implementation testing on the GST report.
   (let* ((env (create-test-env))
+         (book (gnc-get-current-book))
          (account-alist (env-create-account-structure-alist env structure))
          (bank (cdr (assoc "Bank" account-alist)))
          (income (cdr (assoc "Income" account-alist)))
@@ -224,6 +225,7 @@
                 (list "EU Reverse VAT Expenses"))))
   ;; This function will perform implementation testing on the VAT report.
   (let* ((env (create-test-env))
+         (book (gnc-get-current-book))
          (account-alist (env-create-account-structure-alist env structure))
          (YEAR (gnc:time64-get-year (gnc:get-today))))
 
diff --git a/gnucash/report/reports/standard/test/test-portfolios.scm b/gnucash/report/reports/standard/test/test-portfolios.scm
index 298d072e0..01f0a3856 100644
--- a/gnucash/report/reports/standard/test/test-portfolios.scm
+++ b/gnucash/report/reports/standard/test/test-portfolios.scm
@@ -66,7 +66,7 @@
 
 (define (portfolio-tests)
   (test-group-with-cleanup "portfolio-tests"
-    (let* ((account-alist (create-stock-test-data))
+    (let ((account-alist (create-stock-test-data))
            (options (gnc:make-report-options portfolio-uuid)))
       (set-option! options "General" "Price Source" 'pricedb-latest)
       (let ((sxml (options->sxml portfolio-uuid options "latest")))
@@ -97,7 +97,8 @@
 
 (define (advanced-tests)
   (test-group-with-cleanup "advanced-portfolio-tests"
-    (let ((account-alist (create-stock-test-data))
+;; let* required here to ensure that the book is created before creating the options.
+    (let* ((account-alist (create-stock-test-data))
           (options (gnc:make-report-options advanced-uuid)))
       (let ((sxml (options->sxml advanced-uuid options "basic average")))
         (test-equal "advanced: average basis"
diff --git a/gnucash/report/test/test-report-utilities.scm b/gnucash/report/test/test-report-utilities.scm
index ce3816673..1016e3999 100644
--- a/gnucash/report/test/test-report-utilities.scm
+++ b/gnucash/report/test/test-report-utilities.scm
@@ -38,6 +38,7 @@
 (define (test-account-get-trans-type-splits-interval)
   (test-group-with-cleanup "test-account-get-trans-type-splits-interval"
   (let* ((env (create-test-env))
+         (book (gnc-get-current-book))
          (ts-now (gnc-localtime (current-time)))
          (test-day (tm:mday ts-now))
          (test-month (+ 1 (tm:mon ts-now)))
@@ -287,6 +288,7 @@
 
 (define (create-test-data)
   (let* ((env (create-test-env))
+         (book (gnc-get-current-book))
          (account-alist (env-create-account-structure-alist env (structure)))
          (asset (cdr (assoc "Asset" account-alist)))
          (bank (cdr (assoc "Bank" account-alist)))
@@ -613,6 +615,7 @@
 (define (test-get-account-at-dates)
   (test-group-with-cleanup "test-get-balance-at-dates"
     (let* ((env (create-test-env))
+           (book (gnc-get-current-book))
            (structure (list "Root" (list (cons 'type ACCT-TYPE-ASSET))
                             (list "Asset"
                                   (list "Bank1")
diff --git a/libgnucash/app-utils/gnc-ui-util.c b/libgnucash/app-utils/gnc-ui-util.c
index c3a829582..8e1a74009 100644
--- a/libgnucash/app-utils/gnc-ui-util.c
+++ b/libgnucash/app-utils/gnc-ui-util.c
@@ -565,7 +565,9 @@ gnc_get_current_root_account (void)
 gnc_commodity_table *
 gnc_get_current_commodities (void)
 {
-    return gnc_commodity_table_get_table (gnc_get_current_book ());
+     if (gnc_current_session_exist())
+          return gnc_commodity_table_get_table (gnc_get_current_book ());
+     return NULL;
 }
 
 gchar *
@@ -1170,10 +1172,13 @@ gnc_default_currency_common (gchar *requested_currency,
                                           GNC_COMMODITY_NS_CURRENCY,
                                           requested_currency);
 
-    if (gnc_book_use_book_currency (gnc_get_current_book ()))
+    if (gnc_current_session_exist() &&
+        gnc_book_use_book_currency (gnc_get_current_book ()))
         return gnc_book_get_book_currency (gnc_get_current_book ());
 
-    if (gnc_prefs_get_bool (section, GNC_PREF_CURRENCY_CHOICE_OTHER))
+
+    if (gnc_current_session_exist() &&
+        gnc_prefs_get_bool (section, GNC_PREF_CURRENCY_CHOICE_OTHER))
     {
         mnemonic = gnc_prefs_get_string(section, GNC_PREF_CURRENCY_OTHER);
         currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
@@ -1185,11 +1190,13 @@ gnc_default_currency_common (gchar *requested_currency,
 
     if (!currency)
         currency = gnc_locale_default_currency ();
+
     if (currency)
     {
         mnemonic = requested_currency;
         g_free(mnemonic);
     }
+
     return currency;
 }
 



Summary of changes:
 bindings/guile/test/test-engine-extras.scm         |  1 -
 gnucash/gnome-utils/dialog-preferences.c           | 25 ++++++++++++++--------
 gnucash/gnome/dialog-new-user.c                    |  2 --
 .../reports/standard/test/test-average-balance.scm |  1 +
 .../reports/standard/test/test-balsheet-pnl.scm    |  5 ++++-
 .../reports/standard/test/test-income-gst.scm      |  2 ++
 .../reports/standard/test/test-portfolios.scm      |  5 +++--
 gnucash/report/test/test-report-utilities.scm      |  3 +++
 libgnucash/app-utils/gnc-ui-util.c                 | 13 ++++++++---
 9 files changed, 39 insertions(+), 18 deletions(-)



More information about the gnucash-changes mailing list