Factor out and create new function: gnc_commodity_is_currency().

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13507 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Chris Shoemaker
2006-03-07 02:42:12 +00:00
parent 3f6896e82e
commit a914a4da55
4 changed files with 23 additions and 10 deletions

View File

@@ -354,10 +354,7 @@ xaccTransScrubCurrencyFromSplits(Transaction *trans)
gnc_commodity *s_commodity = xaccAccountGetCommodity (s_account);
if (s_commodity) {
const char * namespace = gnc_commodity_get_namespace (s_commodity);
if (!safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) ||
!safe_strcmp (namespace, GNC_COMMODITY_NS_LEGACY)) {
if (gnc_commodity_is_currency(s_commodity)) {
/* Found a split where the amount is the same as the value and
the commodity is a currency. If all splits in the transaction
that fit this description are in the same currency then the

View File

@@ -1334,6 +1334,17 @@ gnc_commodity_is_iso(const gnc_commodity * cm)
return (safe_strcmp(ns_name, GNC_COMMODITY_NS_ISO) == 0);
}
gboolean
gnc_commodity_is_currency(const gnc_commodity *cm)
{
const char *ns_name;
if (!cm) return FALSE;
ns_name = gnc_commodity_namespace_get_name(cm->namespace);
return (!safe_strcmp(ns_name, GNC_COMMODITY_NS_LEGACY) ||
!safe_strcmp(ns_name, GNC_COMMODITY_NS_ISO));
}
/********************************************************************
* gnc_commodity_table_get_commodities
* list commodities in a give namespace

View File

@@ -574,6 +574,15 @@ gboolean gnc_commodity_namespace_is_iso(const char *namespace);
*
* @return TRUE if the commodity represents a currency, FALSE otherwise. */
gboolean gnc_commodity_is_iso(const gnc_commodity * cm);
/** Checks to see if the specified commodity is an ISO 4217 recognized
* currency or a legacy currency.
*
* @param cm The commodity to check.
*
* @return TRUE if the commodity represents a currency, FALSE otherwise. */
gboolean gnc_commodity_is_currency(const gnc_commodity *cm);
/** @} */

View File

@@ -194,12 +194,8 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
*/
if (default_account != NULL) {
gnc_commodity * commodity = xaccAccountGetCommodity (default_account);
if (commodity) {
const char * namespace = gnc_commodity_get_namespace (commodity);
if (!safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) ||
!safe_strcmp (namespace, GNC_COMMODITY_NS_LEGACY))
currency = commodity;
}
if (gnc_commodity_is_currency(commodity))
currency = commodity;
}
gnc_suspend_gui_refresh ();