mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug #144669: Lookup accounts in the register based on the account code 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
This commit is contained in:
parent
06f27da852
commit
b3f9fe8534
@ -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 *
|
||||
\********************************************************************/
|
||||
|
@ -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
|
||||
@ -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);
|
||||
|
||||
/** @} */
|
||||
|
||||
/* ------------------ */
|
||||
|
@ -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. */
|
||||
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user