mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Prevent template accounts being excluded multiple times
Use a hash table to record the template accounts that have been excluded so they are not added multiple times.
This commit is contained in:
parent
8a0d4af128
commit
1f17881613
@ -70,6 +70,8 @@ struct gnc_ledger_display
|
||||
GNCLedgerDisplayDestroy destroy;
|
||||
GNCLedgerDisplayGetParent get_parent;
|
||||
|
||||
GHashTable *excluded_template_acc_hash;
|
||||
|
||||
gpointer user_data;
|
||||
|
||||
gint number_of_subaccounts;
|
||||
@ -168,7 +170,7 @@ gnc_ledger_display_get_query (GNCLedgerDisplay* ld)
|
||||
}
|
||||
|
||||
static void
|
||||
exclude_template_accounts (Query* q)
|
||||
exclude_template_accounts (Query* q, GHashTable *excluded_template_acc_hash)
|
||||
{
|
||||
Account* tRoot;
|
||||
GList* al;
|
||||
@ -176,6 +178,21 @@ exclude_template_accounts (Query* q)
|
||||
tRoot = gnc_book_get_template_root (gnc_get_current_book());
|
||||
al = gnc_account_get_descendants (tRoot);
|
||||
|
||||
if (gnc_list_length_cmp (al, 0) && excluded_template_acc_hash)
|
||||
{
|
||||
GList *node, *next;
|
||||
|
||||
for (node = al; node; node = next)
|
||||
{
|
||||
Account *acc = node->data;
|
||||
next = g_list_next (node);
|
||||
|
||||
if (g_hash_table_lookup (excluded_template_acc_hash, acc) != NULL)
|
||||
al = g_list_delete_link (al, node);
|
||||
else
|
||||
g_hash_table_insert (excluded_template_acc_hash, acc, acc);
|
||||
}
|
||||
}
|
||||
if (gnc_list_length_cmp (al, 0))
|
||||
xaccQueryAddAccountMatch (q, al, QOF_GUID_MATCH_NONE, QOF_QUERY_AND);
|
||||
|
||||
@ -427,6 +444,7 @@ gnc_ledger_display_gl (void)
|
||||
time64 start;
|
||||
struct tm tm;
|
||||
GNCLedgerDisplay* ld;
|
||||
GHashTable *exclude_template_accounts_hash;
|
||||
|
||||
ENTER (" ");
|
||||
|
||||
@ -434,6 +452,8 @@ gnc_ledger_display_gl (void)
|
||||
|
||||
qof_query_set_book (query, gnc_get_current_book());
|
||||
|
||||
exclude_template_accounts_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||
|
||||
/* 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
|
||||
@ -441,7 +461,7 @@ gnc_ledger_display_gl (void)
|
||||
* See Gnome Bug 86302.
|
||||
* -- jsled */
|
||||
// Exclude any template accounts for search register and gl
|
||||
exclude_template_accounts (query);
|
||||
exclude_template_accounts (query, exclude_template_accounts_hash);
|
||||
|
||||
gnc_tm_get_today_start (&tm);
|
||||
tm.tm_mon--; /* Default the register to the last month's worth of transactions. */
|
||||
@ -453,6 +473,8 @@ gnc_ledger_display_gl (void)
|
||||
|
||||
ld = gnc_ledger_display_internal (NULL, query, LD_GL, GENERAL_JOURNAL,
|
||||
REG_STYLE_JOURNAL, FALSE, FALSE, FALSE);
|
||||
|
||||
ld->excluded_template_acc_hash = exclude_template_accounts_hash;
|
||||
LEAVE ("%p", ld);
|
||||
|
||||
qof_query_destroy (query);
|
||||
@ -611,7 +633,7 @@ refresh_handler (GHashTable* changes, gpointer user_data)
|
||||
|
||||
// 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);
|
||||
exclude_template_accounts (ld->query, ld->excluded_template_acc_hash);
|
||||
|
||||
/* 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
|
||||
@ -643,6 +665,10 @@ close_handler (gpointer user_data)
|
||||
gnc_split_register_destroy (ld->reg);
|
||||
ld->reg = NULL;
|
||||
|
||||
// Destroy the excluded template account hash
|
||||
if (ld->excluded_template_acc_hash)
|
||||
g_hash_table_destroy (ld->excluded_template_acc_hash);
|
||||
|
||||
qof_query_destroy (ld->query);
|
||||
ld->query = NULL;
|
||||
|
||||
@ -718,6 +744,8 @@ gnc_ledger_display_query (Query* query, SplitRegisterType type,
|
||||
|
||||
ld = gnc_ledger_display_internal (NULL, query, LD_GL, type, style,
|
||||
FALSE, FALSE, FALSE);
|
||||
|
||||
ld->excluded_template_acc_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||
LEAVE ("%p", ld);
|
||||
return ld;
|
||||
}
|
||||
@ -811,6 +839,7 @@ gnc_ledger_display_internal (Account* lead_account, Query* q,
|
||||
ld->destroy = NULL;
|
||||
ld->get_parent = NULL;
|
||||
ld->user_data = NULL;
|
||||
ld->excluded_template_acc_hash = NULL;
|
||||
|
||||
limit = gnc_prefs_get_float (GNC_PREFS_GROUP_GENERAL_REGISTER,
|
||||
GNC_PREF_MAX_TRANS);
|
||||
@ -906,7 +935,7 @@ gnc_ledger_display_refresh (GNCLedgerDisplay* ld)
|
||||
|
||||
// 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);
|
||||
exclude_template_accounts (ld->query, ld->excluded_template_acc_hash);
|
||||
|
||||
gnc_ledger_display_refresh_internal (ld, qof_query_run (ld->query));
|
||||
LEAVE (" ");
|
||||
|
Loading…
Reference in New Issue
Block a user