From 5c524c31b2c953087b70305c24547960e0d5e585 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sat, 22 Dec 2018 18:07:55 +0000 Subject: [PATCH] Add routine to fix Account Color being set to "Not Set" Previously the account color slot has been populated with "Not Set" when any field for the account has been edited and saved. This routine should run once and remove all such entries. --- gnucash/gnome-utils/gnc-file.c | 7 ++++++ libgnucash/engine/Scrub.c | 46 ++++++++++++++++++++++++++++++---- libgnucash/engine/Scrub.h | 5 ++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/gnucash/gnome-utils/gnc-file.c b/gnucash/gnome-utils/gnc-file.c index 2eefc34a69..0f8e0e4bd3 100644 --- a/gnucash/gnome-utils/gnc-file.c +++ b/gnucash/gnome-utils/gnc-file.c @@ -45,6 +45,7 @@ #include "gnc-window.h" #include "gnc-plugin-file-history.h" #include "qof.h" +#include "Scrub.h" #include "TransLog.h" #include "gnc-session.h" #include "gnc-state.h" @@ -1023,6 +1024,12 @@ RESTART: gnc_warning_dialog(parent, "%s", message); g_free ( message ); } + + // Fix account color slots being set to 'Not Set', should run once on a book + qof_event_suspend(); + xaccAccountScrubColorNotSet (gnc_get_current_book()); + qof_event_resume(); + return TRUE; } diff --git a/libgnucash/engine/Scrub.c b/libgnucash/engine/Scrub.c index d6ff1075ff..38aa240569 100644 --- a/libgnucash/engine/Scrub.c +++ b/libgnucash/engine/Scrub.c @@ -1114,15 +1114,15 @@ xaccTransScrubCurrency (Transaction *trans) } else { - gnc_commodity *currency = xaccAccountGetCommodity(split->acc); + gnc_commodity *currency = xaccAccountGetCommodity(split->acc); PWARN ("setting to split=\"%s\" account=\"%s\" commodity=\"%s\"", split->memo, xaccAccountGetName(split->acc), gnc_commodity_get_mnemonic(currency)); - xaccTransBeginEdit (trans); - xaccTransSetCurrency (trans, currency); - xaccTransCommitEdit (trans); - return; + xaccTransBeginEdit (trans); + xaccTransSetCurrency (trans, currency); + xaccTransCommitEdit (trans); + return; } } } @@ -1354,6 +1354,42 @@ xaccAccountScrubKvp (Account *account) /* ================================================================ */ +void +xaccAccountScrubColorNotSet (QofBook *book) +{ + GValue value_s = G_VALUE_INIT; + + // get the run-once value + qof_instance_get_kvp (QOF_INSTANCE (book), &value_s, 1, "remove-color-not-set-slots"); + + if (G_VALUE_HOLDS_STRING (&value_s) && (strcmp(g_value_get_string (&value_s), "true") == 0)) + return; + else + { + GValue value_b = G_VALUE_INIT; + Account *root = gnc_book_get_root_account (book); + GList *accts = gnc_account_get_descendants_sorted (root); + GList *ptr; + + for (ptr = accts; ptr; ptr = g_list_next (ptr)) + { + const gchar *color = xaccAccountGetColor (ptr->data); + + if (g_strcmp0 (color, "Not Set") == 0) + xaccAccountSetColor (ptr->data, ""); + } + g_list_free (accts); + + g_value_init (&value_b, G_TYPE_BOOLEAN); + g_value_set_boolean (&value_b, TRUE); + + // set the run-once value + qof_instance_set_kvp (QOF_INSTANCE (book), &value_b, 1, "remove-color-not-set-slots"); + } +} + +/* ================================================================ */ + Account * xaccScrubUtilityGetOrMakeAccount (Account *root, gnc_commodity * currency, const char *accname, GNCAccountType acctype, diff --git a/libgnucash/engine/Scrub.h b/libgnucash/engine/Scrub.h index d57fadf1d7..9536f8c34b 100644 --- a/libgnucash/engine/Scrub.h +++ b/libgnucash/engine/Scrub.h @@ -145,6 +145,11 @@ void xaccAccountTreeScrubQuoteSources (Account *root, gnc_commodity_table *table /** Removes empty "notes", "placeholder", and "hbci" KVP slots from Accounts. */ void xaccAccountScrubKvp (Account *account); +/** Remove color slots that have a "Not Set" value, since 2.4.0, fixed in 3.4 + * This should only be run once on a book + */ +void xaccAccountScrubColorNotSet (QofBook *book); + /** Changes Transaction date_posted timestamps from 00:00 local to 11:00 UTC. * 11:00 UTC is the same day local time in almost all timezones, the exceptions * being the -12, +13, and +14 timezones along the International Date Line. If