r23360 - gnucash/trunk/src - Bug 687479 - Automatic invoice/payment matching on posting an invoice should be an optional feature

Geert Janssens gjanssens at code.gnucash.org
Thu Oct 31 18:24:07 EDT 2013


Author: gjanssens
Date: 2013-10-31 18:24:05 -0400 (Thu, 31 Oct 2013)
New Revision: 23360
Trac: http://svn.gnucash.org/trac/changeset/23360

Modified:
   gnucash/trunk/src/business/business-gnome/business-gnome-utils.h
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/business/business-gnome/dialog-invoice.h
   gnucash/trunk/src/business/business-gnome/dialog-payment.c
   gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c
   gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c
   gnucash/trunk/src/business/business-gnome/gschemas/org.gnucash.dialogs.business.gschema.xml.in
   gnucash/trunk/src/business/business-gnome/gtkbuilder/business-prefs.glade
   gnucash/trunk/src/engine/gncInvoice.c
   gnucash/trunk/src/engine/gncInvoice.h
   gnucash/trunk/src/engine/gncOwner.c
   gnucash/trunk/src/engine/gncOwner.h
   gnucash/trunk/src/engine/test/utest-Invoice.c
   gnucash/trunk/src/plugins/bi_import/dialog-bi-import.c
Log:
Bug 687479 - Automatic invoice/payment matching on posting an invoice should be an optional feature

Modified: gnucash/trunk/src/business/business-gnome/business-gnome-utils.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/business-gnome-utils.h	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/business/business-gnome/business-gnome-utils.h	2013-10-31 22:24:05 UTC (rev 23360)
@@ -31,6 +31,13 @@
 #include "gncInvoice.h"
 
 
+#define GNC_PREFS_GROUP_INVOICE "dialogs.business.invoice"
+#define GNC_PREFS_GROUP_BILL    "dialogs.business.bill"
+#define GNC_PREFS_GROUP_VOUCHER "dialogs.business.voucher"
+
+#define GNC_PREF_AUTO_PAY "auto-pay"
+
+
 GtkWidget * gnc_owner_select_create (GtkWidget *label, GtkWidget *hbox,
                                      QofBook *book, GncOwner *owner);
 

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2013-10-31 22:24:05 UTC (rev 23360)
@@ -763,8 +763,7 @@
     const char *text;
     EntryList *entries, *entries_iter;
     GncEntry* entry;
-    gboolean is_cust_doc;
-    gboolean is_cn;
+    gboolean is_cust_doc, is_cn, auto_pay;
     gboolean show_dialog = TRUE;
     gboolean post_ok = TRUE;
 
@@ -931,8 +930,13 @@
     qof_commit_edit (owner_inst);
 
     /* ... post it ... */
-    gncInvoicePostToAccount (invoice, acc, &postdate, &ddue, memo, accumulate);
+    if (is_cust_doc)
+        auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_INVOICE, GNC_PREF_AUTO_PAY);
+    else
+        auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY);
 
+    gncInvoicePostToAccount (invoice, acc, &postdate, &ddue, memo, accumulate, auto_pay);
+
 cleanup:
     gncInvoiceCommitEdit (invoice);
     gnc_resume_gui_refresh ();

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.h	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.h	2013-10-31 22:24:05 UTC (rev 23360)
@@ -46,11 +46,6 @@
 } invoice_sort_type_t;
 
 
-#define GNC_PREFS_GROUP_INVOICE "dialogs.business.invoice"
-#define GNC_PREFS_GROUP_BILL    "dialogs.business.bill"
-#define GNC_PREFS_GROUP_VOUCHER "dialogs.business.voucher"
-
-
 /* Create and edit an invoice */
 InvoiceWindow * gnc_ui_invoice_edit (GncInvoice *invoice);
 InvoiceWindow * gnc_ui_invoice_new (GncOwner *owner, QofBook *book);

Modified: gnucash/trunk/src/business/business-gnome/dialog-payment.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-payment.c	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/business/business-gnome/dialog-payment.c	2013-10-31 22:24:05 UTC (rev 23360)
@@ -36,6 +36,7 @@
 #include "gnc-date-edit.h"
 #include "gnc-amount-edit.h"
 #include "gnc-gtk-utils.h"
+#include "gnc-prefs.h"
 #include "gnc-tree-view-account.h"
 #include "Transaction.h"
 #include "Account.h"
@@ -595,6 +596,7 @@
         gnc_numeric exch = gnc_numeric_create(1, 1); //default to "one to one" rate
         GList *selected_lots = NULL;
         GtkTreeSelection *selection;
+        gboolean auto_pay;
 
         /* Obtain all our ancillary information */
         memo = gtk_entry_get_text (GTK_ENTRY (pw->memo_entry));
@@ -630,8 +632,13 @@
         }
 
         /* Perform the payment */
+        if (gncOwnerGetType (&(pw->owner)) == GNC_OWNER_CUSTOMER)
+            auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_INVOICE, GNC_PREF_AUTO_PAY);
+        else
+            auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY);
+
         gncOwnerApplyPayment (&pw->owner, pw->pre_existing_txn, selected_lots,
-                              post, acc, amount_tot, exch, date, memo, num);
+                              post, acc, amount_tot, exch, date, memo, num, auto_pay);
     }
     gnc_resume_gui_refresh ();
 

Modified: gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c	2013-10-31 22:24:05 UTC (rev 23360)
@@ -37,6 +37,7 @@
 #include "dialog-payment.h"
 #include "dialog-tax-table.h"
 #include "dialog-vendor.h"
+#include "business-gnome-utils.h"
 #include "gnc-plugin-business.h"
 #include "gnc-plugin-page-invoice.h"
 #include "gnc-plugin-page-owner-tree.h"

Modified: gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c	2013-10-31 22:24:05 UTC (rev 23360)
@@ -27,6 +27,7 @@
 #include <glib/gi18n.h>
 
 #include "gnc-plugin.h"
+#include "business-gnome-utils.h"
 #include "dialog-invoice.h"
 #include "gnc-ledger-display.h"
 #include "gnc-plugin-page-invoice.h"

Modified: gnucash/trunk/src/business/business-gnome/gschemas/org.gnucash.dialogs.business.gschema.xml.in
===================================================================
--- gnucash/trunk/src/business/business-gnome/gschemas/org.gnucash.dialogs.business.gschema.xml.in	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/business/business-gnome/gschemas/org.gnucash.dialogs.business.gschema.xml.in	2013-10-31 22:24:05 UTC (rev 23360)
@@ -107,6 +107,11 @@
       <summary>Is tax included in this type of business entry?</summary>
       <description>If set to active then tax is included by default in entries of this type.  This setting is inherited by new customers and vendors.</description>
     </key>
+    <key name="auto-pay" type="b">
+      <default>false</default>
+      <summary>Auto pay when posting.</summary>
+      <description>At post time, automatically attempt to pay customer documents with oustanding pre-payments and counter documents. The pre-payments and documents obviously have to be against the same customer. Counder documents are documents with opposite sign. For example for an invoice, customer credit notes and negative invoices are considered counter documents.</description>
+    </key>
     <key name="enable-toolbuttons" type="b">
       <default>false</default>
       <summary>Enable extra toolbar buttons for business</summary>
@@ -134,6 +139,11 @@
       <summary>Is tax included in this type of business entry?</summary>
       <description>If set to active then tax is included by default in entries of this type.  This setting is inherited by new customers and vendors.</description>
     </key>
+    <key name="auto-pay" type="b">
+      <default>false</default>
+      <summary>Auto pay when posting.</summary>
+      <description>At post time, automatically attempt to pay vendor documents with oustanding pre-payments and counter documents. The pre-payments and documents obviously have to be against the same vendor. Counder documents are documents with opposite sign. For example for a bill, vendor credit notes and negative bills are considered counter documents.</description>
+    </key>
     <key name="notify-when-due" type="b">
       <default>true</default>
       <summary>Show bills due reminder at startup</summary>

Modified: gnucash/trunk/src/business/business-gnome/gtkbuilder/business-prefs.glade
===================================================================
--- gnucash/trunk/src/business/business-gnome/gtkbuilder/business-prefs.glade	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/business/business-gnome/gtkbuilder/business-prefs.glade	2013-10-31 22:24:05 UTC (rev 23360)
@@ -2,6 +2,26 @@
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
+  <object class="GtkListStore" id="liststore_printinvoice">
+    <columns>
+      <!-- column-name item -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Printable Invoice</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Tax Invoice</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Easy Invoice</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Fancy Invoice</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkWindow" id="Preferences">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -11,20 +31,54 @@
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="border_width">6</property>
-        <property name="n_rows">10</property>
+        <property name="n_rows">14</property>
         <property name="n_columns">4</property>
         <property name="column_spacing">12</property>
         <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
           <object class="GtkLabel" id="label53">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="xalign">0</property>
           </object>
           <packing>
-            <property name="top_attach">2</property>
-            <property name="bottom_attach">3</property>
+            <property name="right_attach">4</property>
+            <property name="top_attach">4</property>
+            <property name="bottom_attach">5</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
           </packing>
         </child>
         <child>
@@ -37,10 +91,10 @@
           </object>
           <packing>
             <property name="right_attach">2</property>
-            <property name="top_attach">4</property>
-            <property name="bottom_attach">5</property>
+            <property name="top_attach">5</property>
+            <property name="bottom_attach">6</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
           </packing>
         </child>
         <child>
@@ -52,15 +106,14 @@
             <property name="has_tooltip">True</property>
             <property name="tooltip_markup">Whether tax is included by default in entries on Bills. This setting is inherited by new customers and vendors.</property>
             <property name="tooltip_text" translatable="yes">Whether tax is included by default in entries on Bills. This setting is inherited by new customers and vendors.</property>
-            <property name="use_action_appearance">False</property>
             <property name="use_underline">True</property>
             <property name="draw_indicator">True</property>
           </object>
           <packing>
-            <property name="top_attach">9</property>
-            <property name="bottom_attach">10</property>
+            <property name="top_attach">12</property>
+            <property name="bottom_attach">13</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
             <property name="x_padding">12</property>
           </packing>
         </child>
@@ -71,7 +124,7 @@
             <property name="has_tooltip">True</property>
             <property name="tooltip_markup">How many days in the future to warn about Bills coming due.</property>
             <property name="tooltip_text" translatable="yes">How many days in the future to warn about Bills coming due.</property>
-            <property name="invisible_char">&#x25CF;</property>
+            <property name="invisible_char">●</property>
             <property name="invisible_char_set">True</property>
             <property name="primary_icon_activatable">False</property>
             <property name="secondary_icon_activatable">False</property>
@@ -84,13 +137,16 @@
           <packing>
             <property name="left_attach">3</property>
             <property name="right_attach">4</property>
-            <property name="top_attach">8</property>
-            <property name="bottom_attach">9</property>
-            <property name="x_options"></property>
-            <property name="y_options"></property>
+            <property name="top_attach">11</property>
+            <property name="bottom_attach">12</property>
+            <property name="x_options"/>
+            <property name="y_options"/>
           </packing>
         </child>
         <child>
+          <placeholder/>
+        </child>
+        <child>
           <object class="GtkLabel" id="label15">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
@@ -102,10 +158,10 @@
           <packing>
             <property name="left_attach">2</property>
             <property name="right_attach">3</property>
-            <property name="top_attach">8</property>
-            <property name="bottom_attach">9</property>
+            <property name="top_attach">11</property>
+            <property name="bottom_attach">12</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
           </packing>
         </child>
         <child>
@@ -117,16 +173,15 @@
             <property name="has_tooltip">True</property>
             <property name="tooltip_markup">Whether to display the list of Bills Due at startup.</property>
             <property name="tooltip_text" translatable="yes">Whether to display the list of Bills Due at startup.</property>
-            <property name="use_action_appearance">False</property>
             <property name="use_underline">True</property>
             <property name="draw_indicator">True</property>
           </object>
           <packing>
             <property name="right_attach">2</property>
-            <property name="top_attach">8</property>
-            <property name="bottom_attach">9</property>
+            <property name="top_attach">11</property>
+            <property name="bottom_attach">12</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
             <property name="x_padding">12</property>
           </packing>
         </child>
@@ -140,10 +195,10 @@
           </object>
           <packing>
             <property name="right_attach">2</property>
-            <property name="top_attach">7</property>
-            <property name="bottom_attach">8</property>
+            <property name="top_attach">10</property>
+            <property name="bottom_attach">11</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
           </packing>
         </child>
         <child>
@@ -153,10 +208,11 @@
             <property name="xalign">0</property>
           </object>
           <packing>
-            <property name="top_attach">5</property>
-            <property name="bottom_attach">6</property>
+            <property name="right_attach">4</property>
+            <property name="top_attach">9</property>
+            <property name="bottom_attach">10</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
           </packing>
         </child>
         <child>
@@ -168,16 +224,15 @@
             <property name="has_tooltip">True</property>
             <property name="tooltip_markup">Whether tax is included by default in entries on Invoices. This setting is inherited by new customers and vendors.</property>
             <property name="tooltip_text" translatable="yes">Whether tax is included by default in entries on Invoices. This setting is inherited by new customers and vendors.</property>
-            <property name="use_action_appearance">False</property>
             <property name="use_underline">True</property>
             <property name="draw_indicator">True</property>
           </object>
           <packing>
             <property name="right_attach">2</property>
-            <property name="top_attach">5</property>
-            <property name="bottom_attach">6</property>
+            <property name="top_attach">7</property>
+            <property name="bottom_attach">8</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
             <property name="x_padding">12</property>
           </packing>
         </child>
@@ -190,7 +245,6 @@
             <property name="has_tooltip">True</property>
             <property name="tooltip_markup">Whether multiple entries in an invoice which transfer to the same account should be accumulated into a single split by default. This setting can be changed in the Post dialog.</property>
             <property name="tooltip_text" translatable="yes">Whether multiple entries in an invoice which transfer to the same account should be accumulated into a single split by default. This setting can be changed in the Post dialog.</property>
-            <property name="use_action_appearance">False</property>
             <property name="use_underline">True</property>
             <property name="draw_indicator">True</property>
           </object>
@@ -199,7 +253,7 @@
             <property name="top_attach">3</property>
             <property name="bottom_attach">4</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
             <property name="x_padding">12</property>
           </packing>
         </child>
@@ -212,7 +266,6 @@
             <property name="has_tooltip">True</property>
             <property name="tooltip_markup">If checked, each invoice will be opened in its own top level window. If clear, the invoice will be opened in the current window.</property>
             <property name="tooltip_text" translatable="yes">If checked, each invoice will be opened in its own top level window. If clear, the invoice will be opened in the current window.</property>
-            <property name="use_action_appearance">False</property>
             <property name="use_underline">True</property>
             <property name="draw_indicator">True</property>
           </object>
@@ -221,7 +274,7 @@
             <property name="top_attach">2</property>
             <property name="bottom_attach">3</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
             <property name="x_padding">12</property>
           </packing>
         </child>
@@ -236,7 +289,7 @@
           </object>
           <packing>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
           </packing>
         </child>
         <child>
@@ -248,7 +301,6 @@
             <property name="has_tooltip">True</property>
             <property name="tooltip_markup">If active, extra toolbar buttons for common business functions are shown as well. Otherwise they are not shown.</property>
             <property name="tooltip_text" translatable="yes">If active, extra toolbar buttons for common business functions are shown as well. Otherwise they are not shown.</property>
-            <property name="use_action_appearance">False</property>
             <property name="use_underline">True</property>
             <property name="draw_indicator">True</property>
           </object>
@@ -257,7 +309,7 @@
             <property name="top_attach">1</property>
             <property name="bottom_attach">2</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
             <property name="x_padding">12</property>
           </packing>
         </child>
@@ -282,13 +334,20 @@
             <property name="top_attach">6</property>
             <property name="bottom_attach">7</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
           </packing>
         </child>
         <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
           <object class="GtkLabel" id="label2">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
+            <property name="xalign">0</property>
             <property name="xpad">10</property>
             <property name="label" translatable="yes">Report for printing:</property>
           </object>
@@ -296,7 +355,7 @@
             <property name="top_attach">6</property>
             <property name="bottom_attach">7</property>
             <property name="x_options">GTK_FILL</property>
-            <property name="y_options"></property>
+            <property name="y_options"/>
           </packing>
         </child>
         <child>
@@ -324,7 +383,22 @@
           <placeholder/>
         </child>
         <child>
-          <placeholder/>
+          <object class="GtkCheckButton" id="pref/dialogs.business.invoice/auto-pay">
+            <property name="label" translatable="yes">Auto pay on post_ing</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="tooltip_text" translatable="yes">At post time, automatically attempt to pay customer documents with oustanding pre-payments and counter documents. The pre-payments and documents obviously have to be against the same customer. Counder documents are documents with opposite sign. For example for an invoice, customer credit notes and negative invoices are considered counter documents.</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+          </object>
+          <packing>
+            <property name="top_attach">8</property>
+            <property name="bottom_attach">9</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"/>
+            <property name="x_padding">12</property>
+          </packing>
         </child>
         <child>
           <placeholder/>
@@ -336,26 +410,23 @@
           <placeholder/>
         </child>
         <child>
-          <placeholder/>
+          <object class="GtkCheckButton" id="pref/dialogs.business.bill/auto-pay">
+            <property name="label" translatable="yes">Auto _pay on posting</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="tooltip_text" translatable="yes">At post time, automatically attempt to pay vendor documents with oustanding pre-payments and counter documents. The pre-payments and documents obviously have to be against the same vendor. Counder documents are documents with opposite sign. For example for a bill, vendor credit notes and negative bills are considered counter documents.</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+          </object>
+          <packing>
+            <property name="top_attach">13</property>
+            <property name="bottom_attach">14</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"/>
+            <property name="x_padding">12</property>
+          </packing>
         </child>
-        <child>
-          <placeholder/>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
       </object>
     </child>
   </object>
@@ -366,24 +437,4 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
-  <object class="GtkListStore" id="liststore_printinvoice">
-    <columns>
-      <!-- column-name item -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Printable Invoice</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Tax Invoice</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Easy Invoice</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Fancy Invoice</col>
-      </row>
-    </data>
-  </object>
 </interface>

Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/engine/gncInvoice.c	2013-10-31 22:24:05 UTC (rev 23360)
@@ -1260,7 +1260,8 @@
 
 Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
                                        Timespec *post_date, Timespec *due_date,
-                                       const char * memo, gboolean accumulatesplits)
+                                       const char * memo, gboolean accumulatesplits,
+                                       gboolean autopay)
 {
     Transaction *txn;
     QofBook *book;
@@ -1274,7 +1275,6 @@
     char *lot_title;
     Account *ccard_acct = NULL;
     const GncOwner *owner;
-    gboolean autopay = TRUE; /* FIXME this will have to become a user selectable option at some point */
 
     if (!invoice || !acc) return NULL;
 

Modified: gnucash/trunk/src/engine/gncInvoice.h
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.h	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/engine/gncInvoice.h	2013-10-31 22:24:05 UTC (rev 23360)
@@ -177,11 +177,24 @@
  * that is tied to this invoice.   The transaction is set with
  * the supplied posted date, due date, and memo.  The Transaction
  * description is set to the name of the company.
+ *
+ * If accumulate splits is TRUE, entries in the same account
+ * will be merged into one single split in that account.
+ * Otherwise each entry will be posted as a separate split,
+ * possibly resulting in multiple splits in one account.
+ *
+ * If autopay is TRUE, the code will try to find pre-payments,
+ * invoices or credit notes that can reduce the amount due for this
+ * invoice, marking the invoice as fully or partially paid, depending
+ * on the amounts on all documents involved. If autopay is FALSE,
+ * it's the user's responsibility to explicitly pay the invoice.
+ *
  */
 Transaction *
 gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
                          Timespec *posted_date, Timespec *due_date,
-                         const char *memo, gboolean accumulatesplits);
+                         const char *memo, gboolean accumulatesplits,
+                         gboolean autopay);
 
 /**
  * Unpost this invoice.  This will destroy the posted transaction and

Modified: gnucash/trunk/src/engine/gncOwner.c
===================================================================
--- gnucash/trunk/src/engine/gncOwner.c	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/engine/gncOwner.c	2013-10-31 22:24:05 UTC (rev 23360)
@@ -1024,10 +1024,10 @@
 gncOwnerApplyPayment (const GncOwner *owner, Transaction *txn, GList *lots,
                       Account *posted_acc, Account *xfer_acc,
                       gnc_numeric amount, gnc_numeric exch, Timespec date,
-                      const char *memo, const char *num)
+                      const char *memo, const char *num, gboolean auto_pay)
 {
     GNCLot *payment_lot;
-    GList *selected_lots;
+    GList *selected_lots = NULL;
 
     /* Verify our arguments */
     if (!owner || !posted_acc || !xfer_acc) return;
@@ -1039,7 +1039,7 @@
 
     if (lots)
         selected_lots = lots;
-    else
+    else if (auto_pay)
         selected_lots = xaccAccountFindOpenLots (posted_acc, gncOwnerLotMatchOwnerFunc,
                         (gpointer)owner, NULL);
 
@@ -1050,6 +1050,7 @@
     if (payment_lot)
         selected_lots = g_list_prepend (selected_lots, payment_lot);
     gncOwnerAutoApplyPaymentsWithLots (owner, selected_lots);
+    g_list_free (selected_lots);
 }
 
 GList *

Modified: gnucash/trunk/src/engine/gncOwner.h
===================================================================
--- gnucash/trunk/src/engine/gncOwner.h	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/engine/gncOwner.h	2013-10-31 22:24:05 UTC (rev 23360)
@@ -264,7 +264,7 @@
 gncOwnerApplyPayment (const GncOwner *owner, Transaction *txn, GList *lots,
                       Account *posted_acc, Account *xfer_acc,
                       gnc_numeric amount, gnc_numeric exch, Timespec date,
-                      const char *memo, const char *num);
+                      const char *memo, const char *num, gboolean auto_pay);
 
 /** Returns a GList of account-types based on the owner type */
 GList * gncOwnerGetAccountTypesList (const GncOwner *owner);

Modified: gnucash/trunk/src/engine/test/utest-Invoice.c
===================================================================
--- gnucash/trunk/src/engine/test/utest-Invoice.c	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/engine/test/utest-Invoice.c	2013-10-31 22:24:05 UTC (rev 23360)
@@ -81,7 +81,7 @@
 
     g_test_message( "Will now post the invoice" );
     g_assert(!gncInvoiceIsPosted(invoice));
-    gncInvoicePostToAccount(invoice, fixture->account, &ts1, &ts2, "memo", TRUE);
+    gncInvoicePostToAccount(invoice, fixture->account, &ts1, &ts2, "memo", TRUE, FALSE);
     g_assert(gncInvoiceIsPosted(invoice));
 
     gncInvoiceUnpost(invoice, TRUE);

Modified: gnucash/trunk/src/plugins/bi_import/dialog-bi-import.c
===================================================================
--- gnucash/trunk/src/plugins/bi_import/dialog-bi-import.c	2013-10-31 22:23:28 UTC (rev 23359)
+++ gnucash/trunk/src/plugins/bi_import/dialog-bi-import.c	2013-10-31 22:24:05 UTC (rev 23360)
@@ -46,6 +46,7 @@
 #include "gncVendorP.h"
 #include "gncVendor.h"
 #include "gncEntry.h"
+#include "gnc-prefs.h"
 
 #include "gnc-exp-parser.h"
 
@@ -61,6 +62,7 @@
 // To open the invoices for editing
 #include "business/business-gnome/gnc-plugin-page-invoice.h"
 #include "business/business-gnome/dialog-invoice.h"
+#include "business/business-gnome/business-gnome-utils.h"
 
 
 //#ifdef HAVE_GLIB_2_14
@@ -509,6 +511,9 @@
 
     // these arguments are needed
     g_return_if_fail (store && book);
+    // logic of this function only works for bills or invoices
+    g_return_if_fail ((g_ascii_strcasecmp (type, "INVOICE") == 0) ||
+            (g_ascii_strcasecmp (type, "BILL") == 0));
 
     // allow to call this function without statistics
     if (!n_invoices_created)
@@ -727,7 +732,14 @@
                 if (qof_scan_date (date_posted, &day, &month, &year))
                 {
                     // autopost this invoice
+                    gboolean auto_pay;
                     Timespec d1, d2;
+
+                    if (g_ascii_strcasecmp (type, "INVOICE") == 0)
+                        auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_INVOICE, GNC_PREF_AUTO_PAY);
+                    else
+                        auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY);
+
                     d1 = gnc_dmy2timespec (day, month, year);
                     // FIXME: Must check for the return value of qof_scan_date!
                     qof_scan_date (due_date, &day, &month, &year);	// obtains the due date, or leaves it at date_posted
@@ -736,7 +748,8 @@
                           (gnc_get_current_root_account (), account_posted);
                     gncInvoicePostToAccount (invoice, acc, &d1, &d2,
                                              memo_posted,
-                                             text2bool (accumulatesplits));
+                                             text2bool (accumulatesplits),
+                                             auto_pay);
                 }
             }
             g_free (new_id);



More information about the gnucash-changes mailing list