r20081 - gnucash/trunk/src/engine - Add function for creating a new copy of an existing GncInvoice.
Christian Stimming
cstim at code.gnucash.org
Wed Jan 12 15:40:51 EST 2011
Author: cstim
Date: 2011-01-12 15:40:51 -0500 (Wed, 12 Jan 2011)
New Revision: 20081
Trac: http://svn.gnucash.org/trac/changeset/20081
Modified:
gnucash/trunk/src/engine/gncInvoice.c
gnucash/trunk/src/engine/gncInvoice.h
Log:
Add function for creating a new copy of an existing GncInvoice.
Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c 2011-01-12 20:10:30 UTC (rev 20080)
+++ gnucash/trunk/src/engine/gncInvoice.c 2011-01-12 20:40:51 UTC (rev 20081)
@@ -314,6 +314,61 @@
return invoice;
}
+GncInvoice *gncInvoiceCopy (const GncInvoice *from)
+{
+ GncInvoice *invoice;
+ QofBook* book;
+ GList *node;
+
+ g_assert(from);
+ book = qof_instance_get_book(from);
+ g_assert(book);
+
+ invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
+ qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
+
+ gncInvoiceBeginEdit(invoice);
+
+ invoice->id = CACHE_INSERT (from->id);
+ invoice->notes = CACHE_INSERT (from->notes);
+ invoice->billing_id = CACHE_INSERT (from->billing_id);
+ invoice->active = from->active;
+
+ invoice->terms = from->terms;
+ gncBillTermIncRef (invoice->terms);
+
+ gncOwnerCopy(&from->billto, &invoice->billto);
+ gncOwnerCopy(&from->owner, &invoice->owner);
+ invoice->job = from->job; // FIXME: Need IncRef or similar here?!?
+
+ invoice->to_charge_amount = from->to_charge_amount;
+ invoice->date_opened = from->date_opened;
+ invoice->date_posted = from->date_posted;
+
+ // Copy all invoice->entries
+ for (node = from->entries; node; node = node->next)
+ {
+ GncEntry *from_entry = node->data;
+ GncEntry *to_entry = gncEntryCreate(book);
+ gncEntryCopy(from_entry, to_entry);
+
+ if (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_VENDOR)
+ {
+ // this is a vendor bill
+ gncBillAddEntry(invoice, to_entry);
+ }
+ else
+ {
+ // this is an invoice
+ gncInvoiceAddEntry(invoice, to_entry);
+ }
+ }
+
+ gncInvoiceCommitEdit(invoice);
+
+ return invoice;
+}
+
void gncInvoiceDestroy (GncInvoice *invoice)
{
if (!invoice) return;
@@ -594,6 +649,8 @@
{
GncInvoice *old;
+ g_assert(invoice);
+ g_assert(entry);
if (!invoice || !entry) return;
old = gncEntryGetInvoice (entry);
@@ -635,6 +692,8 @@
{
GncInvoice *old;
+ g_assert(bill);
+ g_assert(entry);
if (!bill || !entry) return;
old = gncEntryGetBill (entry);
Modified: gnucash/trunk/src/engine/gncInvoice.h
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.h 2011-01-12 20:10:30 UTC (rev 20080)
+++ gnucash/trunk/src/engine/gncInvoice.h 2011-01-12 20:40:51 UTC (rev 20081)
@@ -68,7 +68,16 @@
/** @name Create/Destroy Functions
@{ */
GncInvoice *gncInvoiceCreate (QofBook *book);
+
void gncInvoiceDestroy (GncInvoice *invoice);
+
+/** Create a new GncInvoice object as a deep copy of the given other
+ * invoice.
+ *
+ * The returned new invoice has everything copied from the other
+ * invoice, including the ID string field. All GncEntries are newly
+ * allocated copies of the original invoice's entries. */
+GncInvoice *gncInvoiceCopy (const GncInvoice *other_invoice);
/** @} */
/** @name Set Functions
More information about the gnucash-changes
mailing list