mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Warn the user before deleting a commodity if there are price quotes
based on that commodity. If the commodity is deleted anyway, delete the price quotes that depend on it. #111643 git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8840 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
28640525f9
commit
aae31451f0
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
||||
2003-07-04 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/gnome/dialog-price-edit-db.c: Add a couple of extra checks
|
||||
to prevent crashing if the commodity attached to a price quote has
|
||||
disappeared. #111643
|
||||
|
||||
* src/gnome/dialog-commodities.c: Provide a new warning message
|
||||
before deletion if a commodity has any quice quotes. If the user
|
||||
deletes the commodity anyway, removed any quotes are based on the
|
||||
commodity
|
||||
|
||||
* src/engine/gnc-pricedb.c: Enhance the get prices routine to
|
||||
handle a request with a NULL currency.
|
||||
|
||||
2003-07-03 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/scm/price-quotes.scm:
|
||||
|
@ -870,8 +870,11 @@ add_price(GNCPriceDB *db, GNCPrice *p)
|
||||
g_hash_table_insert(currency_hash, currency, price_list);
|
||||
p->db = db;
|
||||
|
||||
LEAVE ("db=%p, pr=%p not-saved=%d do-free=%d",
|
||||
db, p, p->not_saved, p->do_free);
|
||||
LEAVE ("db=%p, pr=%p not-saved=%d do-free=%d commodity=%s/%s currency_hash=%p",
|
||||
db, p, p->not_saved, p->do_free,
|
||||
gnc_commodity_get_namespace(p->commodity),
|
||||
gnc_commodity_get_mnemonic(p->commodity),
|
||||
currency_hash);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1069,6 +1072,13 @@ gnc_pricedb_lookup_latest_any_currency(GNCPriceDB *db,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
hash_values_helper(gpointer key, gpointer value, gpointer data)
|
||||
{
|
||||
GList ** l = data;
|
||||
*l = g_list_concat(*l, g_list_copy (value));
|
||||
}
|
||||
|
||||
GList *
|
||||
gnc_pricedb_get_prices(GNCPriceDB *db,
|
||||
gnc_commodity *commodity,
|
||||
@ -1080,7 +1090,7 @@ gnc_pricedb_get_prices(GNCPriceDB *db,
|
||||
GHashTable *currency_hash;
|
||||
|
||||
ENTER ("db=%p commodity=%p currency=%p", db, commodity, currency);
|
||||
if(!db || !commodity || !currency) return NULL;
|
||||
if(!db || !commodity) return NULL;
|
||||
|
||||
if (db->book && db->book->backend && db->book->backend->price_lookup)
|
||||
{
|
||||
@ -1095,10 +1105,14 @@ gnc_pricedb_get_prices(GNCPriceDB *db,
|
||||
currency_hash = g_hash_table_lookup(db->commodity_hash, commodity);
|
||||
if(!currency_hash) return NULL;
|
||||
|
||||
price_list = g_hash_table_lookup(currency_hash, currency);
|
||||
if(!price_list) return NULL;
|
||||
|
||||
result = g_list_copy (price_list);
|
||||
if (currency) {
|
||||
price_list = g_hash_table_lookup(currency_hash, currency);
|
||||
if(!price_list) return NULL;
|
||||
result = g_list_copy (price_list);
|
||||
} else {
|
||||
result = NULL;
|
||||
g_hash_table_foreach(currency_hash, hash_values_helper, (gpointer)&result);
|
||||
}
|
||||
for (node = result; node; node = node->next)
|
||||
gnc_price_ref (node->data);
|
||||
|
||||
|
@ -226,7 +226,10 @@ edit_clicked (GtkWidget *widget, gpointer data)
|
||||
static void
|
||||
remove_clicked (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
QofBook *book;
|
||||
GNCPriceDB *pdb;
|
||||
GList *node;
|
||||
GList *prices;
|
||||
GList *accounts;
|
||||
gboolean do_delete;
|
||||
gboolean can_delete;
|
||||
@ -259,6 +262,20 @@ remove_clicked (GtkWidget *widget, gpointer data)
|
||||
"not delete it.");
|
||||
|
||||
gnc_warning_dialog_parented (cd->dialog, message);
|
||||
g_list_free (accounts);
|
||||
return;
|
||||
}
|
||||
|
||||
book = xaccGroupGetBook (xaccAccountGetRoot (accounts->data));
|
||||
pdb = gnc_pricedb_get_db (book);
|
||||
prices = gnc_pricedb_get_prices(pdb, cd->commodity, NULL);
|
||||
if (prices)
|
||||
{
|
||||
const char *message = _("This commodity has price quotes. Are\n"
|
||||
"you sure you want to delete the selected\n"
|
||||
"commodity and its price quotes?");
|
||||
|
||||
do_delete = gnc_verify_dialog_parented (cd->dialog, TRUE, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -272,6 +289,9 @@ remove_clicked (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
gnc_commodity_table *ct = gnc_get_current_commodities ();
|
||||
|
||||
for (node = prices; node; node = node->next)
|
||||
gnc_pricedb_remove_price(pdb, node->data);
|
||||
|
||||
gnc_commodity_table_remove (ct, cd->commodity);
|
||||
gnc_commodity_destroy (cd->commodity);
|
||||
cd->commodity = NULL;
|
||||
@ -279,7 +299,9 @@ remove_clicked (GtkWidget *widget, gpointer data)
|
||||
gnc_commodities_load_commodities (cd);
|
||||
}
|
||||
|
||||
gnc_price_list_destroy(prices);
|
||||
g_list_free (accounts);
|
||||
gnc_gui_refresh_all ();
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -105,20 +105,24 @@ price_compare (gconstpointer a, gconstpointer b)
|
||||
comm_a = gnc_price_get_commodity (price_a);
|
||||
comm_b = gnc_price_get_commodity (price_b);
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_namespace (comm_a),
|
||||
gnc_commodity_get_namespace (comm_b));
|
||||
if (comm_a && comm_b){
|
||||
SAFE_STRCMP (gnc_commodity_get_namespace (comm_a),
|
||||
gnc_commodity_get_namespace (comm_b));
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a),
|
||||
gnc_commodity_get_mnemonic (comm_b));
|
||||
SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a),
|
||||
gnc_commodity_get_mnemonic (comm_b));
|
||||
}
|
||||
|
||||
comm_a = gnc_price_get_currency (price_a);
|
||||
comm_b = gnc_price_get_currency (price_b);
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_namespace (comm_a),
|
||||
gnc_commodity_get_namespace (comm_b));
|
||||
if (comm_a && comm_b){
|
||||
SAFE_STRCMP (gnc_commodity_get_namespace (comm_a),
|
||||
gnc_commodity_get_namespace (comm_b));
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a),
|
||||
gnc_commodity_get_mnemonic (comm_b));
|
||||
SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a),
|
||||
gnc_commodity_get_mnemonic (comm_b));
|
||||
}
|
||||
|
||||
ts_a = gnc_price_get_time (price_a);
|
||||
ts_b = gnc_price_get_time (price_b);
|
||||
|
Loading…
Reference in New Issue
Block a user