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.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17814 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Andreas Köhler 2009-01-11 21:00:54 +00:00
parent cda274944e
commit 73992d8cc9
2 changed files with 19 additions and 4 deletions

View File

@ -249,7 +249,7 @@ gnc_commodity_end_handler(gpointer data_for_children,
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 @@ gnc_commodity_end_handler(gpointer data_for_children,
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)
{

View File

@ -1770,6 +1770,20 @@ gnc_commodity_table_insert(gnc_commodity_table * table,
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);