Remember the last-used account when processing payment (#329725)

* src/business/business-core/gncOwner.[ch]: Add api to get owner
	  kvp-slots abstractly.
	* src/business/business-gnome/dialog-payment.c: Load/save the
	  last-used transfer account whenever the owner changes or
	  the dialog completes.
	  Fixes #329725.



git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13298 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins
2006-02-19 18:20:18 +00:00
parent abae418947
commit 584f16aa36
4 changed files with 100 additions and 0 deletions

View File

@@ -23,6 +23,13 @@
* src/business/business-reports/fancy-invoice.scm:
Brian's patch to add company-id to the company address.
* src/business/business-core/gncOwner.[ch]: Add api to get owner
kvp-slots abstractly.
* src/business/business-gnome/dialog-payment.c: Load/save the
last-used transfer account whenever the owner changes or
the dialog completes.
Fixes #329725.
2006-02-18 Derek Atkins <derek@ihtfp.com>
* intl-scm/xgettext.scm: remove the absolute path from filenames

View File

@@ -464,6 +464,22 @@ gboolean gncOwnerIsValid (GncOwner *owner)
return (owner->owner.undefined != NULL);
}
KvpFrame* gncOwnerGetSlots(GncOwner* owner)
{
if (!owner) return NULL;
switch (gncOwnerGetType(owner)) {
case GNC_OWNER_CUSTOMER:
case GNC_OWNER_VENDOR:
case GNC_OWNER_EMPLOYEE:
return qof_instance_get_slots(QOF_INSTANCE(owner->owner.undefined));
case GNC_OWNER_JOB:
return gncOwnerGetSlots(gncJobGetOwner(gncOwnerGetJob(owner)));
default:
return NULL;
}
}
/* XXX: Yea, this is broken, but it should work fine for Queries.
* We're single-threaded, right?
*/

View File

@@ -138,6 +138,9 @@ gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner);
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GUID *guid);
/** Get the kvp-frame from the underlying owner object */
KvpFrame* gncOwnerGetSlots(GncOwner* owner);
#define OWNER_TYPE "type"
#define OWNER_TYPE_STRING "type-string" /**< Allows the type to be handled externally. */
#define OWNER_CUSTOMER "customer"

View File

@@ -86,10 +86,75 @@ gnc_payment_window_close_handler (gpointer data)
gtk_widget_destroy (pw->dialog);
}
static void
gnc_payment_dialog_owner_changed(PaymentWindow *pw)
{
Account *last_acct;
GUID *guid;
KvpValue* value;
KvpFrame* slots = gncOwnerGetSlots(&pw->owner);
if (!slots) return;
value = kvp_frame_get_slot_path(slots, "payment", "last_acct", NULL);
if (!value) return;
guid = kvp_value_get_guid(value);
if (!guid) return;
last_acct = xaccAccountLookup(guid, pw->book);
/* Set the last-used transfer account */
if (last_acct) {
gnc_tree_view_account_set_selected_account(GNC_TREE_VIEW_ACCOUNT(pw->acct_tree),
last_acct);
}
}
static void
gnc_payment_dialog_remember_account(PaymentWindow *pw, Account *acc)
{
KvpValue* value;
KvpFrame* slots = gncOwnerGetSlots(&pw->owner);
if (!acc) return;
if (!slots) return;
value = kvp_value_new_guid(xaccAccountGetGUID(acc));
if (!value) return;
kvp_frame_set_slot_path(slots, value, "payment", "last_acct", NULL);
kvp_value_delete(value);
/* XXX: FIXME: Need a commit_edit here to save the data! */
}
static void
gnc_payment_set_owner (PaymentWindow *pw, GncOwner *owner)
{
gnc_owner_set_owner (pw->owner_choice, owner);
gnc_payment_dialog_owner_changed(pw);
}
static int
gnc_payment_dialog_owner_changed_cb (GtkWidget *widget, gpointer data)
{
PaymentWindow *pw = data;
GncOwner owner;
if (!pw) return FALSE;
gncOwnerCopy (&(pw->owner), &owner);
gnc_owner_get_owner (pw->owner_choice, &owner);
/* If this owner really changed, then reset ourselves */
if (!gncOwnerEqual (&owner, &(pw->owner))) {
gncOwnerCopy (&owner, &(pw->owner));
gnc_payment_dialog_owner_changed(pw);
}
return FALSE;
}
void
@@ -164,6 +229,9 @@ gnc_payment_ok_cb (GtkWidget *widget, gpointer data)
}
gnc_resume_gui_refresh ();
/* Save the transfer account, acc */
gnc_payment_dialog_remember_account(pw, acc);
gnc_ui_payment_window_destroy (pw);
}
@@ -285,11 +353,17 @@ new_payment_window (GncOwner *owner, GNCBook *book, gnc_numeric initial_payment)
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(pw->acct_tree), FALSE);
gnc_payment_set_account_types (GNC_TREE_VIEW_ACCOUNT (pw->acct_tree));
/* Set the dialog for the 'new' owner */
gnc_payment_dialog_owner_changed(pw);
/* Setup signals */
glade_xml_signal_autoconnect_full( xml,
gnc_glade_autoconnect_full_func,
pw);
g_signal_connect (G_OBJECT (pw->owner_choice), "changed",
G_CALLBACK (gnc_payment_dialog_owner_changed_cb), pw);
/* Register with the component manager */
pw->component_id =
gnc_register_gui_component (cm_class,