implement job clone, update stauts notes, update documentation

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9498 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2003-10-14 03:14:44 +00:00
parent a0ccda5926
commit 8e545f865e
6 changed files with 119 additions and 49 deletions

View File

@ -1,15 +1,19 @@
XXX TODO:
-- billterms is incompletely cloned, not sure what to do
with refcount, ask warlord, need to explore.
-- billterm and taxtermss are incompletely cloned, not sure
what to do with refcount, ask warlord, need to explore.
-- taxtable is incompletely cloned, not sure what to do
with certain fields, ask warlord
-- jobs incomplete cloned, neeed to handle owners
-- customer incomplete cloned, neeed to handle jobs
-- 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)
-- Ask warlord if all bill terms should be copied, or just
thiose on customers ...
-- most of the busienss objects have an id/name/desc
this could be abstracted into an common object.
-- TaxTable and BillTerm have common parent/child code.
this could be abstracted into common code.
#include "gncBusiness.h"

View File

@ -52,32 +52,33 @@
#include "gncBusiness.h"
#include "gncCustomer.h"
#include "gncCustomerP.h"
#include "gncJobP.h"
#include "gncTaxTableP.h"
struct _gncCustomer
{
QofInstance inst;
char * id;
char * name;
char * notes;
GncBillTerm * terms;
GncAddress * addr;
GncAddress * shipaddr;
gnc_commodity * currency;
gnc_numeric discount;
gnc_numeric credit;
GncTaxIncluded taxincluded;
QofInstance inst;
char * id;
char * name;
char * notes;
GncBillTerm * terms;
GncAddress * addr;
GncAddress * shipaddr;
gnc_commodity * currency;
gnc_numeric discount;
gnc_numeric credit;
GncTaxIncluded taxincluded;
gboolean active;
GList * jobs;
gboolean active;
GList * jobs;
GncTaxTable* taxtable;
gboolean taxtable_override;
GncTaxTable* taxtable;
gboolean taxtable_override;
};
static short module = MOD_BUSINESS;
static short module = MOD_BUSINESS;
#define _GNC_MOD_NAME GNC_CUSTOMER_MODULE_NAME
#define _GNC_MOD_NAME GNC_CUSTOMER_MODULE_NAME
/* ============================================================== */
/* misc inline funcs */
@ -137,6 +138,7 @@ GncCustomer *gncCustomerCreate (QofBook *book)
GncCustomer *
gncCloneCustomer (GncCustomer *from, QofBook *book)
{
GList *node;
GncCustomer *cust;
cust = g_new0 (GncCustomer, 1);
@ -153,8 +155,6 @@ gncCloneCustomer (GncCustomer *from, QofBook *book)
cust->active = from->active;
cust->taxtable_override = from->taxtable_override;
/* cust->jobs = ??? XXXXXXXXXXXXXXXXXXXXXXX fixme not sure what to do here */
cust->addr = gncCloneAddress (from->addr, book);
cust->shipaddr = gncCloneAddress (from->shipaddr, book);
@ -179,6 +179,13 @@ gncCloneCustomer (GncCustomer *from, QofBook *book)
cust->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
}
for (node=g_list_last(cust->jobs); node; node=node->next)
{
GncJob *job = node->data;
job = gncJobObtainTwin (job, book);
cust->jobs = g_list_prepend(cust->jobs, job);
}
addObj (cust);
gnc_engine_generate_event (&cust->inst.guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
@ -221,14 +228,14 @@ static void gncCustomerFree (GncCustomer *cust)
/* Set Functions */
#define SET_STR(obj, member, str) { \
char * tmp; \
\
if (!safe_strcmp (member, str)) return; \
gncCustomerBeginEdit (obj); \
tmp = CACHE_INSERT (str); \
CACHE_REMOVE (member); \
member = tmp; \
}
char * tmp; \
\
if (!safe_strcmp (member, str)) return; \
gncCustomerBeginEdit (obj); \
tmp = CACHE_INSERT (str); \
CACHE_REMOVE (member); \
member = tmp; \
}
void gncCustomerSetID (GncCustomer *cust, const char *id)
{
@ -368,7 +375,7 @@ void gncCustomerAddJob (GncCustomer *cust, GncJob *job)
if (g_list_index(cust->jobs, job) == -1)
cust->jobs = g_list_insert_sorted (cust->jobs, job,
(GCompareFunc)gncJobCompare);
(GCompareFunc)gncJobCompare);
gnc_engine_generate_event (&cust->inst.guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
}
@ -418,7 +425,7 @@ void gncCustomerCommitEdit (GncCustomer *cust)
{
GNC_COMMIT_EDIT_PART1 (&cust->inst);
GNC_COMMIT_EDIT_PART2 (&cust->inst, _GNC_MOD_NAME, gncCustomerOnError,
gncCustomerOnDone, cust_free);
gncCustomerOnDone, cust_free);
}
/* Get Functions */
@ -512,7 +519,7 @@ GList * gncCustomerGetJoblist (GncCustomer *cust, gboolean show_all)
for (iterator = cust->jobs; iterator; iterator=iterator->next) {
GncJob *j = iterator->data;
if (gncJobGetActive (j))
list = g_list_append (list, j);
list = g_list_append (list, j);
}
return list;
}
@ -536,15 +543,15 @@ GncCustomer * gncCustomerLookup (QofBook *book, const GUID *guid)
{
if (!book || !guid) return NULL;
return qof_entity_lookup (gnc_book_get_entity_table (book),
guid, _GNC_MOD_NAME);
guid, _GNC_MOD_NAME);
}
gboolean gncCustomerIsDirty (GncCustomer *cust)
{
if (!cust) return FALSE;
return (cust->inst.dirty ||
gncAddressIsDirty (cust->addr) ||
gncAddressIsDirty (cust->shipaddr));
gncAddressIsDirty (cust->addr) ||
gncAddressIsDirty (cust->shipaddr));
}
/* Other functions */
@ -581,7 +588,7 @@ static void _gncCustomerMarkClean (QofBook *book)
}
static void _gncCustomerForeach (QofBook *book, QofEntityForeachCB cb,
gpointer user_data)
gpointer user_data)
{
gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data);
}

View File

@ -37,10 +37,7 @@ void gncCustomerSetGUID (GncCustomer *customer, const GUID *guid);
/** The gncCloneCustomer() routine makes a copy of the indicated
* customer, placing it in the indicated book. It copies
* the addresses, credits, etc.
* It copies the bill term, if needed.
* It does not copy jobs?? Or tax terms ???
* XXX the above need fixin....
* the addresses, credits, currency, billing terms and jobs.
* It then adds a pair of 'gemini' kvp pointers so that each copy
* can be found from the other.
*/

View File

@ -106,12 +106,38 @@ GncJob *gncJobCreate (QofBook *book)
job->desc = CACHE_INSERT ("");
job->active = TRUE;
/* GncOwner not initialized */
addObj (job);
gnc_engine_generate_event (&job->inst.guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
return job;
}
GncJob *
gncCloneJob (GncJob *from, QofBook *book)
{
GncJob *job;
if (!book) return NULL;
job = g_new0 (GncJob, 1);
qof_instance_init (&job->inst, book);
qof_instance_gemini (&job->inst, &from->inst);
job->id = CACHE_INSERT (from->id);
job->name = CACHE_INSERT (from->name);
job->desc = CACHE_INSERT (from->desc);
job->active = from->active;
/* XXX need to clone too */
job->owner = from->owner;
addObj (job);
gnc_engine_generate_event (&job->inst.guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
return job;
}
void gncJobDestroy (GncJob *job)
{
if (!job) return;
@ -146,6 +172,20 @@ static void gncJobFree (GncJob *job)
g_free (job);
}
GncJob *
gncJobObtainTwin (GncJob *from, QofBook *book)
{
GncJob *job;
if (!from) return NULL;
job = (GncJob *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
if (!job)
{
job = gncCloneJob (from, book);
}
return job;
}
/* ================================================================== */
/* Set Functions */

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,4 +35,24 @@ gboolean gncJobRegister (void);
gint64 gncJobNextID (QofBook *book);
void gncJobSetGUID (GncJob *job, const GUID *guid);
/** The gncCloneTaxTable() routine makes a copy of the indicated
* tax table, placing it in the indicated book. It copies
* the id, name description and owner.
* It then adds a pair of 'gemini' kvp pointers so that each copy
* can be found from the other.
*/
GncJob * gncCloneJob (GncJob *from, QofBook *book);
/** The gncJobObtainTwin() will find the 'twin' of the
* indicated tax table in the indicated book. If the twin doesn't
* yet exist in the book, it will be created (by calling
* gncCloneJob()) 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.
*/
GncJob * gncJobObtainTwin (GncJob *from, QofBook *book);
#endif /* GNC_JOBP_H_ */

View File

@ -43,13 +43,14 @@ gboolean gncTaxTableGetInvisible (GncTaxTable *table);
/** The gncCloneTaxTable() routine makes a copy of the indicated
* tax table, placing it in the indicated book. It copies
* the etc.
* It does not copy parent/child relationships ???
* XXX the above need fixin....
* the tax table name and list of entries.
* It also copies (as needed) both parents and children, so that
* the parent-child relationship is correctly mirrored in the
* clone.
* XXX the refcount is mis-handled. This needs fixin....
* It then adds a pair of 'gemini' kvp pointers so that each copy
* can be found from the other.
*/
GncTaxTable * gncCloneTaxTable (GncTaxTable *from, QofBook *book);
/** The gncTaxTableObtainTwin() will find the 'twin' of the