AUDIT: r21257 - gnucash/trunk/src/business/business-gnome - Change default post date:

Geert Janssens gjanssens at code.gnucash.org
Wed Sep 14 08:30:00 EDT 2011


Author: gjanssens
Date: 2011-09-14 08:29:59 -0400 (Wed, 14 Sep 2011)
New Revision: 21257
Trac: http://svn.gnucash.org/trac/changeset/21257

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
Log:
Change default post date:
* customer invoices: post at the current date
* bills/vouchers: post at the last date on the bill/voucher
BP

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-09-13 18:49:27 UTC (rev 21256)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-09-14 12:29:59 UTC (rev 21257)
@@ -645,7 +645,7 @@
     KvpFrame *kvpf;
     KvpValue *kvp_val;
     const char *text;
-    EntryList *entries;
+    EntryList *entries, *entries_iter;
     GncEntry* entry;
     gboolean reverse;
     gboolean show_dialog = TRUE;
@@ -699,8 +699,31 @@
     /* Determine which commodity we're working with */
     acct_commodities = gncOwnerGetCommoditiesList(&(iw->owner));
 
+    /* Get the invoice entries */
+    entries = gncInvoiceGetEntries (invoice);
+
+    /* Find the most suitable post date.
+     * For Customer Invoices that would be today.
+     * For Vendor Bills and Employee Vouchers
+     * that would be the date of the most recent invoice entry.
+     * Failing that, today is used as a fallback */
+    postdate = timespec_now();
+
+    if (entries && ((gncInvoiceGetOwnerType (invoice) == GNC_OWNER_VENDOR) ||
+                    (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_EMPLOYEE)))
+    {
+        postdate = gncEntryGetDate ((GncEntry*)entries->data);
+        for (entries_iter = entries; entries_iter != NULL; entries_iter = g_list_next(entries_iter))
+        {
+            Timespec entrydate;
+
+            entrydate = gncEntryGetDate ((GncEntry*)entries_iter->data);
+            if (timespec_cmp(&entrydate, &postdate) > 0)
+                postdate = entrydate;
+        }
+    }
+
     /* Get the due date and posted account */
-    postdate = gncInvoiceGetDateOpened (invoice);
     ddue = postdate;
     memo = NULL;
 
@@ -729,11 +752,11 @@
     /* Fill in the conversion prices with feedback from the user */
     text = _("One or more of the entries are for accounts different from the invoice/bill currency.  You will be asked a conversion rate for each.");
 
-    for (entries = gncInvoiceGetEntries(invoice); entries != NULL; entries = g_list_next(entries))
+    for (entries_iter = entries; entries_iter != NULL; entries_iter = g_list_next(entries_iter))
     {
         Account *this_acc;
 
-        entry = (GncEntry*)entries->data;
+        entry = (GncEntry*)entries_iter->data;
         this_acc = (reverse ? gncEntryGetInvAccount (entry) :
                     gncEntryGetBillAccount (entry));
 



More information about the gnucash-changes mailing list