r22002 - gnucash/trunk/src - Keep the lot list sorted during payment processing to ensure the oldest

Geert Janssens gjanssens at code.gnucash.org
Fri Feb 10 10:35:15 EST 2012


Author: gjanssens
Date: 2012-02-10 10:35:15 -0500 (Fri, 10 Feb 2012)
New Revision: 22002
Trac: http://svn.gnucash.org/trac/changeset/22002

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-payment.c
   gnucash/trunk/src/engine/gncOwner.c
   gnucash/trunk/src/engine/gncOwner.h
Log:
Keep the lot list sorted during payment processing to ensure the oldest
open document is processed first.
In the process, I renamed two helper functions (one of which I had to
extend to work with payment lots).

Modified: gnucash/trunk/src/business/business-gnome/dialog-payment.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-payment.c	2012-02-10 15:35:05 UTC (rev 22001)
+++ gnucash/trunk/src/business/business-gnome/dialog-payment.c	2012-02-10 15:35:15 UTC (rev 22002)
@@ -531,7 +531,7 @@
     g_value_unset (&value);
 
     if (lot)
-        *return_list = g_list_append(*return_list, lot);
+        *return_list = g_list_insert_sorted (*return_list, lot, (GCompareFunc)gncOwnerLotsSortFunc);
 }
 
 void

Modified: gnucash/trunk/src/engine/gncOwner.c
===================================================================
--- gnucash/trunk/src/engine/gncOwner.c	2012-02-10 15:35:05 UTC (rev 22001)
+++ gnucash/trunk/src/engine/gncOwner.c	2012-02-10 15:35:15 UTC (rev 22002)
@@ -656,8 +656,8 @@
     }
 }
 
-static gboolean
-gnc_lot_match_invoice_owner (GNCLot *lot, gpointer user_data)
+gboolean
+gncOwnerLotMatchOwnerFunc (GNCLot *lot, gpointer user_data)
 {
     GncOwner owner_def;
     const GncOwner *owner;
@@ -681,18 +681,25 @@
     return gncOwnerEqual (owner, this_owner);
 }
 
-static gint
-gnc_lot_sort_func (GNCLot *a, GNCLot *b)
+gint
+gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB)
 {
     GncInvoice *ia, *ib;
     Timespec da, db;
 
-    ia = gncInvoiceGetInvoiceFromLot (a);
-    ib = gncInvoiceGetInvoiceFromLot (b);
+    ia = gncInvoiceGetInvoiceFromLot (lotA);
+    ib = gncInvoiceGetInvoiceFromLot (lotB);
 
-    da = gncInvoiceGetDateDue (ia);
-    db = gncInvoiceGetDateDue (ib);
+    if (ia)
+        da = gncInvoiceGetDateDue (ia);
+    else
+        da = xaccTransRetDatePostedTS (xaccSplitGetParent (gnc_lot_get_earliest_split (lotA)));
 
+    if (ib)
+        db = gncInvoiceGetDateDue (ib);
+    else
+        db = xaccTransRetDatePostedTS (xaccSplitGetParent (gnc_lot_get_earliest_split (lotB)));
+
     return timespec_cmp (&da, &db);
 }
 
@@ -1086,7 +1093,7 @@
             continue;
 
         /* Get a list of open lots for this owner and account */
-        lot_list = xaccAccountFindOpenLots (account, gnc_lot_match_invoice_owner,
+        lot_list = xaccAccountFindOpenLots (account, gncOwnerLotMatchOwnerFunc,
                                             (gpointer)owner, NULL);
         /* For each lot */
         for (lot_node = lot_list; lot_node; lot_node = lot_node->next)

Modified: gnucash/trunk/src/engine/gncOwner.h
===================================================================
--- gnucash/trunk/src/engine/gncOwner.h	2012-02-10 15:35:05 UTC (rev 22001)
+++ gnucash/trunk/src/engine/gncOwner.h	2012-02-10 15:35:15 UTC (rev 22002)
@@ -177,9 +177,19 @@
 const GncOwner * gncOwnerGetEndOwner (const GncOwner *owner);
 const GncGUID * gncOwnerGetEndGUID (const GncOwner *owner);
 
-/** attach an owner to a lot */
+/** Attach an owner to a lot */
 void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot);
 
+/** Helper function used to filter a list of lots by owner.
+ */
+gboolean gncOwnerLotMatchOwnerFunc (GNCLot *lot, gpointer user_data);
+
+/** Helper function used to sort lots by date. If the lot is
+ * linked to an invoice, use the invoice posted date, otherwise
+ * use the lot's opened date.
+ */
+gint gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB);
+
 /** Get the owner from the lot.  If an owner is found in the lot,
  * fill in "owner" and return TRUE.  Otherwise return FALSE.
  */



More information about the gnucash-changes mailing list