From 8a0d4af1288ef39d42d9e513f78914132f5c9b48 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Tue, 25 Jan 2022 16:46:35 +0000 Subject: [PATCH] Bug 741674 - Newly created Scheduled Transactions appear in existing search windows When a search is done from the 'find' on the accounts page, the search is across all accounts and is displayed in SEARCH_LEDGER. If one of these transactions is used for the basis of a scheduled transaction, the created scheduled transaction is displayed with today's date in the existing search results and also the general ledger with the transfer accounts being displayed with GUID's of the template accounts. Fixed by excluding template accounts from the SEARCH_LEDGER and the GL. --- gnucash/gnome/dialog-find-transactions.c | 30 +------------- .../register/ledger-core/gnc-ledger-display.c | 41 ++++++++++++------- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/gnucash/gnome/dialog-find-transactions.c b/gnucash/gnome/dialog-find-transactions.c index 3adb8e1eaa..88c406b9dd 100644 --- a/gnucash/gnome/dialog-find-transactions.c +++ b/gnucash/gnome/dialog-find-transactions.c @@ -193,35 +193,7 @@ gnc_ui_find_transactions_dialog_create(GtkWindow *parent, GNCLedgerDisplay * ori { start_q = qof_query_create (); qof_query_set_book (start_q, gnc_get_current_book ()); - - /* In lieu of not "mis-using" some portion of the infrastructure by writing - * a bunch of new code, we just filter out the accounts of the template - * transactions. While these are in a separate Account trees just for this - * reason, the query engine makes no distinction between Account trees. - * See Gnome Bug 86302. - * -- jsled - * - * copied from gnc-ledger-display.c:gnc_ledger_display_gl() -- warlord - * - * Alternatively, you could look for a GNC_SX_ACCOUNT [SchedAction.h] - * key in the KVP frame of the split. - */ - { - Account *tRoot; - GList *al; - - tRoot = gnc_book_get_template_root( gnc_get_current_book() ); - al = gnc_account_get_descendants( tRoot ); - - if (g_list_length(al) != 0) - xaccQueryAddAccountMatch( start_q, al, QOF_GUID_MATCH_NONE, QOF_QUERY_AND ); - - g_list_free (al); - al = NULL; - tRoot = NULL; - } - - ftd->q = start_q; /* save this to destroy it later */ + ftd->q = start_q; // save this to destroy it later } ftd->parent = parent; diff --git a/gnucash/register/ledger-core/gnc-ledger-display.c b/gnucash/register/ledger-core/gnc-ledger-display.c index a6c0f33c7c..321202ebe3 100644 --- a/gnucash/register/ledger-core/gnc-ledger-display.c +++ b/gnucash/register/ledger-core/gnc-ledger-display.c @@ -167,6 +167,23 @@ gnc_ledger_display_get_query (GNCLedgerDisplay* ld) return ld->query; } +static void +exclude_template_accounts (Query* q) +{ + Account* tRoot; + GList* al; + + tRoot = gnc_book_get_template_root (gnc_get_current_book()); + al = gnc_account_get_descendants (tRoot); + + if (gnc_list_length_cmp (al, 0)) + xaccQueryAddAccountMatch (q, al, QOF_GUID_MATCH_NONE, QOF_QUERY_AND); + + g_list_free (al); + al = NULL; + tRoot = NULL; +} + static gboolean find_by_leader (gpointer find_data, gpointer user_data) { @@ -423,20 +440,8 @@ gnc_ledger_display_gl (void) * reason, the query engine makes no distinction between Account trees. * See Gnome Bug 86302. * -- jsled */ - { - Account* tRoot; - GList* al; - - tRoot = gnc_book_get_template_root (gnc_get_current_book()); - al = gnc_account_get_descendants (tRoot); - - if (gnc_list_length_cmp (al, 0)) - xaccQueryAddAccountMatch (query, al, QOF_GUID_MATCH_NONE, QOF_QUERY_AND); - - g_list_free (al); - al = NULL; - tRoot = NULL; - } + // Exclude any template accounts for search register and gl + exclude_template_accounts (query); gnc_tm_get_today_start (&tm); tm.tm_mon--; /* Default the register to the last month's worth of transactions. */ @@ -604,6 +609,10 @@ refresh_handler (GHashTable* changes, gpointer user_data) g_list_free (accounts); } + // Exclude any template accounts for search register and gl + if (!ld->reg->is_template && (ld->reg->type == SEARCH_LEDGER || ld->ld_type == LD_GL)) + exclude_template_accounts (ld->query); + /* Its not clear if we should re-run the query, or if we should * just use qof_query_last_run(). Its possible that the dates * changed, requiring a full new query. Similar considerations @@ -895,6 +904,10 @@ gnc_ledger_display_refresh (GNCLedgerDisplay* ld) return; } + // Exclude any template accounts for search register and gl + if (!ld->reg->is_template && (ld->reg->type == SEARCH_LEDGER || ld->ld_type == LD_GL)) + exclude_template_accounts (ld->query); + gnc_ledger_display_refresh_internal (ld, qof_query_run (ld->query)); LEAVE (" "); }