mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Convert Lots from a QofEntity to a QofInstance.
They now store their own dirty state. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13359 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
da35e7c127
commit
656889ecce
@ -216,9 +216,10 @@ gnc_book_insert_lot (QofBook *book, GNCLot *lot)
|
||||
if (!lot || !book) return;
|
||||
|
||||
/* If this is the same book, its a no-op. */
|
||||
if (lot->book == book) return;
|
||||
if (gnc_lot_get_book(lot) == book) return;
|
||||
|
||||
if (qof_book_get_backend(book) != qof_book_get_backend(lot->book))
|
||||
if (qof_book_get_backend(book) !=
|
||||
qof_book_get_backend(gnc_lot_get_book(lot)))
|
||||
{
|
||||
gnc_book_insert_lot_clobber (book, lot);
|
||||
return;
|
||||
@ -226,8 +227,8 @@ gnc_book_insert_lot (QofBook *book, GNCLot *lot)
|
||||
ENTER ("lot=%p", lot);
|
||||
|
||||
col = qof_book_get_collection (book, GNC_ID_LOT);
|
||||
lot->book = book;
|
||||
qof_collection_insert_entity (col, &lot->entity);
|
||||
lot->inst.book = book;
|
||||
qof_collection_insert_entity (col, &lot->inst.entity);
|
||||
|
||||
/* Move the splits over (only if they haven't already been moved). */
|
||||
col = qof_book_get_collection (book, GNC_ID_SPLIT);
|
||||
|
@ -602,7 +602,7 @@ void gen_event (const Split *split)
|
||||
if (lot)
|
||||
{
|
||||
/* A change of value/amnt affects gains displat, etc. */
|
||||
gnc_engine_gen_event (&lot->entity, GNC_EVENT_MODIFY);
|
||||
gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
}
|
||||
|
||||
@ -624,7 +624,7 @@ void gen_event_trans (Transaction *trans)
|
||||
if (lot)
|
||||
{
|
||||
/* A change of transaction date might affect opening date of lot */
|
||||
gnc_engine_gen_event (&lot->entity, GNC_EVENT_MODIFY);
|
||||
gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,13 +42,7 @@
|
||||
|
||||
struct gnc_lot_struct
|
||||
{
|
||||
QofEntity entity; /* Unique guid for this lot */
|
||||
|
||||
/* Book that this lot belongs to */
|
||||
QofBook *book;
|
||||
|
||||
/* Anchor for generic lot-specific data. */
|
||||
KvpFrame *kvp_data;
|
||||
QofInstance inst;
|
||||
|
||||
/* Account to which this lot applies. All splits in the lot must
|
||||
* belong to this account.
|
||||
|
@ -52,17 +52,13 @@ static QofLogModule log_module = GNC_MOD_LOT;
|
||||
static void
|
||||
gnc_lot_init (GNCLot *lot, QofBook *book)
|
||||
{
|
||||
QofCollection *col;
|
||||
ENTER ("(lot=%p, book=%p)", lot, book);
|
||||
lot->kvp_data = kvp_frame_new();
|
||||
lot->account = NULL;
|
||||
lot->splits = NULL;
|
||||
lot->is_closed = -1;
|
||||
lot->marker = 0;
|
||||
|
||||
lot->book = book;
|
||||
col = qof_book_get_collection (book, GNC_ID_LOT);
|
||||
qof_entity_init (&lot->entity, GNC_ID_LOT, col);
|
||||
qof_instance_init(&lot->inst, GNC_ID_LOT, book);
|
||||
LEAVE ("(lot=%p, book=%p)", lot, book);
|
||||
}
|
||||
|
||||
@ -74,7 +70,7 @@ gnc_lot_new (QofBook *book)
|
||||
|
||||
lot = g_new (GNCLot, 1);
|
||||
gnc_lot_init (lot, book);
|
||||
gnc_engine_gen_event (&lot->entity, GNC_EVENT_CREATE);
|
||||
gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_CREATE);
|
||||
return lot;
|
||||
}
|
||||
|
||||
@ -85,9 +81,8 @@ gnc_lot_destroy (GNCLot *lot)
|
||||
if (!lot) return;
|
||||
|
||||
ENTER ("(lot=%p)", lot);
|
||||
gnc_engine_gen_event (&lot->entity, GNC_EVENT_DESTROY);
|
||||
gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_DESTROY);
|
||||
|
||||
qof_entity_release (&lot->entity);
|
||||
|
||||
for (node=lot->splits; node; node=node->next)
|
||||
{
|
||||
@ -96,12 +91,9 @@ gnc_lot_destroy (GNCLot *lot)
|
||||
}
|
||||
g_list_free (lot->splits);
|
||||
|
||||
kvp_frame_delete (lot->kvp_data);
|
||||
lot->kvp_data = NULL;
|
||||
|
||||
lot->account = NULL;
|
||||
lot->is_closed = TRUE;
|
||||
|
||||
qof_instance_release (&lot->inst);
|
||||
g_free (lot);
|
||||
}
|
||||
|
||||
@ -119,8 +111,7 @@ gnc_lot_lookup (const GUID *guid, QofBook *book)
|
||||
QofBook *
|
||||
gnc_lot_get_book (GNCLot *lot)
|
||||
{
|
||||
if (!lot) return NULL;
|
||||
return lot->book;
|
||||
return qof_instance_get_book(QOF_INSTANCE(lot));
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
@ -143,8 +134,7 @@ gnc_lot_get_account (GNCLot *lot)
|
||||
KvpFrame *
|
||||
gnc_lot_get_slots (GNCLot *lot)
|
||||
{
|
||||
if (!lot) return NULL;
|
||||
return lot->kvp_data;
|
||||
return qof_instance_get_slots(QOF_INSTANCE(lot));
|
||||
}
|
||||
|
||||
SplitList *
|
||||
@ -167,30 +157,30 @@ const char *
|
||||
gnc_lot_get_title (GNCLot *lot)
|
||||
{
|
||||
if (!lot) return NULL;
|
||||
return kvp_frame_get_string (lot->kvp_data, "/title");
|
||||
return kvp_frame_get_string (lot->inst.kvp_data, "/title");
|
||||
}
|
||||
|
||||
const char *
|
||||
gnc_lot_get_notes (GNCLot *lot)
|
||||
{
|
||||
if (!lot) return NULL;
|
||||
return kvp_frame_get_string (lot->kvp_data, "/notes");
|
||||
return kvp_frame_get_string (lot->inst.kvp_data, "/notes");
|
||||
}
|
||||
|
||||
void
|
||||
gnc_lot_set_title (GNCLot *lot, const char *str)
|
||||
{
|
||||
if (!lot) return;
|
||||
qof_collection_mark_dirty(QOF_ENTITY(lot)->collection);
|
||||
return kvp_frame_set_str (lot->kvp_data, "/title", str);
|
||||
qof_instance_mark_dirty(QOF_INSTANCE(lot));
|
||||
return kvp_frame_set_str (lot->inst.kvp_data, "/title", str);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_lot_set_notes (GNCLot *lot, const char *str)
|
||||
{
|
||||
if (!lot) return;
|
||||
qof_collection_mark_dirty(QOF_ENTITY(lot)->collection);
|
||||
return kvp_frame_set_str (lot->kvp_data, "/notes", str);
|
||||
qof_instance_mark_dirty(QOF_INSTANCE(lot));
|
||||
return kvp_frame_set_str (lot->inst.kvp_data, "/notes", str);
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
@ -245,7 +235,7 @@ gnc_lot_add_split (GNCLot *lot, Split *split)
|
||||
gnc_num_dbg_to_string (split->amount),
|
||||
gnc_num_dbg_to_string (split->value));
|
||||
acc = xaccSplitGetAccount (split);
|
||||
qof_collection_mark_dirty(QOF_ENTITY(lot)->collection);
|
||||
qof_instance_mark_dirty(QOF_INSTANCE(lot));
|
||||
if (NULL == lot->account)
|
||||
{
|
||||
xaccAccountInsertLot (acc, lot);
|
||||
@ -271,7 +261,7 @@ gnc_lot_add_split (GNCLot *lot, Split *split)
|
||||
/* for recomputation of is-closed */
|
||||
lot->is_closed = -1;
|
||||
|
||||
gnc_engine_gen_event (&lot->entity, GNC_EVENT_MODIFY);
|
||||
gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
void
|
||||
@ -280,7 +270,7 @@ gnc_lot_remove_split (GNCLot *lot, Split *split)
|
||||
if (!lot || !split) return;
|
||||
|
||||
ENTER ("(lot=%p, split=%p)", lot, split);
|
||||
qof_collection_mark_dirty(QOF_ENTITY(lot)->collection);
|
||||
qof_instance_mark_dirty(QOF_INSTANCE(lot));
|
||||
lot->splits = g_list_remove (lot->splits, split);
|
||||
split->lot = NULL;
|
||||
lot->is_closed = -1; /* force an is-closed computation */
|
||||
@ -290,7 +280,7 @@ gnc_lot_remove_split (GNCLot *lot, Split *split)
|
||||
xaccAccountRemoveLot (lot->account, lot);
|
||||
lot->account = NULL;
|
||||
}
|
||||
gnc_engine_gen_event (&lot->entity, GNC_EVENT_MODIFY);
|
||||
gnc_engine_gen_event (&lot->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
@ -356,40 +346,44 @@ gnc_lot_get_latest_split (GNCLot *lot)
|
||||
|
||||
/* ============================================================= */
|
||||
|
||||
/* Should the object description be enabled?. */
|
||||
/*
|
||||
static QofObject gncLotDesc =
|
||||
{
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: GNC_ID_LOT,
|
||||
type_label: "Lot",
|
||||
create: (gpointer)gnc_lot_new,
|
||||
book_begin: NULL,
|
||||
book_end: NULL,
|
||||
is_dirty: NULL,
|
||||
mark_clean: NULL,
|
||||
foreach: qof_collection_foreach,
|
||||
printable: NULL,
|
||||
version_cmp: (int (*)(gpointer,gpointer))qof_instance_version_cmp,
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: GNC_ID_LOT,
|
||||
type_label: "Lot",
|
||||
create: (gpointer)gnc_lot_new,
|
||||
book_begin: NULL,
|
||||
book_end: NULL,
|
||||
is_dirty: qof_collection_is_dirty,
|
||||
mark_clean: qof_collection_mark_clean,
|
||||
foreach: qof_collection_foreach,
|
||||
printable: NULL,
|
||||
version_cmp: (int (*)(gpointer,gpointer))qof_instance_version_cmp,
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
gboolean gnc_lot_register (void)
|
||||
{
|
||||
static const QofParam params[] = {
|
||||
{ LOT_TITLE, QOF_TYPE_STRING, (QofAccessFunc)gnc_lot_get_title, (QofSetterFunc)gnc_lot_set_title },
|
||||
{ LOT_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gnc_lot_get_notes, (QofSetterFunc)gnc_lot_set_notes },
|
||||
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_entity_get_guid, NULL },
|
||||
{ QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)gnc_lot_get_book, NULL },
|
||||
{ LOT_IS_CLOSED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gnc_lot_is_closed, NULL },
|
||||
{ LOT_BALANCE, QOF_TYPE_NUMERIC, (QofAccessFunc)gnc_lot_get_balance, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_class_register (GNC_ID_LOT, NULL, params);
|
||||
return TRUE;
|
||||
// return qof_object_register(&gncLotDesc);
|
||||
static const QofParam params[] = {
|
||||
{ LOT_TITLE, QOF_TYPE_STRING,
|
||||
(QofAccessFunc) gnc_lot_get_title,
|
||||
(QofSetterFunc) gnc_lot_set_title },
|
||||
{ LOT_NOTES, QOF_TYPE_STRING,
|
||||
(QofAccessFunc) gnc_lot_get_notes,
|
||||
(QofSetterFunc) gnc_lot_set_notes },
|
||||
{ QOF_PARAM_GUID, QOF_TYPE_GUID,
|
||||
(QofAccessFunc) qof_entity_get_guid, NULL },
|
||||
{ QOF_PARAM_BOOK, QOF_ID_BOOK,
|
||||
(QofAccessFunc) gnc_lot_get_book, NULL },
|
||||
{ LOT_IS_CLOSED, QOF_TYPE_BOOLEAN,
|
||||
(QofAccessFunc) gnc_lot_is_closed, NULL },
|
||||
{ LOT_BALANCE, QOF_TYPE_NUMERIC,
|
||||
(QofAccessFunc) gnc_lot_get_balance, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_class_register (GNC_ID_LOT, NULL, params);
|
||||
return qof_object_register(&gncLotDesc);
|
||||
}
|
||||
|
||||
/* ========================== END OF FILE ========================= */
|
||||
|
Loading…
Reference in New Issue
Block a user