[PATCH] dialog-payment fixes

Mike Evans mikee at saxicola.idps.co.uk
Mon Nov 22 07:08:03 EST 2010


On Saturday November 20 2010 13:28:45 Matthijs Kooijman wrote:
> Hi folks,
> 
> Here's a patch to fix a pet peeve I've had for quite some time with the
> invoice payment dialog: Make it possible to enter just the invoice
> (number), instead of always needing to select the owner manually. This
> is especially useful when processing bank statements, when the invoice
> number is listed on the statement.
> 
> I've added a second patch, for a bug I noticed while digging through the
> code. Note that the inconsistent use of spaces in between a function
> name and the opening brace for the arguments is to remain consistent
> with the surrounding code (but dialog-payment.c uses different
> styles...).
> 
> Patches are against current SVN trunk.
> 
> Gr.
> 
> Matthijs
> 
> ---------------
> 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
> ---
>  src/business/business-gnome/business-gnome-utils.c |    1 -
>  src/business/business-gnome/dialog-payment.c       |   27
> ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-)
> 
> diff --git a/src/business/business-gnome/business-gnome-utils.c
> b/src/business/business-gnome/business-gnome-utils.c index
> 23c14ef..6c68a17 100644
> --- a/src/business/business-gnome/business-gnome-utils.c
> +++ b/src/business/business-gnome/business-gnome-utils.c
> @@ -310,7 +310,6 @@ void gnc_invoice_set_owner (GtkWidget *widget, GncOwner
> *owner)
> 
>      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);
> diff --git a/src/business/business-gnome/dialog-payment.c
> b/src/business/business-gnome/dialog-payment.c index eef4484..af8c541
> 100644
> --- a/src/business/business-gnome/dialog-payment.c
> +++ b/src/business/business-gnome/dialog-payment.c
> @@ -96,17 +96,29 @@ gnc_payment_window_close_handler (gpointer data)
>          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 @@ gnc_payment_dialog_owner_changed(PaymentWindow *pw)
>      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)
> 
> --------------------------------------
> 
> Fix "Pay invoice" while the invoice dialog is open.
> 
> If you use "Pay invoice", normally a new payment dialog is opened which
> is completely filled in. However, when there was already a dialog open,
> it was reused but only the owner would be filled in. This patch makes
> sure that the invoice and amount are filled in as well.
> ---
>  src/business/business-gnome/dialog-payment.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/src/business/business-gnome/dialog-payment.c
> b/src/business/business-gnome/dialog-payment.c index af8c541..5d5fdfb
> 100644
> --- a/src/business/business-gnome/dialog-payment.c
> +++ b/src/business/business-gnome/dialog-payment.c
> @@ -463,8 +463,8 @@ new_payment_window (GncOwner *owner, QofBook *book,
> GncInvoice *invoice)
> 
>      /*
>       * Find an existing payment window.  If found, bring it to
> -     * the front.  If we have an actual owner, then set it in
> -     * the window.
> +     * the front.  If we have an actual owner and/or invoice, then set
> +     * it in the window.
>       */
> 
>      pw = gnc_find_first_gui_component (cm_class, find_handler, NULL);
> @@ -472,6 +472,8 @@ new_payment_window (GncOwner *owner, QofBook *book,
> GncInvoice *invoice) {
>          if (owner->owner.undefined)
>              gnc_payment_set_owner (pw, owner);
> +        if (invoice)
> +            gnc_invoice_set_invoice (pw->invoice_choice, invoice);
> 
>          gtk_window_present (GTK_WINDOW(pw->dialog));
>          return(pw);
This breaks GnuCash for me.  

Selecting pay invoice while an invoice is open fills in the customer field 
with
the job instead of the customer.  Selecting OK crashes. This only occurs where
there is a job associated with an invoice, no job no problem.

GnuCash.gnc_invoice_set_invoice: assertion `invoice != NULL' failed
I've left a comment in Bug 635439 
Perhaps because where there's a job then the job is the owner, which is in turn owned by the customer.(?)
Mike E



-- 
GPG Key: 1024D/050895C2
Keyserver: http://pgp.mit.edu/          
Search String: 0x050895C2


More information about the gnucash-devel mailing list