r16819 - gnucash/branches/2.2/src/register/ledger-core - [r16718, r16817] Choose a reasonable currency in stock registers (#116353)

Andreas Köhler andi5 at cvs.gnucash.org
Sat Jan 5 22:01:05 EST 2008


Author: andi5
Date: 2008-01-05 22:01:04 -0500 (Sat, 05 Jan 2008)
New Revision: 16819
Trac: http://svn.gnucash.org/trac/changeset/16819

Modified:
   gnucash/branches/2.2/src/register/ledger-core/split-register-load.c
Log:
[r16718,r16817] Choose a reasonable currency in stock registers (#116353)

Based on the patch from Mike Alexander, walk up the account
tree until we find a "currency" account and use that instead
of always using the locale currency.  Pop up a dialog if this
fails search fails.

Committed by warlord.


Modified: gnucash/branches/2.2/src/register/ledger-core/split-register-load.c
===================================================================
--- gnucash/branches/2.2/src/register/ledger-core/split-register-load.c	2008-01-06 03:00:55 UTC (rev 16818)
+++ gnucash/branches/2.2/src/register/ledger-core/split-register-load.c	2008-01-06 03:01:04 UTC (rev 16819)
@@ -24,11 +24,14 @@
 
 #include "config.h"
 
+#include <glib/gi18n.h>
+
 #include "account-quickfill.h"
 #include "combocell.h"
 #include "gnc-component-manager.h"
 #include "qof.h"
 #include "gnc-ui-util.h"
+#include "gnc-gui-query.h"
 #include "numcell.h"
 #include "quickfillcell.h"
 #include "recncell.h"
@@ -221,7 +224,34 @@
     if (default_account != NULL) {
       gnc_commodity * commodity = xaccAccountGetCommodity (default_account);
       if (gnc_commodity_is_currency(commodity))
-          currency = commodity;
+	currency = commodity;
+      else {
+	Account *parent_account = default_account;
+	/* Account commodity is not a currency, walk up the tree until
+	 * we find a parent account that is a currency account and use
+	 * it's currency.
+	 */
+	do {
+	  parent_account = gnc_account_get_parent ( parent_account );
+	  if (parent_account)
+	  {
+	    commodity = xaccAccountGetCommodity (parent_account);
+	    if (gnc_commodity_is_currency(commodity))
+	    {
+	      currency = commodity;
+	      break;
+	    }
+	  }
+	} while (parent_account && !currency);
+      }
+
+      /* If we don't have a currency then pop up a warning dialog */
+      if (!currency)
+      {
+	gnc_info_dialog(NULL, "%s",
+			_("Could not determine the account currency for this register.  "
+			  "Using the currency obtained from the system's locale setting instead."));
+      }
     }
 
     gnc_suspend_gui_refresh ();



More information about the gnucash-changes mailing list