start work to clone owner

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9499 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2003-10-14 03:34:37 +00:00
parent 8e545f865e
commit a15de4f933
7 changed files with 118 additions and 5 deletions

View File

@ -15,6 +15,10 @@ XXX TODO:
-- TaxTable and BillTerm have common parent/child code.
this could be abstracted into common code.
=======
-- finish onwer cclone
-- vendor, invoice, entry, order
#include "gncBusiness.h"

View File

@ -224,6 +224,20 @@ static void gncCustomerFree (GncCustomer *cust)
g_free (cust);
}
GncCustomer *
gncCustomerObtainTwin (GncCustomer *from, QofBook *book)
{
GncCustomer *cust;
if (!from) return NULL;
cust = (GncCustomer *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
if (!cust)
{
cust = gncCloneCustomer (from, book);
}
return cust;
}
/* ============================================================== */
/* Set Functions */

View File

@ -43,4 +43,15 @@ void gncCustomerSetGUID (GncCustomer *customer, const GUID *guid);
*/
GncCustomer * gncCloneCustomer (GncCustomer *from, QofBook *book);
/** The gncCustomerObtainTwin() will find the 'twin' of the
* indicated customer in the indicated book. If the twin doesn't
* yet exist in the book, it will be created (by calling
* gncCloneCustomer()) 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.
*/
GncCustomer * gncCustomerObtainTwin (GncCustomer *from, QofBook *book);
#endif /* GNC_CUSTOMERP_H_ */

View File

@ -35,10 +35,10 @@
#include "messages.h"
#include "gnc-engine-util.h"
#include "gnc-numeric.h"
#include "gnc-book.h"
#include "gnc-event-p.h"
#include "gnc-be-utils.h"
#include "qofbook.h"
#include "qofclass.h"
#include "qofinstance.h"
#include "qofid.h"

View File

@ -44,7 +44,7 @@ void gncJobSetGUID (GncJob *job, const GUID *guid);
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
* indicated job 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.
*

View File

@ -1,6 +1,28 @@
/********************************************************************\
* gncOwner.c -- Business Interface: Object OWNERs *
* *
* 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 *
* *
\********************************************************************/
/*
* gncOwner.c -- Business Interface: Object OWNERs
* Copyright (C) 2001, 2002 Derek Atkins
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
* Author: Derek Atkins <warlord@MIT.EDU>
*/
@ -9,11 +31,13 @@
#include <glib.h>
#include <string.h> /* for memcpy() */
#include "qofbook.h"
#include "qofclass.h"
#include "qofinstance.h"
#include "qofquerycore.h"
#include "qofquery.h"
#include "gncCustomerP.h"
#include "gncJobP.h"
#include "gncOwner.h"
#include "gncOwnerP.h"
@ -138,6 +162,36 @@ void gncOwnerCopy (const GncOwner *src, GncOwner *dest)
memcpy (dest, src, sizeof (*dest));
}
GncOwner
gncCloneOwner (const GncOwner *from, QofBook *book)
{
GncOwner owner = {GNC_OWNER_NONE};
if (!from) return owner;
owner.type = from->type;
switch (from->type)
{
case GNC_OWNER_NONE:
return owner;
case GNC_OWNER_UNDEFINED:
owner.owner.undefined = from->owner.undefined; /* XXX probably wrong ! */
return owner;
case GNC_OWNER_CUSTOMER:
owner.owner.customer = gncCustomerObtainTwin (from->owner.customer, book);
return owner;
case GNC_OWNER_JOB:
owner.owner.job = gncJobObtainTwin (from->owner.job, book);
return owner;
case GNC_OWNER_VENDOR:
/* XXX unfinished */
return owner;
case GNC_OWNER_EMPLOYEE:
/* XXX unfinished */
return owner;
default:
return owner;
}
}
gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b)
{
if (!a || !b) return FALSE;

View File

@ -1,5 +1,26 @@
/********************************************************************\
* gncOwnerP.h -- Business Interface: Object OWNERs private file *
* *
* 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 *
* *
\********************************************************************/
/*
* gncOwnerP.h -- Business Interface: Object OWNERs
* Copyright (C) 2001, 2002 Derek Atkins
* Author: Derek Atkins <warlord@MIT.EDU>
*/
@ -7,6 +28,15 @@
#ifndef GNC_OWNERP_H_
#define GNC_OWNERP_H_
#include "qofbook.h"
#include "gncOwner.h"
gboolean gncOwnerRegister (void);
/** The gncCloneOwner() routine makes a copy of the indicated
* owner, and one of its union elements, depending on the
* owner type.
*/
GncOwner gncCloneOwner (const GncOwner *from, QofBook *book);
#endif /* GNC_OWNERP_H_ */