[Gnucash-changes] r13069 - gnucash/trunk - Re-sort an invoice entry list when an entry date changes (#320566)

Derek Atkins warlord at cvs.gnucash.org
Wed Feb 1 16:49:07 EST 2006


Author: warlord
Date: 2006-02-01 16:49:06 -0500 (Wed, 01 Feb 2006)
New Revision: 13069
Trac: http://svn.gnucash.org/trac/changeset/13069

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/business/business-core/gncEntry.c
   gnucash/trunk/src/business/business-core/gncInvoice.c
   gnucash/trunk/src/business/business-core/gncInvoice.h
Log:
Re-sort an invoice entry list when an entry date changes (#320566)

	* src/business/business-core/gncInvoice.[ch]:
	  Add new API: gncInvoiceSortEntries()
	* src/business/business-core/gncEntry.c:
	  re-sort the parent when the entry date changes.
	  Only re-sort when the existing date is non-zero (i.e.
	  don't re-sort on the initial setting of the date).
	  Fixes #320566.



Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-02-01 21:23:54 UTC (rev 13068)
+++ gnucash/trunk/ChangeLog	2006-02-01 21:49:06 UTC (rev 13069)
@@ -4,6 +4,14 @@
 	  Need to put the new split into the txn as well as the acct
 	  before we call xaccSplitSetBaseValue().  Fixes #325890.
 
+	* src/business/business-core/gncInvoice.[ch]:
+	  Add new API: gncInvoiceSortEntries()
+	* src/business/business-core/gncEntry.c:
+	  re-sort the parent when the entry date changes.
+	  Only re-sort when the existing date is non-zero (i.e.
+	  don't re-sort on the initial setting of the date).
+	  Fixes #320566.
+
 2006-01-31  Derek Atkins  <derek at ihtfp.com>
 
 	* configure.in: include gmodule in GLIB_LIBS

Modified: gnucash/trunk/src/business/business-core/gncEntry.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntry.c	2006-02-01 21:23:54 UTC (rev 13068)
+++ gnucash/trunk/src/business/business-core/gncEntry.c	2006-02-01 21:49:06 UTC (rev 13069)
@@ -266,12 +266,25 @@
 
 void gncEntrySetDate (GncEntry *entry, Timespec date)
 {
+  gboolean first_date = FALSE;
+  Timespec zero_time = { 0, 0 };
+
   if (!entry) return;
   if (timespec_equal (&entry->date, &date)) return;
+  if (timespec_equal (&entry->date, &zero_time))
+    first_date = TRUE;
   gncEntryBeginEdit (entry);
   entry->date = date;
   mark_entry (entry);
   gncEntryCommitEdit (entry);
+
+  /* Don't re-sort the first time we set the date on this entry */
+  if (!first_date) {
+    if (entry->invoice)
+      gncInvoiceSortEntries(entry->invoice);
+    if (entry->bill)
+      gncInvoiceSortEntries(entry->bill);
+  }
 }
 
 void gncEntrySetDateEntered (GncEntry *entry, Timespec date)

Modified: gnucash/trunk/src/business/business-core/gncInvoice.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoice.c	2006-02-01 21:23:54 UTC (rev 13068)
+++ gnucash/trunk/src/business/business-core/gncInvoice.c	2006-02-01 21:49:06 UTC (rev 13069)
@@ -432,6 +432,14 @@
   mark_invoice (bill);
 }
 
+void gncInvoiceSortEntries (GncInvoice *invoice)
+{
+  if (!invoice) return;
+  invoice->entries = g_list_sort(invoice->entries,
+				 (GCompareFunc)gncEntryCompare);
+  mark_invoice(invoice);
+}
+
 /* ================================================================== */
 /* Get Functions */
 

Modified: gnucash/trunk/src/business/business-core/gncInvoice.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoice.h	2006-02-01 21:23:54 UTC (rev 13068)
+++ gnucash/trunk/src/business/business-core/gncInvoice.h	2006-02-01 21:49:06 UTC (rev 13069)
@@ -76,6 +76,11 @@
 void gncBillAddEntry (GncInvoice *bill, GncEntry *entry);
 void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry);
 
+/** Call this function when an Entry is changed and you want to
+    re-sort the list of entries
+*/
+void gncInvoiceSortEntries (GncInvoice *invoice);
+
 /** @name Get Functions 
  @{ */
 const char * gncInvoiceGetID (GncInvoice *invoice);



More information about the gnucash-changes mailing list