GNOME Bugzilla – Bug 499496
Cannot permanently disable online quote retrieval for currencies.
Last modified: 2018-06-29 21:55:03 UTC
If I have an account which uses a foreign currency, it is not possible to disable online quote retrieval for that currency and have that setting persist when I close and reopen my data file. I can disable online quote retrieval for such a currency, and that setting does take effect until I close the file. However, the next time I load my data file, online quote retrieval for that currency will be reenabled. I wish to permanently disable online quote retrieval for a currency because I use a currency for which online price quotes cannot be retrieved (i.e. online price quotes for that currency always result in an error). As the situation stand right now, I have to disable online quote retrieval for that currency every time I open my data file.
This problem exists because of some code in the function xaccAccountSetCommodity (engine/Account.c) that, whenever an account's commodity is set to a currency, automatically enables online quote retrieval for that currency. Because xaccAccountSetCommodity is called for every account that is loaded from a file, this means that online quote retrieval will be enabled for every foreign currency used by an account, even if quote retrieval had been disabled for that currency when the file was saved. This code was added in r8292 to maintain compatibility with GnuCash 1.8, maintained price quote information on the account, rather than on the commodity, and always retrieved price quotes for foreign currency accounts.
Created attachment 101262 [details] [review] Allow quote retreival for currencies used for foreign currency accounts to be disabled This is my initial attempt to address this issue. It removes the code in Account.c (referenced in my previous comment) which automatically enables quote retrieval for currencies when loading accounts that use them. I have added a new property to gnc_commodity objects, used only for currencies, called auto quote control. It is a boolean which indicates whether or not the engine is allowed to automatically change the quote flag for currencies. To avoid needing to make changes to the storage backend, I store this property in the commodity's KVP frame. This requires some fixes to KVP handling for commodities, which I will attach as a separate patch. If preferred, I can instead store this property as a field in the gnc_commodity structure (in which case the other patch would no longer be strictly necessary). The default value for the property is TRUE. If it is changed to FALSE, it will be persisted in the KVP frame as the string "false" under the key "auto_quote_control". If it is changed back to TRUE, the "auto_quote_control" key will be removed from the KVP frame. Because existing GnuCash files will not contain this key, they will properly default to TRUE for this property. Next, I added a non-persistent field to gnc_commodity called usage_count, which keeps track of the number of accounts using that particular commodity. When a commodity is assigned to an account, the usage count for the account's old commodity is decremented and the usage count for the new commodity is incremented. In addition, when an account is deleted, the usage count for its commodity is decremented. When a commodity is first marked as used, via the function gnc_commodity_increment_usage_count, if it is a currency account and auto quote control is enabled for that commodity, quote retrieval will be enabled for that commodity. Similarly, when a commodity is marked as unused, via the function gnc_commodity_decrement_usage_count (that is, no more accounts exist that use it), if it is a currency account and auto quote control is enabled for that commodity, quote retrieval will be disabled for that commodity. This restores the behavior that was present in GnuCash 1.8; currently, quote retrieval is sticky - once it gets auto-enabled, it will stay on until the user disables it even if there are no longer any accounts which use that currency. Finally, for determining when to disable auto quote control, I added a function called gnc_commodity_user_set_quote_flag. This function should be called whenever the quote flag is being changed by the user, rather than being set internally. When called for a currency, this function disables auto quote control if the quote flag is being changed from its default value; that is, if the quote flag is being enabled while there are no accounts using the currency, or if the quote flag is being disabled while there are accounts using the currency. It will then remain disabled until the user changes the quote flag back to the default value. Finally I modified gnc_ui_commodity_dialog_to_object in dialog-commodity.c to call gnc_commodity_user_set_quote_flag instead of gnc_commodity_set_quote_flag. Comments and suggestions for improvement are welcome. I considered exposing the auto quote control property to the user interface as an additional check box in the Edit Currency window, but felt that might be overkill for this issue.
Created attachment 101263 [details] [review] Fixes for KVP frame handling of gnc_commodity objects This patch is required for the first patch I posted to work, but since it is really an orthogonal change, I decided to make it its own patch. There were a couple of places where the KVP frame for gnc_commodity objects was not being handled in correctly, which I have attempted to fix. In gnc_commodity_copy, the KVP frame was not being copied - now it is. In gnc_commodity_clone, qof_instance_init_data was not being called - now it is. Also, the KVP frame was not being copied - now it is. The change to call qof_instance_init_data in gnc_commodity_clone required that the prototype of gnc_commodity_clone be changed to take an additional parameter specifying the book to use for the cloned commodity. This change had a bit of a ripple effect to other functions, particulary gnc_commodity_table_copy, which now uses a structure to pass both the destination table and destination book to the table_copy_helper callback, rather than just the destination table.
Committed to trunk as r16730. Thanks!
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=499496. Please update any external references or bookmarks.