more cloning; update status in BusPeriod.c

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9611 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas
2003-10-21 13:53:55 +00:00
parent 8e9f1afc97
commit fee30d10b3
7 changed files with 162 additions and 33 deletions
+19 -23
View File
@@ -1,30 +1,18 @@
XXX TODO:
-- instance should somehow reference the qoftype, so that
things like gnc_engine_generate_event wouldn't
need three args ...
(in fact, so that many things wouldn't need to pass type explicitly)
entity node already stores type, so entity_node should be merged
with instance (or be parent of instance ?!)
-- bus obj has per-type hash tables that are identical to the entity
per-type hash tables, should be merged together.
-- bus object foreach should be made into a for-each by type
(requires modes to book for each to be a type-foreach).
(this would also add a per-type edit/commmit-edit, clone, dirty,
etc. functions!) Yahoo!
-- billterm and taxtables are incompletely cloned, not sure
what to do with refcount, ask warlord, need to explore.
-- onwers incomplete cloned, neeed to handle remaining 'owners'
-- contemplate a per-colection (per type) edit/commmit-edit,
clone, dirty, etc. functions some more ...
-- turn clone into a generic object callback, so that
the ObtainTwin could be qof_instance_obtain_twin,
a generic function. (right now its copied everywhere)
-- contemplate copy-on-write, and the true need for cloning,
and how to avoid excess cloning for the SQL backend.
-- billterm and taxtables are incompletely cloned, not sure
what to do with refcount, ask warlord, need to explore.
-- The following busines objects have an id/name/desc/active
this could be abstracted into an common object.
vendor (customer)
@@ -34,15 +22,23 @@ XXX TODO:
-- gnVendor should be a base class to gncCustomer (they're
identical, but customer adds more stuff).
Enployee could be base class for vendor, its got some of the
Employee could be base class for vendor, its got some of the
things (name, addr, active, currency)
-- TaxTable and BillTerm have common parent/child code.
this could be abstracted into common code.
=======
-- finish onwer cclone
-- vendor, invoice, entry, order
-- finish clone of invoice, entry,
-- jobs in the vendor job list that are no longer active should
be kept back in old book, removed from new book??
ditto jobs in the customer list ??
-- closed orders can be removed from new book ?
#include "gncBusiness.h"
+29
View File
@@ -193,6 +193,7 @@ mark_entry (GncEntry *entry)
gnc_engine_gen_event (&entry->inst.entity, GNC_EVENT_MODIFY);
}
/* ================================================================ */
/* Create/Destroy Functions */
GncEntry *gncEntryCreate (QofBook *book)
@@ -257,6 +258,30 @@ static void gncEntryFree (GncEntry *entry)
g_free (entry);
}
GncEntry *
gncCloneEntry (GncEntry *from, QofBook *book)
{
/* XXX unfinished */
return NULL;
}
GncEntry *
gncEntryObtainTwin (GncEntry *from, QofBook *book)
{
GncEntry *entry;
if (!book) return NULL;
entry = (GncEntry *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
if (!entry)
{
entry = gncCloneEntry (from, book);
}
return entry;
}
/* ================================================================ */
/* Set Functions */
void gncEntrySetDate (GncEntry *entry, Timespec date)
@@ -587,6 +612,7 @@ void gncEntryCopy (const GncEntry *src, GncEntry *dest)
gncEntryCommitEdit (dest);
}
/* ================================================================ */
/* Get Functions */
Timespec gncEntryGetDate (GncEntry *entry)
@@ -745,6 +771,7 @@ GncOrder * gncEntryGetOrder (GncEntry *entry)
return entry->order;
}
/* ================================================================ */
/*
* This is the logic of computing the total for an Entry, so you know
* what values to put into various Splits or to display in the ledger.
@@ -1084,6 +1111,8 @@ gboolean gncEntryIsOpen (GncEntry *entry)
return (entry->inst.editlevel > 0);
}
/* ================================================================ */
void gncEntryBeginEdit (GncEntry *entry)
{
GNC_BEGIN_EDIT (&entry->inst);
+22
View File
@@ -22,6 +22,7 @@
/*
* Copyright (C) 2001 Derek Atkins
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
* Author: Derek Atkins <warlord@MIT.EDU>
*/
@@ -38,6 +39,27 @@ void gncEntrySetInvoice (GncEntry *entry, GncInvoice *invoice);
void gncEntrySetBill (GncEntry *entry, GncInvoice *bill);
void gncEntrySetDirty (GncEntry *entry, gboolean dirty);
/** The gncCloneEntry() routine makes a copy of the indicated
* entry, placing it in the indicated book. It copies
* the whole kit-n-kaboodle.
* It then adds a pair of 'gemini' kvp pointers so that each copy
* can be found from the other.
*/
GncEntry * gncCloneEntry (GncEntry *from, QofBook *);
/** The gncEntryObtainTwin() will find the 'twin' of the
* indicated entry in the indicated book. If the twin doesn't
* yet exist in the book, it will be created (by calling
* gncCloneEntry()) and placed into the book.
*
* We called this routine 'Obtain' instead of "Get" to distinguish
* it from the other Get routines, which work in fundamentally
* different ways.
*/
GncEntry * gncEntryObtainTwin (GncEntry *from, QofBook *book);
#define gncEntrySetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G))
#endif /* GNC_ENTRYP_H_ */
+57
View File
@@ -53,6 +53,7 @@
#include "gncOrder.h"
#include "gncOrderP.h"
#include "gncOwner.h"
#include "gncOwnerP.h"
struct _gncOrder
{
@@ -96,6 +97,7 @@ mark_order (GncOrder *order)
gnc_engine_gen_event (&order->inst.entity, GNC_EVENT_MODIFY);
}
/* =============================================================== */
/* Create/Destroy Functions */
GncOrder *gncOrderCreate (QofBook *book)
@@ -142,6 +144,58 @@ static void gncOrderFree (GncOrder *order)
g_free (order);
}
GncOrder *
gncCloneOrder (GncOrder *from, QofBook *book)
{
GList *node;
GncOrder *order;
if (!book) return NULL;
order = g_new0 (GncOrder, 1);
qof_instance_init (&order->inst, _GNC_MOD_NAME, book);
qof_instance_gemini (&order->inst, &from->inst);
order->id = CACHE_INSERT (from->id);
order->notes = CACHE_INSERT (from->notes);
order->reference = CACHE_INSERT (from->reference);
order->active = from->active;
order->printname = NULL; /* yes, null, that's right */
order->opened = from->opened;
order->closed = from->closed;
order->owner = gncCloneOwner (&from->owner, book);
order->entries = NULL;
for (node = g_list_last(from->entries); node; node=node->prev)
{
GncEntry *entry = node->data;
entry = gncEntryObtainTwin (entry, book);
order->entries = g_list_prepend (order->entries, entry);
}
gnc_engine_gen_event (&order->inst.entity, GNC_EVENT_CREATE);
return order;
}
GncOrder *
gncOrderObtainTwin (GncOrder *from, QofBook *book)
{
GncOrder *order;
if (!book) return NULL;
order = (GncOrder *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
if (!order)
{
order = gncCloneOrder (from, book);
}
return order;
}
/* =============================================================== */
/* Set Functions */
void gncOrderSetID (GncOrder *order, const char *id)
@@ -209,6 +263,7 @@ void gncOrderSetActive (GncOrder *order, gboolean active)
gncOrderCommitEdit (order);
}
/* =============================================================== */
/* Add an Entry to the Order */
void gncOrderAddEntry (GncOrder *order, GncEntry *entry)
{
@@ -297,6 +352,8 @@ gboolean gncOrderIsClosed (GncOrder *order)
return FALSE;
}
/* =============================================================== */
void gncOrderBeginEdit (GncOrder *order)
{
GNC_BEGIN_EDIT (&order->inst);
+21
View File
@@ -22,6 +22,7 @@
/*
* Copyright (C) 2001 Derek Atkins
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
* Author: Derek Atkins <warlord@MIT.EDU>
*/
@@ -34,6 +35,26 @@
gboolean gncOrderRegister (void);
gint64 gncOrderNextID (QofBook *book);
/** The gncCloneOrder() routine makes a copy of the indicated
* order, placing it in the indicated book. It copies
* the id, notes, reference, etc.
* It then adds a pair of 'gemini' kvp pointers so that each copy
* can be found from the other.
*/
GncOrder * gncCloneOrder (GncOrder *from, QofBook *);
/** The gncOrderObtainTwin() will find the 'twin' of the
* indicated order in the indicated book. If the twin doesn't
* yet exist in the book, it will be created (by calling
* gncCloneOrder()) and placed into the book.
*
* We called this routine 'Obtain' instead of "Get" to distinguish
* it from the other Get routines, which work in fundamentally
* different ways.
*/
GncOrder * gncOrderObtainTwin (GncOrder *from, QofBook *book);
#define gncOrderSetGUID(O,G) qof_entity_set_guid(QOF_ENTITY(O),(G))
#endif /* GNC_ORDERP_H_ */
+14 -7
View File
@@ -22,6 +22,7 @@
/*
* Copyright (C) 2001, 2002 Derek Atkins
* Copyright (C) 2003 <linas@linas.org>
* Author: Derek Atkins <warlord@MIT.EDU>
*/
@@ -50,6 +51,8 @@
#include "gncAddressP.h"
#include "gncBillTermP.h"
#include "gncBusiness.h"
#include "gncJobP.h"
#include "gncTaxTableP.h"
#include "gncVendor.h"
#include "gncVendorP.h"
@@ -146,6 +149,7 @@ static void gncVendorFree (GncVendor *vendor)
GncVendor *
gncCloneVendor (GncVendor *from, QofBook *book)
{
GList *node;
GncVendor *vendor;
if (!book) return NULL;
@@ -159,6 +163,7 @@ gncCloneVendor (GncVendor *from, QofBook *book)
vendor->notes = CACHE_INSERT (from->notes);
vendor->addr = gncCloneAddress (from->addr, &vendor->inst.entity, book);
vendor->taxincluded = from->taxincluded;
vendor->taxtable_override = from->taxtable_override;
vendor->active = from->active;
vendor->terms = gncBillTermObtainTwin (from->terms, book);
@@ -166,14 +171,16 @@ gncCloneVendor (GncVendor *from, QofBook *book)
vendor->currency = gnc_commodity_obtain_twin (from->currency, book);
#if 0
XXX unfinished
vendor->jobs = NULL; xxx
vendor->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
gncTaxTableIncRef (vendor->taxtable);
GncTaxTable* taxtable;
gboolean taxtable_override;
GList * jobs;
#endif
vendor->jobs = NULL;
for (node=g_list_last(from->jobs); node; node=node->prev)
{
GncJob *job = node->data;
job = gncJobObtainTwin (job, book);
vendor->jobs = g_list_prepend(vendor->jobs, job);
}
gnc_engine_gen_event (&vendor->inst.entity, GNC_EVENT_CREATE);
-3
View File
@@ -37,9 +37,6 @@ gint64 gncVendorNextID (QofBook *book);
/** The gncCloneVendor() routine makes a copy of the indicated
* vendor, placing it in the indicated book. It copies
* the name, notes, address, etc.
* It also copies (as needed) both parents and children, so that
* the parent-child relationship is correctly mirrored in the
* clone.
* It then adds a pair of 'gemini' kvp pointers so that each copy
* can be found from the other.
*/