Skip to content

Commit

Permalink
Bug #144669: Lookup accounts in the register based on the account cod…
Browse files Browse the repository at this point in the history
…e as well.

Patch from C. Ernst to search for an account by code if the lookup by name for
the string entered into the register did not find anything.

BP


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17253 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
andi5 committed Jul 4, 2008
1 parent 06f27da commit b3f9fe8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
33 changes: 33 additions & 0 deletions src/engine/Account.c
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,39 @@ gnc_account_lookup_by_name (const Account *parent, const char * name)
return NULL;
}

Account *
gnc_account_lookup_by_code (const Account *parent, const char * code)
{
AccountPrivate *cpriv, *ppriv;
Account *child, *result;
GList *node;

g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
g_return_val_if_fail(code, NULL);

/* first, look for accounts hanging off the current node */
ppriv = GET_PRIVATE(parent);
for (node = ppriv->children; node; node = node->next)
{
child = node->data;
cpriv = GET_PRIVATE(child);
if (safe_strcmp(cpriv->accountCode, code) == 0)
return child;
}

/* if we are still here, then we haven't found the account yet.
* Recursively search each of the child accounts next */
for (node = ppriv->children; node; node = node->next)
{
child = node->data;
result = gnc_account_lookup_by_code (child, code);
if (result)
return result;
}

return NULL;
}

/********************************************************************\
* Fetch an account, given its full name *
\********************************************************************/
Expand Down
8 changes: 7 additions & 1 deletion src/engine/Account.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ gboolean xaccAccountHasAncestor(const Account *acc, const Account *ancestor);

/** @} */

/** @name Getting Accounts and Subaccounts by Name
/** @name Lookup Accounts and Subaccounts by name or code
@{
*/
/** The gnc_account_lookup_by_name() subroutine fetches the account by
Expand All @@ -899,6 +899,12 @@ Account *gnc_account_lookup_by_name (const Account *parent, const char *name);
Account *gnc_account_lookup_by_full_name (const Account *any_account,
const gchar *name);

/** The gnc_account_lookup_full_name() subroutine works like
* gnc_account_lookup_by_name, but uses the account code.
*/
Account *gnc_account_lookup_by_code (const Account *parent,
const char *code);

/** @} */

/* ------------------ */
Expand Down
16 changes: 9 additions & 7 deletions src/register/ledger-core/split-register.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,8 @@ gnc_split_register_get_account_by_name (SplitRegister *reg, BasicCell * bcell,

/* Find the account */
account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (), name);
if (!account)
account = gnc_account_lookup_by_code (gnc_get_current_root_account (), name);

if (!account) {
/* Ask if they want to create a new one. */
Expand All @@ -1519,15 +1521,15 @@ gnc_split_register_get_account_by_name (SplitRegister *reg, BasicCell * bcell,
account = gnc_ui_new_accounts_from_name_window (name);
if (!account)
return NULL;
*refresh = TRUE;

/* Now have a new account. Update the cell with the name as created. */
fullname = xaccAccountGetFullName (account);
gnc_combo_cell_set_value (cell, fullname);
gnc_basic_cell_set_changed (&cell->cell, TRUE);
g_free (fullname);
}

/* Now have the account. Update the cell with the name as created. */
*refresh = TRUE;
fullname = xaccAccountGetFullName (account);
gnc_combo_cell_set_value (cell, fullname);
gnc_basic_cell_set_changed (&cell->cell, TRUE);
g_free (fullname);

/* See if the account (either old or new) is a placeholder. */
if (xaccAccountGetPlaceholder (account)) {
gnc_error_dialog (gnc_split_register_get_parent (reg),
Expand Down

0 comments on commit b3f9fe8

Please sign in to comment.