r19853 - gnucash/trunk/src/business/business-gnome - Bug #635439: Patch to autoset owner in the payment dialog

Christian Stimming cstim at code.gnucash.org
Sun Nov 21 15:17:29 EST 2010


Author: cstim
Date: 2010-11-21 15:17:29 -0500 (Sun, 21 Nov 2010)
New Revision: 19853
Trac: http://svn.gnucash.org/trac/changeset/19853

Modified:
   gnucash/trunk/src/business/business-gnome/business-gnome-utils.c
   gnucash/trunk/src/business/business-gnome/dialog-payment.c
Log:
Bug #635439: Patch to autoset owner in the payment dialog

Patch by Matthijs Kooijman <matthijs at stdin.nl>:

    In the payment dialog, set the owner when an invoice is selected

    Before, you would always need to select an owner manually. If you would
    just select an invoice (which was possible, since the invoice selection
    is not disabled when no owner has been selected yet), pressing OK would
    error out because no owner was selected.

    This patch makes sure that when an invoice is selected, but no owner is
    selected yet, the right owner is filled into the owner selection box
    automatically.

    This also happens when the wrong owner is selected, which can happen
    because the invoice autocompletion is not limited to invoices from the
    selected owner, but always completes all invoices. This could cause
    weird behaviour: Select an owner, then use completion to select an
    invoice by another owner and press ok. This would cause the amount for
    the invoice by the other owner to be charged against the first owner.
    This patch prevents that by replacing the first owner by the other owner
    in the dialog.

    This patch also changes gnc_invoice_set_owner to no longer reset the
    invoice selection to NULL. Instead, this is now handled by

Modified: gnucash/trunk/src/business/business-gnome/business-gnome-utils.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/business-gnome-utils.c	2010-11-21 02:16:04 UTC (rev 19852)
+++ gnucash/trunk/src/business/business-gnome/business-gnome-utils.c	2010-11-21 20:17:29 UTC (rev 19853)
@@ -310,7 +310,6 @@
 
     gncOwnerCopy(owner, &isi->owner);
     isi->have_owner = TRUE;
-    gnc_general_search_set_selected(GNC_GENERAL_SEARCH(widget), NULL);
 
     /* Reset the label */
     gnc_invoice_select_search_set_label(isi);

Modified: gnucash/trunk/src/business/business-gnome/dialog-payment.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-payment.c	2010-11-21 02:16:04 UTC (rev 19852)
+++ gnucash/trunk/src/business/business-gnome/dialog-payment.c	2010-11-21 20:17:29 UTC (rev 19853)
@@ -96,17 +96,29 @@
         gtk_widget_destroy (pw->dialog);
 }
 
+/* Forward declaration */
+static void gnc_payment_set_owner (PaymentWindow *pw, GncOwner *owner);
+
 static void
 gnc_payment_dialog_invoice_changed(PaymentWindow *pw)
 {
     GNCLot *lot;
     gnc_numeric val;
+    GncOwner *owner;
 
     /* Set the payment amount in the dialog */
     if (pw->invoice)
     {
         lot = gncInvoiceGetPostedLot (pw->invoice);
         val = gnc_numeric_abs (gnc_lot_get_balance (lot));
+        /* If a invoice is selected without selecting an owner first, or
+         * if the owner for the selected invoice is different from the
+         * previously selected owner, make sure the right owner is
+         * selected. */
+        owner = gncInvoiceGetOwner (pw->invoice);
+        if (pw->owner.owner.undefined == NULL || pw->owner.owner.undefined != owner->owner.undefined) {
+            gnc_payment_set_owner (pw, gncInvoiceGetOwner (pw->invoice));
+        }
     }
     else
     {
@@ -124,18 +136,19 @@
     KvpValue* value;
     KvpFrame* slots;
 
-    /* If the owner changed, the invoice selection is invalid */
-    pw->invoice = NULL;
+    /* The selected invoice has a different owner than the newly
+     * selected owner, reset it */
+    if (pw->invoice != NULL && !gncOwnerEqual(gncInvoiceGetOwner(pw->invoice), &pw->owner)) {
+        pw->invoice = NULL;
+        gnc_invoice_set_invoice(pw->invoice_choice, NULL);
+    }
+
+    /* Limit the invoice selection to this owner */
     gnc_invoice_set_owner(pw->invoice_choice, &pw->owner);
-    /* note that set_owner implies ...set_invoice(...,NULL); */
 
     /* in case we don't get the callback */
     gnc_payment_dialog_invoice_changed(pw);
 
-    /* XXX: We should set the sensitive flag on the invoice_choice
-     * based on whether 'owner' is NULL or not...
-     */
-
     /* Now handle the account tree */
     slots = gncOwnerGetSlots(&pw->owner);
     if (slots)



More information about the gnucash-changes mailing list