diff --git a/src/engine/Account.c b/src/engine/Account.c index 11080a80ef..9af1816ab4 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -157,6 +157,8 @@ xaccMallocAccount (QofBook *book) Account * xaccCloneAccountSimple(const Account *from, QofBook *book) { + const char * ucom; + const gnc_commodity_table * comtbl; Account *ret; if (!from || !book) return NULL; @@ -178,7 +180,12 @@ xaccCloneAccountSimple(const Account *from, QofBook *book) ret->kvp_data = kvp_frame_copy(from->kvp_data); - ret->commodity = from->commodity; + /* The new book should contain a commodity that matches + * the one in the old book. Find it, use it. */ + ucom = gnc_commodity_get_unique_name (from->commodity); + comtbl = gnc_commodity_table_get_table (book); + ret->commodity = gnc_commodity_table_lookup_unique (comtbl, ucom); + ret->commodity_scu = from->commodity_scu; ret->non_standard_scu = from->non_standard_scu; ret->core_dirty = TRUE; @@ -212,7 +219,12 @@ xaccCloneAccount (const Account *from, QofBook *book, ret->kvp_data = kvp_frame_copy(from->kvp_data); - ret->commodity = from->commodity; + /* The new book should contain a commodity that matches + * the one in the old book. Find it, use it. */ + ucom = gnc_commodity_get_unique_name (from->commodity); + comtbl = gnc_commodity_table_get_table (book); + ret->commodity = gnc_commodity_table_lookup_unique (comtbl, ucom); + ret->commodity_scu = from->commodity_scu; ret->non_standard_scu = from->non_standard_scu; ret->core_dirty = TRUE; diff --git a/src/engine/Account.h b/src/engine/Account.h index 8b50ce3462..849843df38 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -118,9 +118,13 @@ Account * xaccCloneAccount (const Account *from, QofBook *book, /** The xaccCloneAccountSimple() routine makes a simple copy of the * indicated account, placing it in the indicated book. It copies * the account type, name, description, and the kvp values; - * it does not copy splits/transactions. Note also that it - * does NOT use the 'gemini' kvp value to indicate where it - * was copied from.*/ + * it does not copy splits/transactions. The book should have + * a commodity table in it that has commodities with the same + * unique name as the ones being copied in the account (the + * commodities in the clone will be those from the book). + * Note that this routines does *NOT* use the 'gemini' kvp value + * to indicate where it was copied from. + */ Account * xaccCloneAccountSimple (const Account *from, QofBook *book); /** The xaccAccountBeginEdit() subroutine is the first phase of