r21530 - gnucash/trunk/src - Bug #651565 - Billing term not set properly when using "Clone

Geert Janssens gjanssens at code.gnucash.org
Mon Nov 7 09:41:58 EST 2011


Author: gjanssens
Date: 2011-11-07 09:41:57 -0500 (Mon, 07 Nov 2011)
New Revision: 21530
Trac: http://svn.gnucash.org/trac/changeset/21530

Modified:
   gnucash/trunk/src/business/business-gnome/business-gnome-utils.c
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/engine/gncBillTerm.c
   gnucash/trunk/src/engine/gncBillTerm.h
Log:
Bug #651565 - Billing term not set properly when using "Clone
Invoice/Bill" or "New Invoice/Bill for same owner"

Modified: gnucash/trunk/src/business/business-gnome/business-gnome-utils.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/business-gnome-utils.c	2011-11-07 01:01:57 UTC (rev 21529)
+++ gnucash/trunk/src/business/business-gnome/business-gnome-utils.c	2011-11-07 14:41:57 UTC (rev 21530)
@@ -375,6 +375,7 @@
  */
 
 typedef const char * (*GenericLookup_t)(gpointer);
+typedef gboolean (*GenericEqual_t)(gpointer, gpointer);
 
 typedef struct
 {
@@ -384,6 +385,7 @@
     gboolean     none_ok;
     const char * (*get_name)(gpointer);
     GList *      (*get_list)(QofBook*);
+    gboolean     (*is_equal)(gpointer, gpointer);
 
 } ListStoreData;
 
@@ -442,6 +444,7 @@
                        gboolean none_ok, QofIdType type_name,
                        GList * (*get_list)(QofBook*),
                        GenericLookup_t get_name,
+                       GenericEqual_t is_equal,
                        gpointer initial_choice)
 {
     ListStoreData *lsd;
@@ -462,6 +465,7 @@
         lsd->none_ok = none_ok;
         lsd->get_name = get_name;
         lsd->get_list = get_list;
+        lsd->is_equal = is_equal;
         g_object_set_data (G_OBJECT (cbox), "liststore-data", lsd);
 
         lsd->component_id =
@@ -501,6 +505,7 @@
     gnc_simple_combo_make (cbox, book, none_ok, GNC_BILLTERM_MODULE_NAME,
                            gncBillTermGetTerms,
                            (GenericLookup_t)gncBillTermGetName,
+                           (GenericEqual_t)gncBillTermIsFamily,
                            (gpointer)initial_choice);
 }
 
@@ -513,6 +518,7 @@
     gnc_simple_combo_make (cbox, book, none_ok, GNC_TAXTABLE_MODULE_NAME,
                            gncTaxTableGetTables,
                            (GenericLookup_t)gncTaxTableGetName,
+                           NULL,
                            (gpointer)initial_choice);
 }
 
@@ -524,7 +530,7 @@
 
     if (!cbox) return;
 
-    gnc_simple_combo_make (cbox, NULL, FALSE, NULL, NULL, NULL,
+    gnc_simple_combo_make (cbox, NULL, FALSE, NULL, NULL, NULL, NULL,
                            GINT_TO_POINTER(initial_choice));
     liststore = GTK_LIST_STORE (gtk_combo_box_get_model (cbox));
 
@@ -565,6 +571,7 @@
     GtkTreeIter iter;
     GtkTreeModel *model;
     gboolean valid_iter;
+    ListStoreData *lsd = g_object_get_data (G_OBJECT (cbox), "liststore-data");
 
     if (!cbox) return;
 
@@ -576,12 +583,22 @@
         GValue value = { 0 };
 
         gtk_tree_model_get_value (model, &iter, 1, &value);
-        if (g_value_get_pointer(&value) == data)
+        if (lsd && lsd->is_equal)    // A specific comparator function was set
         {
-            gtk_combo_box_set_active_iter (cbox, &iter);
-            return;
+            if ((lsd->is_equal)(g_value_get_pointer(&value), data))
+            {
+                gtk_combo_box_set_active_iter (cbox, &iter);
+                return;
+            }
         }
-
+        else    // No specific comparator function set, use generic pointer comparison instead
+        {
+            if (g_value_get_pointer(&value) == data)
+            {
+                gtk_combo_box_set_active_iter (cbox, &iter);
+                return;
+            }
+        }
         valid_iter = gtk_tree_model_iter_next (model, &iter);
     }
 }

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-11-07 01:01:57 UTC (rev 21529)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-11-07 14:41:57 UTC (rev 21530)
@@ -2240,11 +2240,25 @@
 
     if (invoice == NULL)
     {
+        GncBillTerm *owner_terms = NULL;
         iw->dialog_type = NEW_INVOICE;
         invoice = gncInvoiceCreate (bookp);
         gncInvoiceSetCurrency (invoice, gnc_default_currency ());
         iw->book = bookp;
         start_owner = owner;
+        switch (gncOwnerGetType (gncOwnerGetEndOwner (owner)))
+        {
+            case GNC_OWNER_CUSTOMER:
+                owner_terms = gncCustomerGetTerms (gncOwnerGetCustomer (gncOwnerGetEndOwner (owner)));
+                break;
+            case GNC_OWNER_VENDOR:
+                owner_terms = gncVendorGetTerms (gncOwnerGetVendor (gncOwnerGetEndOwner (owner)));
+                break;
+            default:
+                break;
+        }
+        if (owner_terms)
+            gncInvoiceSetTerms (invoice, owner_terms);
     }
     else
     {

Modified: gnucash/trunk/src/engine/gncBillTerm.c
===================================================================
--- gnucash/trunk/src/engine/gncBillTerm.c	2011-11-07 01:01:57 UTC (rev 21529)
+++ gnucash/trunk/src/engine/gncBillTerm.c	2011-11-07 14:41:57 UTC (rev 21530)
@@ -695,6 +695,14 @@
     return TRUE;
 }
 
+gboolean gncBillTermIsFamily (const GncBillTerm *a, const GncBillTerm *b)
+{
+    if (!gncBillTermCompare (a, b))
+        return TRUE;
+    else
+        return FALSE;
+}
+
 gboolean gncBillTermIsDirty (const GncBillTerm *term)
 {
     if (!term) return FALSE;

Modified: gnucash/trunk/src/engine/gncBillTerm.h
===================================================================
--- gnucash/trunk/src/engine/gncBillTerm.h	2011-11-07 01:01:57 UTC (rev 21529)
+++ gnucash/trunk/src/engine/gncBillTerm.h	2011-11-07 14:41:57 UTC (rev 21530)
@@ -143,8 +143,22 @@
 gint64 gncBillTermGetRefcount (const GncBillTerm *term);
 /** @} */
 
+/** @name Comparison Functions
+ @{ */
+/** Compare BillTerms on their name for sorting. */
 int gncBillTermCompare (const GncBillTerm *a, const GncBillTerm *b);
+/** Check if all internal fields of a and b match. */
 gboolean gncBillTermEqual(const GncBillTerm *a, const GncBillTerm *b);
+/** Check only if the bill terms are "family". This is the case if
+ *  - a and b are the same bill term
+ *  - a is b's parent or vice versa
+ *  - a and be are children of the same parent
+ *
+ *  In practice, this check if performed by comparing the bill term's names.
+ *  This is required to be unique per parent/children group.
+ */
+gboolean gncBillTermIsFamily (const GncBillTerm *a, const GncBillTerm *b);
+/** @} */
 
 /********************************************************/
 /* functions to compute dates from Bill Terms           */



More information about the gnucash-changes mailing list