AUDIT: r17253 - gnucash/trunk/src - Bug #144669: Lookup accounts in the register based on the account code as well.

Andreas Köhler andi5 at cvs.gnucash.org
Thu Jul 3 20:41:44 EDT 2008


Author: andi5
Date: 2008-07-03 20:41:44 -0400 (Thu, 03 Jul 2008)
New Revision: 17253
Trac: http://svn.gnucash.org/trac/changeset/17253

Modified:
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/Account.h
   gnucash/trunk/src/register/ledger-core/split-register.c
Log:
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


Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2008-07-02 20:56:33 UTC (rev 17252)
+++ gnucash/trunk/src/engine/Account.c	2008-07-04 00:41:44 UTC (rev 17253)
@@ -2491,6 +2491,39 @@
   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                            *
 \********************************************************************/

Modified: gnucash/trunk/src/engine/Account.h
===================================================================
--- gnucash/trunk/src/engine/Account.h	2008-07-02 20:56:33 UTC (rev 17252)
+++ gnucash/trunk/src/engine/Account.h	2008-07-04 00:41:44 UTC (rev 17253)
@@ -878,7 +878,7 @@
 
 /** @} */
 
-/** @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_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);
+
 /** @} */
 
 /* ------------------ */

Modified: gnucash/trunk/src/register/ledger-core/split-register.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register.c	2008-07-02 20:56:33 UTC (rev 17252)
+++ gnucash/trunk/src/register/ledger-core/split-register.c	2008-07-04 00:41:44 UTC (rev 17253)
@@ -1507,6 +1507,8 @@
 
   /* 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 @@
     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),



More information about the gnucash-changes mailing list