r17814 - gnucash/trunk/src - Fix currency replacements.

Andreas Köhler andi5 at cvs.gnucash.org
Sun Jan 11 16:00:54 EST 2009


Author: andi5
Date: 2009-01-11 16:00:54 -0500 (Sun, 11 Jan 2009)
New Revision: 17814
Trac: http://svn.gnucash.org/trac/changeset/17814

Modified:
   gnucash/trunk/src/backend/file/gnc-commodity-xml-v2.c
   gnucash/trunk/src/engine/gnc-commodity.c
Log:
Fix currency replacements.

While loading an xml file, do not look up an internal commodity and modify that,
but rather work on a copy.  When inserting the commodity, apply the same
replacements as in gnc_commodity_table_lookup().

This change should not be necessary on branches/2.2 but it might not do any
harm.


Modified: gnucash/trunk/src/backend/file/gnc-commodity-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/file/gnc-commodity-xml-v2.c	2009-01-11 20:23:12 UTC (rev 17813)
+++ gnucash/trunk/src/backend/file/gnc-commodity-xml-v2.c	2009-01-11 21:00:54 UTC (rev 17814)
@@ -249,7 +249,7 @@
                           gpointer parent_data, gpointer global_data,
                           gpointer *result, const gchar *tag)
 {
-    gnc_commodity *com;
+    gnc_commodity *com, *old_com;
     xmlNodePtr achild;
     xmlNodePtr tree = (xmlNodePtr)data_for_children;
     gxpf_data *gdata = (gxpf_data*)global_data;
@@ -269,9 +269,10 @@
     
     g_return_val_if_fail(tree, FALSE);
 
-    com = gnc_commodity_find_currency(book, tree);
-    if (!com)
-      com = gnc_commodity_new(book, NULL, NULL, NULL, NULL, 0); 
+    com = gnc_commodity_new(book, NULL, NULL, NULL, NULL, 0); 
+    old_com = gnc_commodity_find_currency(book, tree);
+    if (old_com)
+        gnc_commodity_copy(com, old_com);
 
     for(achild = tree->xmlChildrenNode; achild; achild = achild->next)
     {

Modified: gnucash/trunk/src/engine/gnc-commodity.c
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.c	2009-01-11 20:23:12 UTC (rev 17813)
+++ gnucash/trunk/src/engine/gnc-commodity.c	2009-01-11 21:00:54 UTC (rev 17814)
@@ -1770,6 +1770,20 @@
       LEAVE("already in table");
       return c;
     }
+
+    /* Backward compatability support for currencies that have
+     * recently changed. */
+    if (priv->namespace->iso4217) {
+      guint i;
+      for (i = 0; i < GNC_NEW_ISO_CODES; i++) {
+        if (!priv->mnemonic
+            || !strcmp(priv->mnemonic, gnc_new_iso_codes[i].old_code)) {
+          gnc_commodity_set_mnemonic(comm, gnc_new_iso_codes[i].new_code);
+          break;
+        }
+      }
+    }
+
     gnc_commodity_copy (c, comm);
     gnc_commodity_destroy (comm);
     LEAVE("found at %p", c);



More information about the gnucash-changes mailing list