r18894 - gnucash/trunk/src/business/business-core - Implement the object reference infrastructure routines to allow a list of business objects referring to a specific other object (e.g. an account) to be determined. This will help fix bug 140400 because the account delete code can now determine a list of business (or other) objects which have references to that account, and prevent the account from being deleted while references still exist.

Phil Longstaff plongstaff at code.gnucash.org
Fri Mar 12 05:16:16 EST 2010


Author: plongstaff
Date: 2010-03-12 05:16:16 -0500 (Fri, 12 Mar 2010)
New Revision: 18894
Trac: http://svn.gnucash.org/trac/changeset/18894

Modified:
   gnucash/trunk/src/business/business-core/gncAddress.c
   gnucash/trunk/src/business/business-core/gncBillTerm.c
   gnucash/trunk/src/business/business-core/gncCustomer.c
   gnucash/trunk/src/business/business-core/gncEmployee.c
   gnucash/trunk/src/business/business-core/gncEntry.c
   gnucash/trunk/src/business/business-core/gncInvoice.c
   gnucash/trunk/src/business/business-core/gncJob.c
   gnucash/trunk/src/business/business-core/gncOrder.c
   gnucash/trunk/src/business/business-core/gncTaxTable.c
   gnucash/trunk/src/business/business-core/gncVendor.c
Log:
Implement the object reference infrastructure routines to allow a list of business objects referring to a specific other object (e.g. an account) to be determined.  This will help fix bug 140400 because the account delete code can now determine a list of business (or other) objects which have references to that account, and prevent the account from being deleted while references still exist.


Modified: gnucash/trunk/src/business/business-core/gncAddress.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncAddress.c	2010-03-12 10:14:27 UTC (rev 18893)
+++ gnucash/trunk/src/business/business-core/gncAddress.c	2010-03-12 10:16:16 UTC (rev 18894)
@@ -138,16 +138,35 @@
     }
 }
 
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    /* Refers to nothing.  The parent field doesn't really count since the parent knows which address
+       belongs to it. */
+    return NULL;
+}
+
 static void
 gnc_address_class_init (GncAddressClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
 
     gobject_class->dispose = gnc_address_dispose;
     gobject_class->finalize = gnc_address_finalize;
     gobject_class->set_property = gnc_address_set_property;
     gobject_class->get_property = gnc_address_get_property;
 
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = NULL;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
     g_object_class_install_property
     (gobject_class,
      PROP_NAME,

Modified: gnucash/trunk/src/business/business-core/gncBillTerm.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncBillTerm.c	2010-03-12 10:14:27 UTC (rev 18893)
+++ gnucash/trunk/src/business/business-core/gncBillTerm.c	2010-03-12 10:16:16 UTC (rev 18894)
@@ -203,16 +203,34 @@
     }
 }
 
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    /* Bill term doesn't refer to anything except other billterms */
+    return NULL;
+}
+
 static void
 gnc_billterm_class_init (GncBillTermClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
 
     gobject_class->dispose = gnc_billterm_dispose;
     gobject_class->finalize = gnc_billterm_finalize;
     gobject_class->set_property = gnc_billterm_set_property;
     gobject_class->get_property = gnc_billterm_get_property;
 
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = NULL;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
     g_object_class_install_property
     (gobject_class,
      PROP_NAME,

Modified: gnucash/trunk/src/business/business-core/gncCustomer.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomer.c	2010-03-12 10:14:27 UTC (rev 18893)
+++ gnucash/trunk/src/business/business-core/gncCustomer.c	2010-03-12 10:16:16 UTC (rev 18894)
@@ -163,16 +163,75 @@
     }
 }
 
+/** Return display name for this object */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncCustomer* cust;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_CUSTOMER(inst), FALSE);
+
+    cust = GNC_CUSTOMER(inst);
+    /* XXX internationalization of "Customer" */
+    return g_strdup_printf("Customer %s", cust->name);
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncCustomer* cust;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_CUSTOMER(inst), FALSE);
+
+    cust = GNC_CUSTOMER(inst);
+
+    if (GNC_IS_BILLTERM(ref))
+    {
+        return (cust->terms == GNC_BILLTERM(ref));
+    }
+    else if (GNC_IS_TAXTABLE(ref))
+    {
+        return (cust->taxtable == GNC_TAXTABLE(ref));
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_BILLTERM(ref) && !GNC_IS_TAXTABLE(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
 static void
 gnc_customer_class_init (GncCustomerClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
 
     gobject_class->dispose = gnc_customer_dispose;
     gobject_class->finalize = gnc_customer_finalize;
     gobject_class->set_property = gnc_customer_set_property;
     gobject_class->get_property = gnc_customer_get_property;
 
+    qof_class->get_display_name = impl_get_display_name;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
     g_object_class_install_property
     (gobject_class,
      PROP_NAME,

Modified: gnucash/trunk/src/business/business-core/gncEmployee.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEmployee.c	2010-03-12 10:14:27 UTC (rev 18893)
+++ gnucash/trunk/src/business/business-core/gncEmployee.c	2010-03-12 10:16:16 UTC (rev 18894)
@@ -146,16 +146,74 @@
     }
 }
 
+/** Get displayable name */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncEmployee* emp;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE);
+
+    emp = GNC_EMPLOYEE(inst);
+    return g_strdup_printf("Employee %s", emp->username);
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncEmployee* emp;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE);
+
+    emp = GNC_EMPLOYEE(inst);
+
+    if (GNC_IS_COMMODITY(ref))
+    {
+        return (emp->currency == GNC_COMMODITY(ref));
+    }
+    else if (GNC_IS_ACCOUNT(ref))
+    {
+        return (emp->ccard_acc == GNC_ACCOUNT(ref));
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_COMMODITY(ref) && !GNC_IS_ACCOUNT(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
 static void
 gnc_employee_class_init (GncEmployeeClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
 
     gobject_class->dispose = gnc_employee_dispose;
     gobject_class->finalize = gnc_employee_finalize;
     gobject_class->set_property = gnc_employee_set_property;
     gobject_class->get_property = gnc_employee_get_property;
 
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
     g_object_class_install_property
     (gobject_class,
      PROP_USERNAME,

Modified: gnucash/trunk/src/business/business-core/gncEntry.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntry.c	2010-03-12 10:14:27 UTC (rev 18893)
+++ gnucash/trunk/src/business/business-core/gncEntry.c	2010-03-12 10:16:16 UTC (rev 18894)
@@ -249,16 +249,100 @@
     }
 }
 
+/** Return displayable name */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncEntry* entry;
+    gchar* display_name;
+    gchar* s;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_ENTRY(inst), FALSE);
+
+    entry = GNC_ENTRY(inst);
+    if (entry->order != NULL)
+    {
+        display_name = qof_instance_get_display_name(QOF_INSTANCE(entry->order));
+        s = g_strdup_printf("Entry in %s", display_name);
+        g_free(display_name);
+        return s;
+    }
+    if (entry->invoice != NULL)
+    {
+        display_name = qof_instance_get_display_name(QOF_INSTANCE(entry->invoice));
+        s = g_strdup_printf("Entry in %s", display_name);
+        g_free(display_name);
+        return s;
+    }
+    if (entry->bill != NULL)
+    {
+        display_name = qof_instance_get_display_name(QOF_INSTANCE(entry->bill));
+        s = g_strdup_printf("Entry in %s", display_name);
+        g_free(display_name);
+        return s;
+    }
+
+    return g_strdup_printf("Entry %p", inst);
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncEntry* entry;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_ENTRY(inst), FALSE);
+
+    entry = GNC_ENTRY(inst);
+
+    if (GNC_IS_ACCOUNT(ref))
+    {
+        Account* acc = GNC_ACCOUNT(ref);
+        return (entry->i_account == acc || entry->b_account == acc);
+    }
+    else if (GNC_IS_TAXTABLE(ref))
+    {
+        GncTaxTable* tt = GNC_TAXTABLE(ref);
+        return (entry->i_tax_table == tt || entry->b_tax_table == tt);
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_ACCOUNT(ref) && !GNC_IS_TAXTABLE(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
 static void
 gnc_entry_class_init (GncEntryClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
 
     gobject_class->dispose = gnc_entry_dispose;
     gobject_class->finalize = gnc_entry_finalize;
     gobject_class->set_property = gnc_entry_set_property;
     gobject_class->get_property = gnc_entry_get_property;
 
+    qof_class->get_display_name = impl_get_display_name;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
     g_object_class_install_property
     (gobject_class,
      PROP_DESCRIPTION,

Modified: gnucash/trunk/src/business/business-core/gncInvoice.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoice.c	2010-03-12 10:14:27 UTC (rev 18893)
+++ gnucash/trunk/src/business/business-core/gncInvoice.c	2010-03-12 10:16:16 UTC (rev 18894)
@@ -177,16 +177,106 @@
     }
 }
 
+/** Returns a string representing this object */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncInvoice* inv;
+    QofInstance* owner;
+    gchar* s;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_INVOICE(inst), FALSE);
+
+    inv = GNC_INVOICE(inst);
+    owner = qofOwnerGetOwner(&inv->owner);
+    if (owner != NULL)
+    {
+        gchar* display_name;
+
+        display_name = qof_instance_get_display_name(owner);
+        s = g_strdup_printf("Invoice %s (%s)", inv->id, display_name);
+        g_free(display_name);
+    }
+    else {
+        s = g_strdup_printf("Invoice %s", inv->id);
+    }
+
+    return s;
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncInvoice* inv;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_INVOICE(inst), FALSE);
+
+    inv = GNC_INVOICE(inst);
+
+    if (GNC_IS_BILLTERM(ref))
+    {
+        return (inv->terms == GNC_BILLTERM(ref));
+    }
+    else if (GNC_IS_JOB(ref))
+    {
+        return (inv->job == GNC_JOB(ref));
+    }
+    else if (GNC_IS_COMMODITY(ref))
+    {
+        return (inv->currency == GNC_COMMODITY(ref));
+    }
+    else if (GNC_IS_ACCOUNT(ref))
+    {
+        return (inv->posted_acc == GNC_ACCOUNT(ref));
+    }
+    else if (GNC_IS_TRANSACTION(ref))
+    {
+        return (inv->posted_txn == GNC_TRANSACTION(ref));
+    }
+    else if (GNC_IS_LOT(ref))
+    {
+        return (inv->posted_lot == GNC_LOT(ref));
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_BILLTERM(ref) && !GNC_IS_JOB(ref) && !GNC_IS_COMMODITY(ref) && !GNC_IS_ACCOUNT(ref)
+            && !GNC_IS_TRANSACTION(ref) && !GNC_IS_LOT(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
 static void
 gnc_invoice_class_init (GncInvoiceClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
 
     gobject_class->dispose = gnc_invoice_dispose;
     gobject_class->finalize = gnc_invoice_finalize;
     gobject_class->set_property = gnc_invoice_set_property;
     gobject_class->get_property = gnc_invoice_get_property;
 
+    qof_class->get_display_name = impl_get_display_name;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
     g_object_class_install_property
     (gobject_class,
      PROP_NOTES,

Modified: gnucash/trunk/src/business/business-core/gncJob.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncJob.c	2010-03-12 10:14:27 UTC (rev 18893)
+++ gnucash/trunk/src/business/business-core/gncJob.c	2010-03-12 10:16:16 UTC (rev 18894)
@@ -137,16 +137,34 @@
     }
 }
 
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    /* Refers to nothing */
+    return NULL;
+}
+
 static void
 gnc_job_class_init (GncJobClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
 
     gobject_class->dispose = gnc_job_dispose;
     gobject_class->finalize = gnc_job_finalize;
     gobject_class->set_property = gnc_job_set_property;
     gobject_class->get_property = gnc_job_get_property;
 
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = NULL;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
     g_object_class_install_property
     (gobject_class,
      PROP_NAME,

Modified: gnucash/trunk/src/business/business-core/gncOrder.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncOrder.c	2010-03-12 10:14:27 UTC (rev 18893)
+++ gnucash/trunk/src/business/business-core/gncOrder.c	2010-03-12 10:16:16 UTC (rev 18894)
@@ -151,16 +151,34 @@
     }
 }
 
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    /* Refers to nothing */
+    return NULL;
+}
+
 static void
 gnc_order_class_init (GncOrderClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
 
     gobject_class->dispose = gnc_order_dispose;
     gobject_class->finalize = gnc_order_finalize;
     gobject_class->set_property = gnc_order_set_property;
     gobject_class->get_property = gnc_order_get_property;
 
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = NULL;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
     g_object_class_install_property
     (gobject_class,
      PROP_NOTES,

Modified: gnucash/trunk/src/business/business-core/gncTaxTable.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncTaxTable.c	2010-03-12 10:14:27 UTC (rev 18893)
+++ gnucash/trunk/src/business/business-core/gncTaxTable.c	2010-03-12 10:16:16 UTC (rev 18894)
@@ -276,16 +276,80 @@
     }
 }
 
+/** Return displayable name */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncTaxTable* tt;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_TAXTABLE(inst), FALSE);
+
+    tt = GNC_TAXTABLE(inst);
+    return g_strdup_printf("Tax table %s", tt->name);
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncTaxTable* tt;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_TAXTABLE(inst), FALSE);
+
+    tt = GNC_TAXTABLE(inst);
+
+    if (GNC_IS_ACCOUNT(ref))
+    {
+        GList* node;
+
+        for (node = tt->entries; node != NULL; node = node->next)
+        {
+            GncTaxTableEntry* tte = node->data;
+
+            if (tte->account == GNC_ACCOUNT(ref))
+            {
+                return TRUE;
+            }
+        }
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_ACCOUNT(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
 static void
 gnc_taxtable_class_init (GncTaxTableClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
 
     gobject_class->dispose = gnc_taxtable_dispose;
     gobject_class->finalize = gnc_taxtable_finalize;
     gobject_class->set_property = gnc_taxtable_set_property;
     gobject_class->get_property = gnc_taxtable_get_property;
 
+    qof_class->get_display_name = impl_get_display_name;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
     g_object_class_install_property
     (gobject_class,
      PROP_NAME,

Modified: gnucash/trunk/src/business/business-core/gncVendor.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncVendor.c	2010-03-12 10:14:27 UTC (rev 18893)
+++ gnucash/trunk/src/business/business-core/gncVendor.c	2010-03-12 10:16:16 UTC (rev 18894)
@@ -152,16 +152,74 @@
     }
 }
 
+/** Return displayable name */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncVendor* v;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_VENDOR(inst), FALSE);
+
+    v = GNC_VENDOR(inst);
+    return g_strdup_printf("Vendor %s", v->name);
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncVendor* v;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_VENDOR(inst), FALSE);
+
+    v = GNC_VENDOR(inst);
+
+    if (GNC_IS_BILLTERM(ref))
+    {
+        return (v->terms == GNC_BILLTERM(ref));
+    }
+    else if (GNC_IS_TAXTABLE(ref))
+    {
+        return (v->taxtable == GNC_TAXTABLE(ref));
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_BILLTERM(ref) && !GNC_IS_TAXTABLE(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
 static void
 gnc_vendor_class_init (GncVendorClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
 
     gobject_class->dispose = gnc_vendor_dispose;
     gobject_class->finalize = gnc_vendor_finalize;
     gobject_class->set_property = gnc_vendor_set_property;
     gobject_class->get_property = gnc_vendor_get_property;
 
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
     g_object_class_install_property
     (gobject_class,
      PROP_NAME,



More information about the gnucash-changes mailing list