mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-12-01 04:59:29 -06:00
Better integrate stock prices with QOF. Gnucash now warns you about
unsaved stock price changes. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12056 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
140f159372
commit
2da447961a
22
ChangeLog
22
ChangeLog
@ -1,3 +1,13 @@
|
||||
2005-11-27 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/backend/file/io-gncbin-r.c:
|
||||
* src/backend/file/gnc-pricedb-xml-v2.c:
|
||||
* src/backend/file/io-gncxml-v1.c:
|
||||
* src/backend/postgres/price.c:
|
||||
* src/engine/gnc-pricedb.[ch]:
|
||||
* src/engine/gnc-pricedb-p.h: Better integrate stock prices with
|
||||
QOF. Gnucash now warns you about unsaved stock price changes.
|
||||
|
||||
2005-11-26 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/gnome/gnc-plugin-page-register.c: Change "Reverse
|
||||
@ -1652,7 +1662,7 @@
|
||||
* src/engine/Period.h: Doxygen tweak.
|
||||
* src/engine/Transaction.c: qof_begin_edit changes.
|
||||
* src/engine/gnc-engine.c: Load the two default GModules.
|
||||
* src/engine/gnc-pricedb.c: Pair up the ENTER and LEAVE calls.
|
||||
* src/engine/gnc-pricedb.c: Pair up the ENTER printf c%s: alls.
|
||||
* src/engine/gnc-trace.c: QOF sync.
|
||||
* src/engine/gnc-trace.h: QOF Sync
|
||||
* src/engine/qof-be-utils.h: qof_begin_edit changes.
|
||||
@ -1880,7 +1890,7 @@
|
||||
* src/report/standard-reports/transaction.scm:
|
||||
* src/app-utils/date-utilities.scm:
|
||||
* src/app-utils/app-utils.scm:
|
||||
Add "Quarterly" option to transaction report. Add support
|
||||
Add "Q __FUNCTION__,uarterly" option to transaction report. Add support
|
||||
functions to app-utils.scm and date-utilities.scm to support
|
||||
finding the quarter of a given date, and to format it as Q1, Q2,
|
||||
Q3, or Q4. Fix a bug in the as-yet-unused function
|
||||
@ -2040,8 +2050,8 @@
|
||||
applications.
|
||||
* src/engine/qofbook.h
|
||||
* src/engine/qofbook.c: New trace subsystem, qof.h
|
||||
fixes and test-period fixes. Balance ENTER and LEAVE
|
||||
in log output.
|
||||
fixes and test-period fixes. Balance ENTER printf
|
||||
%s: in log output.
|
||||
* src/engine/qofquery.c: Balance ENTER and LEAVE.
|
||||
* src/engine/qofsession.c: Balance ENTER and LEAVE
|
||||
and new trace subsystem changes.
|
||||
@ -2214,7 +2224,7 @@
|
||||
2005-09-21 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/gnome-utils/dialog-options.c: Remove remnants of the old
|
||||
"Advanced Preferences" page.
|
||||
"A __FUNCTION__,dvanced Preferences" page.
|
||||
|
||||
* src/app-utils/prefs.scm:
|
||||
* src/gnome/schemas/apps_gnucash_dialog_common.schemas:
|
||||
@ -3455,7 +3465,7 @@
|
||||
Handle new (private) header file, gnc-hooks-scm.h
|
||||
|
||||
* src/engine/gnc-hooks.c:
|
||||
Use ENTER/LEAVE macros instead of commented printfs
|
||||
Use printf m%s: acros instead of commented printfs
|
||||
|
||||
* src/engine/gw-engine-spec.scm:
|
||||
use gnc-hooks-scm.h header
|
||||
|
@ -229,7 +229,7 @@ pricedb_start_handler(GSList* sibling_data,
|
||||
{
|
||||
gxpf_data *gdata = global_data;
|
||||
QofBook *book = gdata->bookdata;
|
||||
GNCPriceDB *db = gnc_pricedb_create(book);
|
||||
GNCPriceDB *db = gnc_book_get_pricedb(book);
|
||||
g_return_val_if_fail(db, FALSE);
|
||||
gnc_pricedb_set_bulk_update(db, TRUE);
|
||||
*result = db;
|
||||
|
@ -199,7 +199,7 @@ cvt_potential_prices_to_pricedb_and_cleanup(GNCPriceDB **prices,
|
||||
{
|
||||
GSList *item = potential_quotes;
|
||||
|
||||
*prices = gnc_pricedb_create(book);
|
||||
*prices = gnc_book_get_pricedb(book);
|
||||
if (!*prices) return FALSE;
|
||||
|
||||
while(item)
|
||||
|
@ -1142,7 +1142,6 @@ ledger_data_after_child_handler(gpointer data_for_children,
|
||||
return FALSE;
|
||||
}
|
||||
status->pricedb = pdb;
|
||||
gnc_pricedb_mark_clean(pdb);
|
||||
child_result->should_cleanup = FALSE;
|
||||
}
|
||||
return(TRUE);
|
||||
@ -3704,7 +3703,7 @@ pricedb_start_handler(GSList* sibling_data,
|
||||
gchar **attrs)
|
||||
{
|
||||
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
|
||||
GNCPriceDB *db = gnc_pricedb_create(pstatus->book);
|
||||
GNCPriceDB *db = gnc_book_get_pricedb(pstatus->book);
|
||||
g_return_val_if_fail(db, FALSE);
|
||||
*result = db;
|
||||
return(TRUE);
|
||||
|
@ -440,10 +440,6 @@ pgendPriceFind (QofBackend *bend, gpointer olook)
|
||||
SEND_QUERY (be, be->buff, );
|
||||
pgendGetResults (be, get_price_cb, NULL);
|
||||
|
||||
/* insertion into the price db will mark it dirty;
|
||||
* but it really isn't at this point. */
|
||||
gnc_pricedb_mark_clean (look->prdb);
|
||||
|
||||
/* re-enable events */
|
||||
pgendEnable(be);
|
||||
gnc_engine_resume_events();
|
||||
|
@ -89,7 +89,6 @@ typedef struct gnc_price_lookup_helper_s
|
||||
} GNCPriceLookupHelper;
|
||||
|
||||
#define gnc_price_set_guid(P,G) qof_entity_set_guid(QOF_ENTITY(P),(G))
|
||||
#define gnc_pricedb_mark_clean(db) qof_instance_mark_clean(QOF_INSTANCE(db))
|
||||
void gnc_pricedb_substitute_commodity(GNCPriceDB *db,
|
||||
gnc_commodity *old_c,
|
||||
gnc_commodity *new_c);
|
||||
|
@ -177,6 +177,21 @@ gnc_pricedb_commit_edit (GNCPriceDB *pdb)
|
||||
/* ==================================================================== */
|
||||
/* setters */
|
||||
|
||||
static void
|
||||
gnc_price_set_dirty (GNCPrice *p)
|
||||
{
|
||||
if (p->db) {
|
||||
qof_instance_set_dirty(&p->inst);
|
||||
return;
|
||||
}
|
||||
|
||||
/* This is a transient price structure, probably for the add new
|
||||
* price dialog. The user may end up cancelling it instead of
|
||||
* saving it, so don't mark the collection dirty. We'll mark it
|
||||
* dirty later if the price is ever saved to the db. */
|
||||
p->inst.dirty = TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_price_set_commodity(GNCPrice *p, gnc_commodity *c)
|
||||
{
|
||||
@ -191,7 +206,7 @@ gnc_price_set_commodity(GNCPrice *p, gnc_commodity *c)
|
||||
remove_price (p->db, p, TRUE);
|
||||
gnc_price_begin_edit (p);
|
||||
p->commodity = c;
|
||||
if(p->db) p->db->inst.dirty = TRUE;
|
||||
gnc_price_set_dirty(p);
|
||||
gnc_price_commit_edit (p);
|
||||
add_price (p->db, p);
|
||||
gnc_price_unref (p);
|
||||
@ -213,7 +228,7 @@ gnc_price_set_currency(GNCPrice *p, gnc_commodity *c)
|
||||
remove_price (p->db, p, TRUE);
|
||||
gnc_price_begin_edit (p);
|
||||
p->currency = c;
|
||||
if(p->db) p->db->inst.dirty = TRUE;
|
||||
gnc_price_set_dirty(p);
|
||||
gnc_price_commit_edit (p);
|
||||
add_price (p->db, p);
|
||||
gnc_price_unref (p);
|
||||
@ -233,7 +248,7 @@ gnc_price_set_time(GNCPrice *p, Timespec t)
|
||||
remove_price (p->db, p, FALSE);
|
||||
gnc_price_begin_edit (p);
|
||||
p->tmspec = t;
|
||||
if(p->db) p->db->inst.dirty = TRUE;
|
||||
gnc_price_set_dirty(p);
|
||||
gnc_price_commit_edit (p);
|
||||
add_price (p->db, p);
|
||||
gnc_price_unref (p);
|
||||
@ -252,7 +267,7 @@ gnc_price_set_source(GNCPrice *p, const char *s)
|
||||
tmp = gnc_string_cache_insert((gpointer) s);
|
||||
if(p->source) gnc_string_cache_remove(p->source);
|
||||
p->source = tmp;
|
||||
if(p->db) p->db->inst.dirty = TRUE;
|
||||
gnc_price_set_dirty(p);
|
||||
gnc_price_commit_edit (p);
|
||||
}
|
||||
}
|
||||
@ -269,7 +284,7 @@ gnc_price_set_type(GNCPrice *p, const char* type)
|
||||
tmp = gnc_string_cache_insert((gpointer) type);
|
||||
if(p->type) gnc_string_cache_remove(p->type);
|
||||
p->type = tmp;
|
||||
if(p->db) p->db->inst.dirty = TRUE;
|
||||
gnc_price_set_dirty(p);
|
||||
gnc_price_commit_edit (p);
|
||||
}
|
||||
}
|
||||
@ -282,7 +297,7 @@ gnc_price_set_value(GNCPrice *p, gnc_numeric value)
|
||||
{
|
||||
gnc_price_begin_edit (p);
|
||||
p->value = value;
|
||||
if(p->db) p->db->inst.dirty = TRUE;
|
||||
gnc_price_set_dirty(p);
|
||||
gnc_price_commit_edit (p);
|
||||
}
|
||||
}
|
||||
@ -574,7 +589,7 @@ commodity_equal (gconstpointer a, gconstpointer b)
|
||||
return gnc_commodity_equiv (ca, cb);
|
||||
}
|
||||
|
||||
GNCPriceDB *
|
||||
static GNCPriceDB *
|
||||
gnc_pricedb_create(QofBook * book)
|
||||
{
|
||||
GNCPriceDB * result;
|
||||
@ -676,6 +691,7 @@ destroy and recreate the book. Yuk.
|
||||
GNCPriceDB *
|
||||
gnc_collection_get_pricedb(QofCollection *col)
|
||||
{
|
||||
if (!col) return NULL;
|
||||
return qof_collection_get_data (col);
|
||||
}
|
||||
|
||||
@ -683,6 +699,7 @@ GNCPriceDB *
|
||||
gnc_pricedb_get_db(QofBook *book)
|
||||
{
|
||||
QofCollection *col;
|
||||
|
||||
if (!book) return NULL;
|
||||
col = qof_book_get_collection (book, GNC_ID_PRICEDB);
|
||||
return gnc_collection_get_pricedb (col);
|
||||
@ -862,13 +879,9 @@ gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If we haven't been able to call the backend before, call it now */
|
||||
if (TRUE == p->inst.dirty)
|
||||
{
|
||||
gnc_price_begin_edit(p);
|
||||
db->inst.dirty = TRUE;
|
||||
gnc_price_commit_edit(p);
|
||||
}
|
||||
gnc_pricedb_begin_edit(db);
|
||||
qof_instance_set_dirty(&db->inst);
|
||||
gnc_pricedb_commit_edit(db);
|
||||
|
||||
LEAVE ("db=%p, pr=%p dirty=%d do-free=%d",
|
||||
db, p, p->inst.dirty, p->inst.do_free);
|
||||
@ -948,13 +961,14 @@ gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
|
||||
|
||||
gnc_price_ref(p);
|
||||
rc = remove_price (db, p, TRUE);
|
||||
gnc_pricedb_begin_edit(db);
|
||||
qof_instance_set_dirty(&db->inst);
|
||||
gnc_pricedb_commit_edit(db);
|
||||
|
||||
/* invoke the backend to delete this price */
|
||||
gnc_price_begin_edit (p);
|
||||
db->inst.dirty = TRUE;
|
||||
p->inst.do_free = TRUE;
|
||||
gnc_price_commit_edit (p);
|
||||
|
||||
p->db = NULL;
|
||||
gnc_price_unref(p);
|
||||
LEAVE ("db=%p, pr=%p", db, p);
|
||||
@ -2113,25 +2127,29 @@ gnc_pricedb_print_contents(GNCPriceDB *db, FILE *f)
|
||||
static void
|
||||
pricedb_book_begin (QofBook *book)
|
||||
{
|
||||
gnc_pricedb_create(book);
|
||||
GNCPriceDB *db;
|
||||
|
||||
db = gnc_pricedb_create(book);
|
||||
}
|
||||
|
||||
static void
|
||||
pricedb_book_end (QofBook *book)
|
||||
{
|
||||
/* ????? */
|
||||
GNCPriceDB *db;
|
||||
QofCollection *col;
|
||||
|
||||
if (!book)
|
||||
return;
|
||||
col = qof_book_get_collection(book, GNC_ID_PRICEDB);
|
||||
db = qof_collection_get_data(col);
|
||||
qof_collection_set_data(col, NULL);
|
||||
gnc_pricedb_destroy(db);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pricedb_is_dirty (QofCollection *col)
|
||||
static gpointer
|
||||
price_create (QofBook *book)
|
||||
{
|
||||
return gnc_pricedb_dirty(gnc_collection_get_pricedb(col));
|
||||
}
|
||||
|
||||
static void
|
||||
pricedb_mark_clean(QofCollection *col)
|
||||
{
|
||||
gnc_pricedb_mark_clean(gnc_collection_get_pricedb(col));
|
||||
return gnc_price_create(book);
|
||||
}
|
||||
|
||||
/* ==================================================================== */
|
||||
@ -2183,9 +2201,11 @@ void_unstable_price_traversal(GNCPriceDB *db,
|
||||
}
|
||||
|
||||
static void
|
||||
pricedb_foreach(QofCollection *col, QofEntityForeachCB cb, gpointer data)
|
||||
price_foreach(QofCollection *col, QofEntityForeachCB cb, gpointer data)
|
||||
{
|
||||
GNCPriceDB *db = gnc_collection_get_pricedb(col);
|
||||
GNCPriceDB *db;
|
||||
|
||||
db = qof_collection_get_data(col);
|
||||
void_unstable_price_traversal(db,
|
||||
(void (*)(GNCPrice *, gpointer)) cb,
|
||||
data);
|
||||
@ -2194,7 +2214,7 @@ pricedb_foreach(QofCollection *col, QofEntityForeachCB cb, gpointer data)
|
||||
/* ==================================================================== */
|
||||
|
||||
static const char *
|
||||
pricedb_printable(gpointer obj)
|
||||
price_printable(gpointer obj)
|
||||
{
|
||||
GNCPrice *pr = obj;
|
||||
gnc_commodity *commodity;
|
||||
@ -2219,18 +2239,33 @@ pricedb_printable(gpointer obj)
|
||||
return buff;
|
||||
}
|
||||
|
||||
static QofObject pricedb_object_def =
|
||||
static QofObject price_object_def =
|
||||
{
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: GNC_ID_PRICE,
|
||||
type_label: "Price",
|
||||
create: (gpointer)gnc_price_create,
|
||||
create: price_create,
|
||||
book_begin: NULL,
|
||||
book_end: NULL,
|
||||
is_dirty: qof_collection_is_dirty,
|
||||
mark_clean: qof_collection_mark_clean,
|
||||
foreach: price_foreach,
|
||||
printable: price_printable,
|
||||
version_cmp: NULL,
|
||||
};
|
||||
|
||||
static QofObject pricedb_object_def =
|
||||
{
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: GNC_ID_PRICEDB,
|
||||
type_label: "PriceDB",
|
||||
create: NULL,
|
||||
book_begin: pricedb_book_begin,
|
||||
book_end: pricedb_book_end,
|
||||
is_dirty: pricedb_is_dirty,
|
||||
mark_clean: pricedb_mark_clean,
|
||||
foreach: pricedb_foreach,
|
||||
printable: pricedb_printable,
|
||||
is_dirty: qof_collection_is_dirty,
|
||||
mark_clean: qof_collection_mark_clean,
|
||||
foreach: NULL,
|
||||
printable: NULL,
|
||||
version_cmp: NULL,
|
||||
};
|
||||
|
||||
@ -2249,6 +2284,8 @@ gnc_pricedb_register (void)
|
||||
|
||||
qof_class_register (GNC_ID_PRICE, NULL, params);
|
||||
|
||||
if (!qof_object_register (&price_object_def))
|
||||
return FALSE;
|
||||
return qof_object_register (&pricedb_object_def);
|
||||
}
|
||||
|
||||
|
@ -245,10 +245,6 @@ gboolean gnc_price_list_equal(GList *prices1, GList *prices2);
|
||||
/** Data type */
|
||||
typedef struct gnc_price_db_s GNCPriceDB;
|
||||
|
||||
/** gnc_pricedb_create - create a new pricedb. Normally you won't need
|
||||
this; you will get the pricedb via gnc_pricedb_get_db. */
|
||||
GNCPriceDB * gnc_pricedb_create(QofBook *book);
|
||||
|
||||
/* XXX backwards-compat defines, remove these someday */
|
||||
#define gnc_book_get_pricedb gnc_pricedb_get_db
|
||||
|
||||
@ -381,10 +377,6 @@ gboolean gnc_pricedb_foreach_price(GNCPriceDB *db,
|
||||
gpointer user_data,
|
||||
gboolean stable_order);
|
||||
|
||||
/** gnc_pricedb_dirty - return FALSE if the database has not been
|
||||
modified. */
|
||||
#define gnc_pricedb_dirty(db) qof_instance_is_dirty(QOF_INSTANCE(db))
|
||||
|
||||
/** gnc_pricedb_get_num_prices - return the number of prices
|
||||
in the database. */
|
||||
guint gnc_pricedb_get_num_prices(GNCPriceDB *db);
|
||||
|
Loading…
Reference in New Issue
Block a user