mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
more cloning of stuff.
(Yes Derek, I'm agonizing over whether/how to clone/not clone depending on the backend. But in the meantime this fills in needed function anyway.) git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9606 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncAddress.c -- an Address object *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncAddress.h -- an Address object
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -73,7 +94,7 @@ gncAddressCreate (QofBook *book, QofEntity *prnt)
|
||||
}
|
||||
|
||||
GncAddress *
|
||||
gncCloneAddress (GncAddress *from, QofBook *book)
|
||||
gncCloneAddress (GncAddress *from, QofEntity *new_parent, QofBook *book)
|
||||
{
|
||||
GncAddress *addr;
|
||||
|
||||
@@ -82,7 +103,7 @@ gncCloneAddress (GncAddress *from, QofBook *book)
|
||||
addr = g_new0 (GncAddress, 1);
|
||||
addr->book = book;
|
||||
addr->dirty = TRUE;
|
||||
addr->parent = from->parent;
|
||||
addr->parent = new_parent;
|
||||
|
||||
addr->name = CACHE_INSERT (from->name);
|
||||
addr->addr1 = CACHE_INSERT (from->addr1);
|
||||
@@ -96,7 +117,9 @@ gncCloneAddress (GncAddress *from, QofBook *book)
|
||||
return addr;
|
||||
}
|
||||
|
||||
void gncAddressDestroy (GncAddress *addr){
|
||||
void
|
||||
gncAddressDestroy (GncAddress *addr)
|
||||
{
|
||||
if (!addr) return;
|
||||
|
||||
CACHE_REMOVE (addr->name);
|
||||
@@ -116,6 +139,7 @@ void gncAddressDestroy (GncAddress *addr){
|
||||
#define SET_STR(member, str) { \
|
||||
char * tmp; \
|
||||
\
|
||||
if (member == str) return; \
|
||||
if (!safe_strcmp (member, str)) return; \
|
||||
tmp = CACHE_INSERT (str); \
|
||||
CACHE_REMOVE (member); \
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncAddress.h -- an Address object *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncAddress.h -- an Address object
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -10,15 +31,12 @@
|
||||
#include "qofbook.h"
|
||||
#include "qofid.h"
|
||||
|
||||
#define GNC_ADDRESS_MODULE_NAME "gncAddress"
|
||||
#define GNC_ADDRESS_MODULE_NAME "gncAddress"
|
||||
|
||||
typedef struct _gncAddress GncAddress;
|
||||
|
||||
/* Create/Destroy functions */
|
||||
GncAddress * gncAddressCreate (QofBook *book, QofEntity *parent);
|
||||
|
||||
/** make a copy of the address, but associate it with a different book */
|
||||
GncAddress * gncCloneAddress (GncAddress *from, QofBook *book);
|
||||
void gncAddressDestroy (GncAddress *addr);
|
||||
|
||||
/* Set functions */
|
||||
@@ -47,9 +65,9 @@ gboolean gncAddressIsDirty (const GncAddress *addr);
|
||||
|
||||
int gncAddressCompare (const GncAddress *a, const GncAddress *b);
|
||||
|
||||
#define ADDRESS_NAME "name"
|
||||
#define ADDRESS_PHONE "phone"
|
||||
#define ADDRESS_FAX "fax"
|
||||
#define ADDRESS_EMAIL "email"
|
||||
#define ADDRESS_NAME "name"
|
||||
#define ADDRESS_PHONE "phone"
|
||||
#define ADDRESS_FAX "fax"
|
||||
#define ADDRESS_EMAIL "email"
|
||||
|
||||
#endif /* GNC_ADDRESS_H_ */
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncAddressP.h -- Private Business Interface: Addresses *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncAddressP.h -- Business Interface: Addresses
|
||||
* Copyright (C) 2001, 2002 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -7,6 +28,13 @@
|
||||
#ifndef GNC_ADDRESSP_H_
|
||||
#define GNC_ADDRESSP_H_
|
||||
|
||||
#include "gncAddress.h"
|
||||
#include "qofid.h"
|
||||
|
||||
gboolean gncAddressRegister (void);
|
||||
|
||||
/** Make a copy of the address, setting the parent to 'new_parent' */
|
||||
GncAddress * gncCloneAddress (GncAddress *from, QofEntity *new_parent, QofBook *book);
|
||||
|
||||
|
||||
#endif /* GNC_ADDRESSP_H_ */
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
#include "qofquerycore.h"
|
||||
#include "qofquery.h"
|
||||
|
||||
#include "gncAddress.h"
|
||||
#include "gncAddressP.h"
|
||||
#include "gncBillTermP.h"
|
||||
#include "gncBusiness.h"
|
||||
#include "gncCustomer.h"
|
||||
@@ -148,29 +148,16 @@ gncCloneCustomer (GncCustomer *from, QofBook *book)
|
||||
cust->active = from->active;
|
||||
cust->taxtable_override = from->taxtable_override;
|
||||
|
||||
cust->addr = gncCloneAddress (from->addr, book);
|
||||
cust->shipaddr = gncCloneAddress (from->shipaddr, book);
|
||||
cust->addr = gncCloneAddress (from->addr, &cust->inst.entity, book);
|
||||
cust->shipaddr = gncCloneAddress (from->shipaddr, &cust->inst.entity, book);
|
||||
|
||||
/* Find the matching currency in the new book, assumes
|
||||
* currency has already been copied into new book. */
|
||||
if (from->currency)
|
||||
{
|
||||
const char * ucom;
|
||||
const gnc_commodity_table * comtbl;
|
||||
ucom = gnc_commodity_get_unique_name (from->currency);
|
||||
comtbl = gnc_commodity_table_get_table (book);
|
||||
cust->currency = gnc_commodity_table_lookup_unique (comtbl, ucom);
|
||||
}
|
||||
cust->currency = gnc_commodity_obtain_twin (from->currency, book);
|
||||
|
||||
/* Find the matching bill term, tax table in the new book */
|
||||
if (from->terms)
|
||||
{
|
||||
cust->terms = gncBillTermObtainTwin(from->terms, book);
|
||||
}
|
||||
if (from->taxtable)
|
||||
{
|
||||
cust->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
|
||||
}
|
||||
cust->terms = gncBillTermObtainTwin(from->terms, book);
|
||||
cust->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
|
||||
|
||||
for (node=g_list_last(cust->jobs); node; node=node->next)
|
||||
{
|
||||
|
||||
@@ -32,12 +32,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "guid.h"
|
||||
#include "messages.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-be-utils.h"
|
||||
|
||||
#include "qofbook.h"
|
||||
#include "qofclass.h"
|
||||
#include "qofid.h"
|
||||
@@ -48,10 +42,17 @@
|
||||
#include "qofquery.h"
|
||||
#include "qofquerycore.h"
|
||||
|
||||
#include "Account.h"
|
||||
#include "messages.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-be-utils.h"
|
||||
|
||||
#include "gncAddressP.h"
|
||||
#include "gncBusiness.h"
|
||||
#include "gncEmployee.h"
|
||||
#include "gncEmployeeP.h"
|
||||
#include "gncAddress.h"
|
||||
|
||||
struct _gncEmployee
|
||||
{
|
||||
@@ -149,11 +150,11 @@ gncCloneEmployee (GncEmployee *from, QofBook *book)
|
||||
employee->username = CACHE_INSERT (from->username);
|
||||
employee->language = CACHE_INSERT (from->language);
|
||||
employee->acl = CACHE_INSERT (from->acl);
|
||||
employee->addr = gncCloneAddress (from->addr, book);
|
||||
employee->addr = gncCloneAddress (from->addr, &employee->inst.entity, book);
|
||||
employee->workday = from->workday;
|
||||
employee->rate = from->rate;
|
||||
employee->active = from->active;
|
||||
employee->currency = from->currency;
|
||||
employee->currency = gnc_commodity_obtain_twin(from->currency, book);
|
||||
employee->ccard_acc =
|
||||
GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->ccard_acc), book));
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include "gncBusiness.h"
|
||||
#include "gncJob.h"
|
||||
#include "gncJobP.h"
|
||||
#include "gncOwnerP.h"
|
||||
|
||||
struct _gncJob
|
||||
{
|
||||
@@ -120,8 +121,7 @@ gncCloneJob (GncJob *from, QofBook *book)
|
||||
job->desc = CACHE_INSERT (from->desc);
|
||||
job->active = from->active;
|
||||
|
||||
/* XXX need to clone too */
|
||||
job->owner = from->owner;
|
||||
job->owner = gncCloneOwner(&from->owner, book);
|
||||
|
||||
gnc_engine_gen_event (&job->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
@@ -219,7 +219,15 @@ void gncJobSetOwner (GncJob *job, GncOwner *owner)
|
||||
if (!job) return;
|
||||
if (!owner) return;
|
||||
if (gncOwnerEqual (owner, &(job->owner))) return;
|
||||
/* XXX: Fail if we have ANY orders or invoices */
|
||||
|
||||
switch (gncOwnerGetType (&(job->owner))) {
|
||||
case GNC_OWNER_CUSTOMER:
|
||||
case GNC_OWNER_VENDOR:
|
||||
break;
|
||||
default:
|
||||
PERR("Unsupported Owner type");
|
||||
return;
|
||||
}
|
||||
|
||||
gncJobBeginEdit (job);
|
||||
|
||||
|
||||
@@ -37,9 +37,11 @@
|
||||
#include "qofquery.h"
|
||||
|
||||
#include "gncCustomerP.h"
|
||||
#include "gncEmployeeP.h"
|
||||
#include "gncJobP.h"
|
||||
#include "gncOwner.h"
|
||||
#include "gncOwnerP.h"
|
||||
#include "gncVendorP.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ID_OWNER
|
||||
|
||||
@@ -162,13 +164,13 @@ void gncOwnerCopy (const GncOwner *src, GncOwner *dest)
|
||||
memcpy (dest, src, sizeof (*dest));
|
||||
}
|
||||
|
||||
GncOwner
|
||||
GncOwner
|
||||
gncCloneOwner (const GncOwner *from, QofBook *book)
|
||||
{
|
||||
GncOwner owner = {GNC_OWNER_NONE};
|
||||
GncOwner owner = { GNC_OWNER_NONE };
|
||||
if (!from) return owner;
|
||||
owner.type = from->type;
|
||||
switch (from->type)
|
||||
switch (from->type)
|
||||
{
|
||||
case GNC_OWNER_NONE:
|
||||
return owner;
|
||||
@@ -182,10 +184,10 @@ gncCloneOwner (const GncOwner *from, QofBook *book)
|
||||
owner.owner.job = gncJobObtainTwin (from->owner.job, book);
|
||||
return owner;
|
||||
case GNC_OWNER_VENDOR:
|
||||
/* XXX unfinished */
|
||||
owner.owner.vendor = gncVendorObtainTwin (from->owner.vendor, book);
|
||||
return owner;
|
||||
case GNC_OWNER_EMPLOYEE:
|
||||
/* XXX unfinished */
|
||||
owner.owner.employee = gncEmployeeObtainTwin (from->owner.employee, book);
|
||||
return owner;
|
||||
default:
|
||||
return owner;
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
typedef struct gnc_owner_s GncOwner;
|
||||
|
||||
#define GNC_ID_OWNER "gncOwner"
|
||||
#define GNC_IS_OWNER(obj) (QOF_CHECK_TYPE((obj), GNC_ID_OWNER))
|
||||
#define GNC_OWNER(obj) (QOF_CHECK_CAST((obj), GNC_ID_OWNER, GncOwner))
|
||||
|
||||
#include "gncCustomer.h"
|
||||
#include "gncJob.h"
|
||||
@@ -101,16 +99,16 @@ void gncOwnerAttachToLot (GncOwner *owner, GNCLot *lot);
|
||||
*/
|
||||
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner);
|
||||
|
||||
#define OWNER_TYPE "type"
|
||||
#define OWNER_CUSTOMER "customer"
|
||||
#define OWNER_JOB "job"
|
||||
#define OWNER_VENDOR "vendor"
|
||||
#define OWNER_EMPLOYEE "employee"
|
||||
#define OWNER_PARENT "parent"
|
||||
#define OWNER_PARENTG "parent-guid"
|
||||
#define OWNER_NAME "name"
|
||||
#define OWNER_TYPE "type"
|
||||
#define OWNER_CUSTOMER "customer"
|
||||
#define OWNER_JOB "job"
|
||||
#define OWNER_VENDOR "vendor"
|
||||
#define OWNER_EMPLOYEE "employee"
|
||||
#define OWNER_PARENT "parent"
|
||||
#define OWNER_PARENTG "parent-guid"
|
||||
#define OWNER_NAME "name"
|
||||
|
||||
#define OWNER_FROM_LOT "owner-from-lot"
|
||||
#define OWNER_FROM_LOT "owner-from-lot"
|
||||
|
||||
/*
|
||||
* These two functions are mainly for the convenience of scheme code.
|
||||
|
||||
@@ -34,9 +34,8 @@
|
||||
gboolean gncOwnerRegister (void);
|
||||
|
||||
/** The gncCloneOwner() routine makes a copy of the indicated
|
||||
* owner, and one of its union elements, depending on the
|
||||
* owner type.
|
||||
* owner union structure.
|
||||
*/
|
||||
GncOwner gncCloneOwner (const GncOwner *from, QofBook *book);
|
||||
GncOwner gncCloneOwner (const GncOwner *from, QofBook *);
|
||||
|
||||
#endif /* GNC_OWNERP_H_ */
|
||||
|
||||
@@ -31,12 +31,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "guid.h"
|
||||
#include "messages.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-be-utils.h"
|
||||
|
||||
#include "qofbook.h"
|
||||
#include "qofclass.h"
|
||||
#include "qofid.h"
|
||||
@@ -47,10 +41,17 @@
|
||||
#include "qofquery.h"
|
||||
#include "qofquerycore.h"
|
||||
|
||||
#include "messages.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-be-utils.h"
|
||||
|
||||
#include "gncAddressP.h"
|
||||
#include "gncBillTermP.h"
|
||||
#include "gncBusiness.h"
|
||||
#include "gncVendor.h"
|
||||
#include "gncVendorP.h"
|
||||
#include "gncAddress.h"
|
||||
|
||||
struct _gncVendor
|
||||
{
|
||||
@@ -141,7 +142,6 @@ static void gncVendorFree (GncVendor *vendor)
|
||||
g_free (vendor);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/** Create a copy of a vendor, placing the copy into a new book. */
|
||||
GncVendor *
|
||||
gncCloneVendor (GncVendor *from, QofBook *book)
|
||||
@@ -157,20 +157,23 @@ gncCloneVendor (GncVendor *from, QofBook *book)
|
||||
vendor->id = CACHE_INSERT (from->id);
|
||||
vendor->name = CACHE_INSERT (from->name);
|
||||
vendor->notes = CACHE_INSERT (from->notes);
|
||||
vendor->addr = gncCloneAddress (from->addr, book);
|
||||
vendor->addr = gncCloneAddress (from->addr, &vendor->inst.entity, book);
|
||||
vendor->taxincluded = from->taxincluded;
|
||||
vendor->active = from->active;
|
||||
|
||||
vendor->terms = gncBillTermObtainTwin (from->terms, book);
|
||||
gncBillTermIncRef (vendor->terms);
|
||||
|
||||
vendor->currency = gnc_commodity_obtain_twin (from->currency, book);
|
||||
|
||||
#if 0
|
||||
XXX unfinished
|
||||
vendor->jobs = NULL; xxx
|
||||
|
||||
GncBillTerm * terms;
|
||||
GncAddress * addr;
|
||||
gnc_commodity * currency;
|
||||
GncTaxTable* taxtable;
|
||||
gboolean taxtable_override;
|
||||
GncTaxIncluded taxincluded;
|
||||
gboolean active;
|
||||
GList * jobs;
|
||||
#endif
|
||||
|
||||
gnc_engine_gen_event (&vendor->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
@@ -186,12 +189,11 @@ gncVendorObtainTwin (GncVendor *from, QofBook *book)
|
||||
vendor = (GncVendor *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
|
||||
if (!vendor)
|
||||
{
|
||||
employee = gncCloneEmployee (from, book);
|
||||
vendor = gncCloneVendor (from, book);
|
||||
}
|
||||
|
||||
return vendor;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ============================================================== */
|
||||
/* Set Functions */
|
||||
@@ -243,7 +245,7 @@ void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms)
|
||||
gncBillTermDecRef (vendor->terms);
|
||||
vendor->terms = terms;
|
||||
if (vendor->terms)
|
||||
gncBillTermDecRef (vendor->terms);
|
||||
gncBillTermIncRef (vendor->terms);
|
||||
mark_vendor (vendor);
|
||||
gncVendorCommitEdit (vendor);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,28 @@
|
||||
gboolean gncVendorRegister (void);
|
||||
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.
|
||||
*/
|
||||
|
||||
GncVendor * gncCloneVendor (GncVendor *from, QofBook *);
|
||||
|
||||
/** The gncVendorObtainTwin() will find the 'twin' of the
|
||||
* indicated vendor in the indicated book. If the twin doesn't
|
||||
* yet exist in the book, it will be created (by calling
|
||||
* gncCloneVendor()) 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.
|
||||
*/
|
||||
GncVendor * gncVendorObtainTwin (GncVendor *from, QofBook *book);
|
||||
#define gncVendorSetGUID(V,G) qof_entity_set_guid(QOF_ENTITY(V),(G))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user