r16854 - gnucash/trunk/src/business/business-gnome - Save last used account for posting of invoices in kvp slots of effective owners.

Andreas Köhler andi5 at cvs.gnucash.org
Sun Jan 13 07:46:29 EST 2008


Author: andi5
Date: 2008-01-13 07:46:28 -0500 (Sun, 13 Jan 2008)
New Revision: 16854
Trac: http://svn.gnucash.org/trac/changeset/16854

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-date-close.c
   gnucash/trunk/src/business/business-gnome/dialog-date-close.h
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
Log:
Save last used account for posting of invoices in kvp slots of effective owners.

The slot is named "last_posted_to_acct".  Before showing the post-to
dialog, try to read that slot and pre-select the account appropriately.


Modified: gnucash/trunk/src/business/business-gnome/dialog-date-close.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-date-close.c	2008-01-13 12:46:19 UTC (rev 16853)
+++ gnucash/trunk/src/business/business-gnome/dialog-date-close.c	2008-01-13 12:46:28 UTC (rev 16854)
@@ -103,9 +103,7 @@
   gnc_account_sel_set_acct_filters( gas, ddc->acct_types );
   gnc_account_sel_set_new_account_ability( gas, TRUE );
   gnc_account_sel_set_new_account_modal( gas, TRUE );
-
-  /* XXX: Some way to remember the last selection? */
-  gnc_account_sel_set_account( gas, NULL );
+  gnc_account_sel_set_account( gas, ddc->acct );
 }
 
 static void
@@ -248,6 +246,7 @@
   ddc->ts2 = post;
   ddc->book = book;
   ddc->acct_types = acct_types;
+  ddc->acct = *acct;
   ddc->memo = memo;
   ddc->terms = terms;
 
@@ -357,6 +356,7 @@
   ddc->ts = date;
   ddc->book = book;
   ddc->acct_types = acct_types;
+  ddc->acct = *acct;
 
   xml = gnc_glade_xml_new ("date-close.glade", "Date Account Dialog");
   ddc->dialog = glade_xml_get_widget (xml, "Date Account Dialog");
@@ -364,6 +364,8 @@
 
   acct_box = glade_xml_get_widget (xml, "acct_hbox");
   ddc->acct_combo = gnc_account_sel_new();
+  if (*acct)
+    gnc_account_sel_set_account (GNC_ACCOUNT_SEL(ddc->acct_combo), *acct);
   gtk_box_pack_start (GTK_BOX(acct_box), ddc->acct_combo, TRUE, TRUE, 0);
 
   date_box = glade_xml_get_widget (xml, "date_box");

Modified: gnucash/trunk/src/business/business-gnome/dialog-date-close.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-date-close.h	2008-01-13 12:46:19 UTC (rev 16853)
+++ gnucash/trunk/src/business/business-gnome/dialog-date-close.h	2008-01-13 12:46:28 UTC (rev 16854)
@@ -41,6 +41,8 @@
  * Note that the dialog will "own" (and free) the acct_types list.
  * it should be a list of GNCAccountTypes.  If memo is non-NULL,
  * it will g_malloc() a string.  The caller should g_free() it.
+ * The value of *acct will be used as preselection of the account
+ * selection widget.
  */
 
 gboolean

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2008-01-13 12:46:19 UTC (rev 16853)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2008-01-13 12:46:28 UTC (rev 16854)
@@ -85,6 +85,8 @@
 
 #define GCONF_SECTION_SEARCH  "dialogs/business/invoice_search"
 
+#define LAST_POSTED_TO_ACCT "last-posted-to-acct"
+
 void gnc_invoice_window_ok_cb (GtkWidget *widget, gpointer data);
 void gnc_invoice_window_cancel_cb (GtkWidget *widget, gpointer data);
 void gnc_invoice_window_help_cb (GtkWidget *widget, gpointer data);
@@ -602,6 +604,9 @@
   GList * acct_types = NULL;
   Timespec ddue, postdate;
   gboolean accumulate;
+  QofInstance *owner_inst;
+  KvpFrame *kvpf;
+  KvpValue *kvp_val;
 
   /* Make sure the invoice is ok */
   if (!gnc_invoice_window_verify_ok (iw))
@@ -650,6 +655,11 @@
   ddue = postdate;
   memo = NULL;
 
+  owner_inst = qofOwnerGetOwner (gncOwnerGetEndOwner (&(iw->owner)));
+  kvpf = qof_instance_get_slots (owner_inst);
+  acc = xaccAccountLookup (kvp_frame_get_guid (kvpf, LAST_POSTED_TO_ACCT),
+			   iw->book);
+
   /* Get the default for the accumulate option */
   accumulate = gnc_gconf_get_bool(GCONF_SECTION_INVOICE, "accumulate_splits", NULL);
 
@@ -667,6 +677,13 @@
   gncInvoiceBeginEdit (invoice);
   gnc_invoice_window_ok_save (iw);
 
+  /* Save acc as last used account in the kvp frame of the invoice owner */
+  kvp_val = kvp_value_new_guid (qof_instance_get_guid (QOF_INSTANCE (acc)));;
+  qof_begin_edit (owner_inst);
+  kvp_frame_set_slot_nc (kvpf, LAST_POSTED_TO_ACCT, kvp_val);
+  qof_instance_set_dirty (owner_inst);
+  qof_commit_edit (owner_inst);
+  
   /* ... post it; post date is set to now ... */
   gncInvoicePostToAccount (invoice, acc, &postdate, &ddue, memo, accumulate);
   gncInvoiceCommitEdit (invoice);



More information about the gnucash-changes mailing list