Hi, I wonder whether the attached patch, applicable to trunk, is desirable for those that use the business functions. I usually do not touch that code :-)
As of r16773 there is no default account selected in the account selection widgets of invoice/bill/expense voucher post-to dialogs. The patch tries to save the last used account in the kvp slot "last-posted-to-acct" of the effective invoice owner (i.e. owner of job if the job is the owner). Before showing the post-to dialogs it tries to read that slot and pre-selects the account appropriately. Comments? -- andi5
Index: src/business/business-gnome/dialog-date-close.c =================================================================== --- src/business/business-gnome/dialog-date-close.c (Revision 16771) +++ src/business/business-gnome/dialog-date-close.c (Arbeitskopie) @@ -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"); Index: src/business/business-gnome/dialog-date-close.h =================================================================== --- src/business/business-gnome/dialog-date-close.h (Revision 16771) +++ src/business/business-gnome/dialog-date-close.h (Arbeitskopie) @@ -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 Index: src/business/business-gnome/dialog-invoice.c =================================================================== --- src/business/business-gnome/dialog-invoice.c (Revision 16771) +++ src/business/business-gnome/dialog-invoice.c (Arbeitskopie) @@ -76,6 +76,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); @@ -593,6 +595,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)) @@ -641,6 +646,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); @@ -658,6 +668,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);
_______________________________________________ gnucash-devel mailing list gnucash-devel@gnucash.org https://lists.gnucash.org/mailman/listinfo/gnucash-devel